0

'

public partial class ComPortForm : Form
{
    //Port Numaralarını ports isimli diziye atıyoruz.
    string[] ports = SerialPort.GetPortNames(); 
    

    public ComPortForm(SerialPort SP)
    {
        InitializeComponent();

    }

    private void ComPortForm_Load(object sender, EventArgs e)
    {
        
        foreach (string port in ports)
        {
            // Port isimlerini combobox1'de gösteriyoruz.
            comboBox1.Items.Add(port); 
            comboBox1.SelectedIndex = 0;
        }
        // Baudrate'leri kendimiz combobox2'ye giriyoruz.
        comboBox2.Items.Add("2400");  
        comboBox2.Items.Add("4800");
        comboBox2.Items.Add("9600");
        comboBox2.Items.Add("19200");
        comboBox2.Items.Add("115200");
        comboBox2.SelectedIndex = 2;

        //Bu esnada bağlantı yok.
        label1.Text = "Bağlantı Kapalı";   
    }
    
    private void ComPortForm_Load(object sender, FormClosingEventArgs e)
    {
        

        // Form kapandığında Seri Port Kapatılmış Olacak.
        if (Program.serial.IsOpen == true)
        {
            Program.serial.Close();   
        }


    }

    private void button1_Click(object sender, EventArgs e)
    {


        timer1.Start(); 
        if (Program.serial.IsOpen == false)
        {
            if (comboBox1.Text == "")
                return;

            // combobox1'e zaten port isimlerini aktarmıştık.
            Program.serial.PortName = comboBox1.Text;

            //Seri Haberleşme baudrate'i combobox2 'de seçilene göre belirliyoruz.
            Program.serial.BaudRate = Convert.ToInt16(comboBox2.Text); 

            try
            {
                //Haberleşme için port açılıyor
                Program.serial.Open(); 
                label1.ForeColor = Color.Green;
                label1.Text = "Bağlantı Açık.";


            }
            catch (Exception hata)
            {
                MessageBox.Show("Hata:" + hata.Message);
            }
        }
        else
        {
            label1.Text = "Bağlantı Zaten Açık!";
        }

    }

    private void button2_Click(object sender, EventArgs e)
    {
        //BAĞLANTIYI KES BUTONU
        timer1.Stop();
        if (Program.serial.IsOpen == true)
        {
            Program.serial.Close();
            label1.BackColor = Color.Transparent;
            label1.ForeColor = Color.Red;
            label1.Text = "Bağlantı Kapalı.";
        }
    }

    private void button3_Click(object sender, EventArgs e)
    {
        //kaydet butonuyla Form2'yi kapatıyoruz.
        this.Close();
    }

    private void pictureBox1_Click(object sender, EventArgs e)
    {
        //resim kutusuna dokununca url ye gidecek.
        System.Diagnostics.Process.Start("explorer.exe", @"https://hosseven.com.tr/");
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

'

My application for which I selected the Serial Port settings is currently running, but I want to save these settings and use them when my application starts again.I want to keep my chosen settings between application starts? Do I need to save to json file? please edit my code and help.I'm new at this job.

  • i would suggest looking at writing to a file, what format or whatnot you want if up to you, microsoft has a good example [here](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-write-to-a-text-file) – A Sad Shoe Oct 06 '22 at 06:38
  • sorry i couldn't – HandeGoroglu Oct 06 '22 at 07:40
  • Does this answer your question? [How can I save application settings in a Windows Forms application?](https://stackoverflow.com/questions/453161/how-can-i-save-application-settings-in-a-windows-forms-application) – BurnsBA Oct 06 '22 at 14:22

0 Answers0