net.wimpi.modbus.msg
Class WriteMultipleRegistersRequest

java.lang.Object
  extended by net.wimpi.modbus.msg.ModbusMessageImpl
      extended by net.wimpi.modbus.msg.ModbusRequest
          extended by net.wimpi.modbus.msg.WriteMultipleRegistersRequest
All Implemented Interfaces:
Transportable, ModbusMessage

public final class WriteMultipleRegistersRequest
extends ModbusRequest

Class implementing a ReadMultipleRegistersRequest. The implementation directly correlates with the class 0 function write multiple registers (FC 16). It encapsulates the corresponding request message.

Version:
@version@ (@date@)
Author:
Dieter Wimberger

Constructor Summary
WriteMultipleRegistersRequest()
          Constructs a new WriteMultipleRegistersRequest instance.
WriteMultipleRegistersRequest(int ref, Register[] registers)
          Constructs a new WriteMultipleRegistersRequest instance with a given reference and values to be written.
 
Method Summary
 ModbusResponse createResponse()
          Returns the ModbusResponse that represents the answer to this ModbusRequest.
 int getByteCount()
          Returns the number of bytes representing the values to be written.
 NonWordDataHandler getNonWordDataHandler()
          Returns the actual non word data handler.
 int getReference()
          Returns the reference of the register to start writing to with this WriteMultipleRegistersRequest.
 Register getRegister(int index)
          Returns the Register at the given position (relative to the reference used in the request).
 Register[] getRegisters()
          Returns the registers to be written with this WriteMultipleRegistersRequest.
 int getRegisterValue(int index)
          Returns the value of the register at the given position (relative to the reference used in the request) interpreted as unsigned short.
 int getWordCount()
          Returns the number of words to be written.
 void readData(DataInput din)
          Reads the subclass specific data from the given DataInput instance.
 void setNonWordDataHandler(NonWordDataHandler dhandler)
          Sets a non word data handler.
 void setReference(int ref)
          Sets the reference of the register to writing to with this WriteMultipleRegistersRequest.
 void setRegisters(Register[] registers)
          Sets the registers to be written with this WriteMultipleRegistersRequest.
 void writeData(DataOutput dout)
          Writes the subclass specific data to the given DataOutput.
 
Methods inherited from class net.wimpi.modbus.msg.ModbusRequest
createExceptionResponse, createModbusRequest
 
Methods inherited from class net.wimpi.modbus.msg.ModbusMessageImpl
getDataLength, getFunctionCode, getHexMessage, getOutputLength, getProtocolID, getTransactionID, getUnitID, isHeadless, readFrom, setDataLength, setHeadless, setProtocolID, setTransactionID, setUnitID, writeTo
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WriteMultipleRegistersRequest

public WriteMultipleRegistersRequest()
Constructs a new WriteMultipleRegistersRequest instance.


WriteMultipleRegistersRequest

public WriteMultipleRegistersRequest(int ref,
                                     Register[] registers)
Constructs a new WriteMultipleRegistersRequest instance with a given reference and values to be written.

Parameters:
ref - the reference number of the register to read from.
registers - the registers to be written.
Method Detail

createResponse

public ModbusResponse createResponse()
Description copied from class: ModbusRequest
Returns the ModbusResponse that represents the answer to this ModbusRequest.

The implementation should take care about assembling the reply to this ModbusRequest.

Specified by:
createResponse in class ModbusRequest
Returns:
the corresponding ModbusResponse.

setReference

public void setReference(int ref)
Sets the reference of the register to writing to with this WriteMultipleRegistersRequest.

Parameters:
ref - the reference of the register to start writing to as int.

getReference

public int getReference()
Returns the reference of the register to start writing to with this WriteMultipleRegistersRequest.

Returns:
the reference of the register to start writing to as int.

setRegisters

public void setRegisters(Register[] registers)
Sets the registers to be written with this WriteMultipleRegistersRequest.

Parameters:
registers - the registers to be written as Register[].

getRegisters

public Register[] getRegisters()
Returns the registers to be written with this WriteMultipleRegistersRequest.

Returns:
the registers to be written as Register[].

getRegister

public Register getRegister(int index)
                     throws IndexOutOfBoundsException
Returns the Register at the given position (relative to the reference used in the request).

Parameters:
index - the relative index of the Register.
Returns:
the register as Register.
Throws:
IndexOutOfBoundsException - if the index is out of bounds.

getRegisterValue

public int getRegisterValue(int index)
                     throws IndexOutOfBoundsException
Returns the value of the register at the given position (relative to the reference used in the request) interpreted as unsigned short.

Parameters:
index - the relative index of the register for which the value should be retrieved.
Returns:
the value as int.
Throws:
IndexOutOfBoundsException - if the index is out of bounds.

getByteCount

public int getByteCount()
Returns the number of bytes representing the values to be written.

Returns:
the number of bytes to be written as int.

getWordCount

public int getWordCount()
Returns the number of words to be written.

Returns:
the number of words to be written as int.

setNonWordDataHandler

public void setNonWordDataHandler(NonWordDataHandler dhandler)
Sets a non word data handler.

Parameters:
dhandler - a NonWordDataHandler instance.

getNonWordDataHandler

public NonWordDataHandler getNonWordDataHandler()
Returns the actual non word data handler.

Returns:
the actual NonWordDataHandler.

writeData

public void writeData(DataOutput dout)
               throws IOException
Description copied from class: ModbusMessageImpl
Writes the subclass specific data to the given DataOutput.

Specified by:
writeData in class ModbusMessageImpl
Parameters:
dout - the DataOutput to be written to.
Throws:
IOException - if an I/O related error occurs.

readData

public void readData(DataInput din)
              throws IOException
Description copied from class: ModbusMessageImpl
Reads the subclass specific data from the given DataInput instance.

Specified by:
readData in class ModbusMessageImpl
Parameters:
din - the DataInput to read from.
Throws:
IOException - if an I/O related error occurs.


Copyright © 2010. All Rights Reserved.