Ejemplo n.º 1
0
 private void buttonDisconnect_Click(object sender, EventArgs e)
 {
     if (serialComm != null)
     {
         serialComm.Dispose();
         serialComm               = null;
         buttonConnect.Enabled    = true;
         buttonDisconnect.Enabled = false;
         buttonRequest.Enabled    = false;
         checkAutorequest.Enabled = false;
     }
 }
Ejemplo n.º 2
0
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            Int32 baudRate = 0;

            try
            {
                baudRate = Int32.Parse(textBaudRate.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Invalid Baud Rate.");
                return;
            }

            try
            {
                serialComm = new SerialCommunication(textPortName.Text, baudRate);
                serialComm.AddReceiveHandler(SerialDataReceived);
                serialComm.Open();

                if (serialComm.Connected == false)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot connect to " + textPortName.Text);
                serialComm.Dispose();
                serialComm = null;
                return;
            }

            keyBuffers[0]            = keyBuffers[1] = 0xFF;
            buttonConnect.Enabled    = false;
            buttonDisconnect.Enabled = true;
            buttonRequest.Enabled    = true;
            checkAutorequest.Enabled = true;
        }