Example #1
0
 private void Connect_Button_Click(object sender, EventArgs e)
 {
     try
     {
         SerialCOMPort = new Serial(this);
         SerialCOMPort.Connect(COMPort_ComboBox.Text, "115200", "8", "0", "1");
         SerialCOMPort.GetSerialPort().DataReceived += SerialCOMPort.ReceiveData;
     }
     catch (Exception ex)
     {
         Console_ListBox.Items.Add("Error: " + ex.Message);
         int itemsPerPage = (int)(Console_ListBox.Height / Console_ListBox.ItemHeight);
         Console_ListBox.TopIndex = Console_ListBox.Items.Count - itemsPerPage;
     }            
 }
Example #2
0
        public void Dispose()
        {
            if (serialPort == null)
                return;

            serialPort.Connected = false;
            serialPort.Dispose();
            serialPort = null;
        }
Example #3
0
        private void comboPorts_SelectedIndexChanged(object sender, EventArgs e)
        {
            int idx = comboPorts.SelectedIndex;
            if (idx <= 0)
            {
                Connection = null;
                comboBaudRate.Enabled = false;
                btnConnect.Enabled = false;
                return;
            }

            if (Connection == null)
            {
                Connection = new Serial();
                Driver.Controller.Connection = Connection;
            }
            string portName = comboPorts.SelectedItem.ToString().Remove(0, 3); //Removing the COM part
            Connection.Port = Convert.ToInt16(portName);
            comboBaudRate.Enabled = true;
            btnConnect.Enabled = true;
        }