コード例 #1
0
ファイル: CenterControl.cs プロジェクト: Bogay/TinyKeyboard
        //Catch event from detector if COM is connect or dis connect from pc
        private void PortsChanged(object sender, PortsChangedArgs e)
        {
            if (e.EventType == EventType.Insertion)
            {
                if (serialPortMessage == null)
                {
                    ScanPorts();
                }
            }
            else
            {
                serialPortMessage.EndRead();
                var foundFlag = false;
                foreach (var port in e.SerialPorts)
                {
                    if (port == serialPortMessage.name)
                    {
                        foundFlag = true;
                        break;
                    }
                }

                if (!foundFlag)
                {
                    serialPortMessage.Dispose();
                    serialPortMessage = null;
                }
                else
                {
                    serialPortMessage.StartRead();
                }
            }
        }
コード例 #2
0
ファイル: CenterControl.cs プロジェクト: Bogay/TinyKeyboard
 //Use COM name to init SerialPortMessageObject and Start Listen
 private void SetSerialPortMessage(string port)
 {
     if (serialPortMessage != null)
     {
         serialPortMessage.Dispose();
     }
     serialPortMessage = new SerialPortMessage(new System.IO.Ports.SerialPort(port));
     serialPortMessage.SerialPortReceived += messageScheduler.ScheduleFuction;
     serialPortMessage.StartRead();
 }