Ejemplo n.º 1
0
 /// <summary>
 /// Set the command and crc, calculates whether crc is valid
 /// </summary>
 /// <param name="command"></param>
 /// <param name="crc"></param>
 public Message(string command, ushort crc)
 {
     Command  = command;
     Crc      = crc;
     CrcValid = CRC16.Calculate(Encoding.ASCII.GetBytes(command)) == crc;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Set the command and calculate the crc, always sets crcValid to true
 /// </summary>
 /// <param name="command"></param>
 public Message(string command)
 {
     Command  = command;
     Crc      = CRC16.Calculate(Encoding.ASCII.GetBytes(command));
     CrcValid = true;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Set command and crc from packed byte array
 /// </summary>
 /// <param name="commandAndCrc"></param>
 public Message(byte[] commandAndCrc)
 {
     Crc      = (ushort)((commandAndCrc[commandAndCrc.Length - 2] << 8) | commandAndCrc[commandAndCrc.Length - 1]);
     Command  = Encoding.ASCII.GetString(commandAndCrc, 0, commandAndCrc.Length - 2);
     CrcValid = CRC16.Calculate(Encoding.ASCII.GetBytes(Command)) == Crc;
 }