Example #1
0
 public static void CloseComPort()
 {
     IsReadComMsg = false;
     if (_SerialPort == null || !_SerialPort.IsOpen)
     {
         return;
     }
     _SerialPort.Close();
     _SerialPort = null;
 }
Example #2
0
        public static void OpenComPort()
        {
            if (!pcvr.bIsHardWare)
            {
                return;
            }

            if (_SerialPort != null)
            {
                return;
            }

            //_SerialPort = new SerialPort(ComPortName, 38400, Parity.None, 8, StopBits.One);
            _SerialPort = new GkioPort();
            if (_SerialPort != null)
            {
                try
                {
                    if (_SerialPort.IsOpen)
                    {
                        _SerialPort.Close();
                        Debug.Log("Closing port, because it was already open!");
                    }
                    else
                    {
                        _SerialPort.Open();
                        if (_SerialPort.IsOpen)
                        {
                            IsFindDeviceDt = true;
                            Debug.Log("COM open sucess");
                        }
                    }
                }
                catch (Exception exception)
                {
                    if (XkGameCtrl.IsGameOnQuit || ComThread == null)
                    {
                        return;
                    }
                    Debug.Log("error:COM already opened by other PRG... " + exception);
                }
            }
            else
            {
                Debug.Log("Port == null");
            }
        }