public ModbusMessage ProcessMessage(RS232Message message)
        {
            byte[] data = message.BinaryData;

            int messageStart;
            for (messageStart = 0; messageStart < data.Length; messageStart++)
                if (data[messageStart] == (byte)':')
                    break;

            int messageLength = data.Length - messageStart;
            if (messageLength < MINIMUM_MESSAGE_LENGTH)
                return null;

            int lrc = HexHelper.DecodeHex(data[data.Length - 2], data[data.Length - 1]);
            int expectedLrc = CalculateLRC(HexHelper.DecodeHexArray(data, messageStart + 1, data.Length - messageStart - 3));
            if (lrc != expectedLrc)
                return null;

            byte address = HexHelper.DecodeHex(data[messageStart + 1], data[messageStart + 2]);
            byte function = HexHelper.DecodeHex(data[messageStart + 3], data[messageStart + 4]);
            byte[] messageContent = HexHelper.DecodeHexArray(data, messageStart + 5, messageLength - 7);

            return new ModbusMessage(messageContent, address, function);
        }
Exemple #2
0
 public ModbusMessage ProcessMessage(RS232Message rs232Message)
 {
     throw new NotImplementedException();
 }