public static DiagnosticsMessage Decode(byte[] message)
        {
            int index = 0;
            DiagnosticsMessage msg = new DiagnosticsMessage();

            msg.MessageType   = (ModbusMessageType)message[7];
            msg.TransactionId = (ushort)(message[index++] << 0x08 | message[index++]);
            msg.ProtocolId    = (ushort)(message[index++] << 0x08 | message[index++]);
            msg.Length        = (ushort)(message[index++] << 0x08 | message[index++]);
            msg.UnitId        = Convert.ToByte(message[index++]);
            msg.Function      = Convert.ToByte(message[index++]);

            return(msg);
        }
Exemple #2
0
        private bool Apply(DiagnosticsMessage mesage)
        {
            if (Type == ConstraintType.DenyAll)
            {
                return(false);
            }
            if (Type == ConstraintType.AllowAll)
            {
                return(true);
            }

            if (Filters == null || Filters.Count == 0)
            {
                return(true);
            }

            return(false);
        }
        public static ModbusTcpMessage Create(byte[] message)
        {
            if (message[7] <= 4 || message[7] == 15 || message[7] == 16)
            {
                return(BasicModbusMessage.Decode(message));
            }

            if (message[7] > 4 && message[7] < 7)
            {
                return(WriteSingleMessage.Decode(message));
            }

            if (message[7] == 8 || message[7] == 11 || message[7] == 12)
            {
                return(DiagnosticsMessage.Decode(message));
            }

            throw new InvalidCastException("Invalid modbus message type.");
        }