final public int [ ] readWriteMultipleRegisters ( int serverAddress , int readAddress , int readQuantity , int writeAddress , int [ ] registers ) throws ModbusProtocolException , ModbusNumberException , ModbusIOException { ModbusRequest request = ModbusRequestBuilder . getInstance ( ) . buildReadWriteMultipleRegisters ( serverAddress , readAddress , readQuantity , writeAddress , registers ) ; ReadWriteMultipleRegistersResponse response = ( ReadWriteMultipleRegistersResponse ) processRequest ( request ) ; return response . getRegisters ( ) ; }
This function code performs a combination of one read operation and one write operation in a single MODBUS transaction . The write operation is performed before the read . Holding registers are addressed starting at zero . Therefore holding registers 1 - 16 are addressed in the PDU as 0 - 15 . The request specifies the starting address and number of holding registers to be read as well as the starting address number of holding registers and the data to be written .