public ReadWriteMultipleRegistersRequest( byte slaveAddress, ushort startReadAddress, ushort numberOfPointsToRead, ushort startWriteAddress, RegisterCollection writeData) : base(slaveAddress, ModbusFunctionCodes.ReadWriteMultipleRegisters) { _readRequest = new ReadHoldingInputRegistersRequest( ModbusFunctionCodes.ReadHoldingRegisters, slaveAddress, startReadAddress, numberOfPointsToRead); _writeRequest = new WriteMultipleRegistersRequest( slaveAddress, startWriteAddress, writeData); // TODO: ugly hack for all ModbusSerialTransport-inheritances (ModbusIpTransport would not need this, as it implements complete different BuildMessageFrame) // fake ByteCount, Data can hold only even number of bytes ByteCount = (ProtocolDataUnit[1]); // fake Data, as this modbusmessage does not fit ModbusMessageImpl Data = new RegisterCollection(ProtocolDataUnit.Slice(2, ProtocolDataUnit.Length - 2).ToArray()); }
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, ModbusFunctionCodes.ReadWriteMultipleRegisters) { _readRequest = new ReadHoldingInputRegistersRequest( ModbusFunctionCodes.ReadHoldingRegisters, slaveAddress, startReadAddress, numberOfPointsToRead); _writeRequest = new WriteMultipleRegistersRequest( slaveAddress, startWriteAddress, writeData); }