protected override void InitializeUnique(byte[] frame) { if (frame.Length < MinimumFrameSize + frame[10]) { throw new FormatException("Message frame does not contain enough bytes."); } byte[] readFrame = new byte[2 + 4]; byte[] writeFrame = new byte[frame.Length - 6 + 2]; readFrame[0] = writeFrame[0] = SlaveAddress; readFrame[1] = writeFrame[1] = FunctionCode; Buffer.BlockCopy(frame, 2, readFrame, 2, 4); Buffer.BlockCopy(frame, 6, writeFrame, 2, frame.Length - 6); _readRequest = ModbusMessageFactory.CreateModbusMessage <ReadHoldingInputRegistersRequest>(readFrame); _writeRequest = ModbusMessageFactory.CreateModbusMessage <WriteMultipleRegistersRequest>(writeFrame); }
public ReadWriteMultipleRegistersRequest( byte slaveAddress, ushort startReadAddress, ushort numberOfPointsToRead, ushort startWriteAddress, RegisterCollection writeData) : base(slaveAddress, Modbus.ReadWriteMultipleRegisters) { _readRequest = new ReadHoldingInputRegistersRequest( Modbus.ReadHoldingRegisters, slaveAddress, startReadAddress, numberOfPointsToRead); _writeRequest = new WriteMultipleRegistersRequest( slaveAddress, startWriteAddress, writeData); }