Beispiel #1
0
 public void InvokeSend(AbstractCommand command, int sleepMilSeconds)
 {
     lock (_lockItem)
     {
         _log.Debug("Invoke send");
         _buffer.Remove(0, _buffer.Length);
         _serialPort.WriteLine(command.CompleteCommand());
         _log.Debug("Invoke send success and wait " + sleepMilSeconds);
         Thread.Sleep(sleepMilSeconds);
         _buffer.Remove(0, _buffer.Length);
     }
 }
Beispiel #2
0
 public string Send(AbstractCommand command)
 {
     lock (_lockItem)
     {
         try
         {
             _buffer.Remove(0, _buffer.Length);
             ThreadPool.QueueUserWorkItem(delegate { _serialPort.WriteLine(command.CompleteCommand()); });
             return WaitReturn(command);
         }
         finally
         {
             _log.Info("Complete receive is: " + _buffer.ToString());
             _buffer.Remove(0, _buffer.Length);
         }
     }
 }
Beispiel #3
0
 private string WaitReturn(AbstractCommand command)
 {
     var now = DateTime.Now;
     while (true)
     {
         if ((DateTime.Now - now).TotalSeconds > 12)
         {
             _log.Warn("waiting return timeout.");
             break;
         }
         if (command.Init(_buffer.ToString()))
         {
             _log.Debug("Return value,command is success or not?" + command.Success);
             break;
         }
         Thread.Sleep(100);
     }
     string result = _buffer.ToString();
     //_log.InfoFormat("Wait Return  command \r\n {0}", result);
     return result;
 }
 public CommandEventHandlerArgs(AbstractCommand command)
 {
     Command = command;
 }