Пример #1
0
        private static IModbusCommand Parse16(byte slave, byte code, ushort address, byte[] request, int offset)
        {
            var count  = ModbusHelper.GetUShort(request, offset + 4);
            var values = ModbusHelper.DecodeWords(request, offset + 7, count);
            var bytes  = request[offset + 6];

            Tools.AssertEqual(ModbusHelper.BytesForWords(count), bytes, "Byte count mismatch got {0} expected {1}");
            return(new ModbusF16WriteRegisters(slave, address, values));
        }
Пример #2
0
        public object ParseResponse(byte[] response, int offset)
        {
            var bytes = ModbusHelper.BytesForWords(count);

            Assert.Equal(response[offset + 0], slave, "Slave mismatch {0} expected:{1}");
            Assert.Equal(response[offset + 1], 4, "Function mismatch {0} expected:{1}");
            Assert.Equal(response[offset + 2], bytes, "Bytes mismatch {0} expected:{1}");
            return(ModbusHelper.DecodeWords(response, offset + 3, count));
        }
Пример #3
0
        public void FillResponse(byte[] response, int offset, object value)
        {
            var bytes = ModbusHelper.BytesForWords(count);

            response[offset + 0] = slave;
            response[offset + 1] = 4;
            response[offset + 2] = bytes;
            var data = ModbusHelper.EncodeWords((ushort[])value);

            ModbusHelper.Copy(data, 0, response, offset + 3, bytes);
        }