Exemple #1
0
        /// <summary>
        /// 检测线程函数,用于多线程检测
        /// </summary>
        /// <param name="com"></param>
        private void ProcDetectting(object com)
        {
            SerialPortCommunication serialPort = com as SerialPortCommunication;
            bool bOpen = serialPort.IsOpen();

            if (!bOpen)
            {
                return;
            }
            serialPort.SendData(_detectCommandBytes);
        }
Exemple #2
0
 /// <summary>
 /// 打开串口
 /// </summary>
 /// <returns></returns>
 public bool Open()
 {
     if (null == _communicateDevice)
     {
         _communicateDevice = new SerialPortCommunication();
     }
     if (_communicateDevice.IsOpen())
     {
         _communicateDevice.Close();
     }
     _communicateDevice.InitializeDevice(_portName, _baudRate, _dataBits, _stopBits, _parity, Handshake.None);
     _communicateDevice.DataReceived += ReceiveData;
     try
     {
         _communicateDevice.Open();
     }
     catch
     {
         return(false);
     }
     return(true);
 }