Example #1
0
 public SerialConnectionStatus DisconnectFromSerial()
 {
     if (_serialPort.IsOpen)
     {
         _serialPort.Write("q");
         status          = SerialConnectionStatus.Disconnected;
         connectedPort   = null;
         connectedDevice = null;
         _serialPort.Close();
         return(status);
     }
     return(SerialConnectionStatus.Error);
 }
Example #2
0
 public SerialConnectionStatus ConnectToSerial(string portName)
 {
     if (status == SerialConnectionStatus.Disconnected)
     {
         _serialPort.PortName    = portName;
         _serialPort.BaudRate    = 115200;
         _serialPort.ReadTimeout = 1500;
         _serialPort.Open();
         try
         {
             _serialPort.DiscardInBuffer();
             message = _serialPort.ReadLine();
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
         }
         if (message != null)
         {
             if (message.Contains("EC-Test SN:"))
             {
                 _serialPort.Write("x");
                 status          = SerialConnectionStatus.Connected;
                 connectedPort   = portName;
                 connectedDevice = message;
                 return(SerialConnectionStatus.Connected);
             }
         }
         _serialPort.Close();
         return(SerialConnectionStatus.Error);
     }
     else
     {
         return(SerialConnectionStatus.Error);
     }
 }