erorr when i wrote "WRITE serial port"in RadioButton

ben-robot

New member
Joined
Dec 23, 2014
Messages
1
Programming Experience
1-3
hello all
first excuse me for my bad english and please answer to my question

i wrote a program for getting and sending text to serial port

i got information from serial port very good but how can i send data to serial port i used serialport.write in radiobutton shown erorr "PORT IS CLose"why?
this code is recevie data
C#:
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {

            SerialPort sp = (SerialPort)sender;
            string w = sp.ReadLine();

            if (w != string.Empty)
            {
                string[] data = Regex.Split(w, ":");
                if (data[0] == "H")
                {

                    Invoke(new Action(() => HUMI.Text = (data[1])));
                }
                if (data[0] == "T")
                {

                    Invoke(new Action(() => temp.Text = (data[1])));
                }

            }
        }
and radiobuton for send information
C#:
       private void Calibrate_CheckedChanged(object sender, EventArgs e)
        {

            Calibrate.Checked = false;
            if (textBox1.Text == "")
            {
                Calibrate.Checked = false;
                MessageBox.Show("TextBox is empty ");

            }
            
            sp.Write("a");
         

  }
thanks
 
Top Bottom