Exemple #1
0
        private void SendCommand(ShieldBoxCommand command, string response, int timeout = 5000)
        {
            int failCount = 0;

            do
            {
                try
                {
                    SendCmd(command);
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    while (_response != response && _response != ShieldBoxResponse.ResponseEnding + response)
                    {
                        if (stopwatch.ElapsedMilliseconds > timeout)
                        {
                            throw new Exception("Box SendCommand timeout");
                        }
                        Delay(100);
                    }
                    break;
                }
                catch (Exception)
                {
                    failCount++;
                    Delay(100);
                    if (failCount > 2)
                    {
                        throw new Exception("Box SendCommand " + command + " timeout");
                    }
                }
            } while (true);
        }
Exemple #2
0
 public void SendCmd(ShieldBoxCommand command)
 {
     lock (_sendLock)
     {
         Delay(50);
         _response = string.Empty;
         string cmd = command + CmdEnding;
         try
         {
             _serial.Write(cmd);
         }
         catch (Exception ex)
         {
             throw new Exception("Try sending command to box " + Id + " failed due to:" + ex.Message);
         }
     }
 }