Tuesday 5 March 2013

Posted by Prasad KM | 22:41 Categories:
Serial port Connection setting using C#

             var _with1 = mySerialPort;
            _with1.PortName = comboBox1.Text;
            _with1.BaudRate = 9600;
            _with1.Parity = System.IO.Ports.Parity.None;
            _with1.DataBits = 8;
            _with1.StopBits = System.IO.Ports.StopBits.One;
            _with1.Handshake = System.IO.Ports.Handshake.None;
            _with1.WriteTimeout = 10000;
            _with1.ReadTimeout = 10000;
            _with1.DiscardNull = true;


            // check whether device is avaiable: 
            try
            {   //Opens SerialPort Communication
                mySerialPort.DiscardNull = true;
                mySerialPort.Open();
                comOpen = mySerialPort.IsOpen;
                tbRX.Clear();

            }
            catch (Exception arg)
            {
                comOpen = false;
                tbRX.Text = "Error Open: ";

            }

            if (comOpen)
            {
                comboBox1.Enabled = false;
                connect.Enabled = false;

            }

0 comments:

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube