public object ParseResponse(byte[] response, int offset) { var bytes = ModbusHelper.BytesForWords(Count); Assert.Equal(response[offset + 0], Slave, "Slave mismatch got {0} expected {1}"); Assert.Equal(response[offset + 1], 4, "Function mismatch got {0} expected {1}"); Assert.Equal(response[offset + 2], bytes, "Bytes mismatch got {0} expected {1}"); return(ModbusHelper.DecodeWords(response, offset + 3, Count)); }
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]; Assert.Equal(ModbusHelper.BytesForWords(count), bytes, "Byte count mismatch got {0} expected {1}"); return(new ModbusF16WriteRegisters(slave, address, values)); }