public void StopSendPeriodicMessage()
 {
     _PeriodicTimer.Stop();
     FireSendingStatus(SendingStatus.eIdle);
     _Command        = SendingCommand.eStop;
     _AppendMetaData = false;
 }
예제 #2
0
        private void SendCommand(Command command)
        {
            _waitForResponse = new AutoResetEvent(false);
            _parser.Reset();

            if (command.Address == null)
            {
                command.Address = _currentAddress;
            }

            byte[] bytesToSend = command.ToByteArray();

            if (SendingCommand != null)
            {
                SendingCommand.BeginInvoke(this, new CommandRequest(command), null, null);
            }

            Thread.Sleep(100);

            _port.DtrEnable = false;
            _port.RtsEnable = true;

            Thread.Sleep(Convert.ToInt32(ADDITIONAL_WAIT_TIME_BEFORE_SEND));

            DateTime startTime = DateTime.Now;

            Log.Debug(string.Format("Data sent to {1}: {0}", BitConverter.ToString(bytesToSend), _port.PortName));
            _port.Write(bytesToSend, 0, bytesToSend.Length);

            SleepAfterSend(bytesToSend.Length, startTime);
            _port.RtsEnable = false;
            _port.DtrEnable = true;
        }
예제 #3
0
 public void SimulateSendingCommand(CommandRequest request)
 {
     if (SendingCommand != null)
     {
         SendingCommand.Invoke(this, request);
     }
 }
 public void SendPeriodicMessage(string message)
 {
     _PeriodicTimer.Start();
     _Message = message;
     sendMessage(_Message);
     _Command = SendingCommand.eStartEndless;
     FireSendingStatus(SendingStatus.eStarted);
 }
 bool IsCountZero(uint counts)
 {
     _Command = SendingCommand.eCmdIdle;
     if (counts == 0)
     {
         _ActualCounts = 0;
         return(true);
     }
     return(false);
 }
 public void SendPeriodicMessageWithHeader(string message)
 {
     _AppendMetaData = true;
     _PeriodicTimer.Start( );
     _ActualCounts      = 1;
     _Message           = message;
     _MessageWithHeader = AppendHeader(_Message);
     sendMessage(_MessageWithHeader);
     _Command = SendingCommand.eStartEndless;
     FireSendingStatus(SendingStatus.eStarted);
 }
예제 #7
0
        private CommandResult SendCommand(byte commandNumber, byte[] data)
        {
            if (commandNumber == 0)
            {
                _currentAddress = new ShortAddress(0);
            }

            if (AutomaticZeroCommand && commandNumber != 0 && !(_currentAddress is LongAddress))
            {
                SendZeroCommand();
            }

            Command command;

            if (commandNumber == 0)
            {
                command         = Command.Zero(PreambleLength);
                _currentAddress = new LongAddress(0, 1, new byte[] { 2, 3, 4 });
            }
            else
            {
                command = new Command(PreambleLength, _currentAddress, commandNumber, new byte[0], data);
            }

            if (SendingCommand != null)
            {
                SendingCommand.BeginInvoke(this, new CommandRequest(command), null, null);
            }

            command.ResponseCode = new byte[] { 0, 0 };

            Thread.Sleep(5); // give chance to handle sending event

            if (Receive != null)
            {
                Receive.BeginInvoke(this, new CommandResult(command), null, null);
            }

            return(new CommandResult(command));
        }