Пример #1
0
        private void SerialPortDisconnect()//断开连接
        {
            try
            {
                STMSerial.Close();
                if (!STMSendMsgThread.IsAlive && STMSerial.IsOpen)
                {
                    STMSendMsgThread.Abort();
                }

                M8128Serial.Close();
                if (!M8128SendMsgThread.IsAlive && M8128Serial.IsOpen)
                {
                    M8128SendMsgThread.Abort();
                }


                if (SerialScanTimer.Enabled)
                {
                    SerialScanTimer.Start();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        private void SerialPortConnect()//串口连接
        {
            try
            {
                STMSerial.PortName = comboMCUCom.Text;
                STMSerial.BaudRate = Convert.ToInt32(comboMCUBaud.Text, 10);

                M8128Serial.PortName = comboM8128Com.Text;
                M8128Serial.BaudRate = Convert.ToInt32(comboM8128Baud.Text, 10);

                STMSerial.Open();
                if (!STMSendMsgThread.IsAlive && STMSerial.IsOpen)
                {
                    STMSendMsgThread.Start();
                }


                //M8128Serial.Open();
                if (!M8128SendMsgThread.IsAlive && M8128Serial.IsOpen)
                {
                    M8128SendMsgThread.Start();
                }



                if (!SerialScanTimer.Enabled)
                {
                    SerialScanTimer.Start();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }