Exemplo n.º 1
0
 // Sends a command and message to controller
 public byte[] Send(SerialComm.SerialCommand Command, byte[] Message, UInt16 Timeout)
 {
     // Set lock so multiple threads don't try to use port at same time
     lock (_SendLock)
     {
         // Create the message to send (frame message)
         byte[] serialMessage = MakeMessage(Command, Message);
         // Set flags to false
         _Responded = false;
         _Timedout  = false;
         // Disable timer while we configure it
         _Timer.Stop();
         // Attempt to write message
         if (_Port.Write(serialMessage))
         {
             // If sucessful, start timeout
             _Timer.Interval = Timeout;
             _Timer.Start();
             // Loop while we wait for a response or timeout
             while (!_Responded && !_Timedout)
             {
                 ;
             }
             // If we got a response, return it
             if (_Responded)
             {
                 return(_Response);
             }
         }
         // Otherwise, return null;
         return(null);
     }
 }
Exemplo n.º 2
0
 private byte[] MakeMessage(SerialComm.SerialCommand Command, byte[] Message)
 {
     // Stuff command in payload
     byte[] rawMessage = new byte[Message.Length + 1];
     rawMessage[0] = (byte)Command;
     //Array.Copy(rawMessage, 1, Message, 0, Message.Length);
     for (int i = 0; i < Message.Length; i++)
     {
         rawMessage[i + 1] = Message[i];
     }
     // Send to framer to create full message
     return(_Framer.FrameMessage(rawMessage));
 }