net.sourceforge.jmodbus
Class ModbusRegisterBank

java.lang.Object
  |
  +--net.sourceforge.jmodbus.ModbusRegisterBank

public class ModbusRegisterBank
extends java.lang.Object

Class to represent the registers (16 bit data items) in a Modbus device. The classes uses int varibales internally to represent registers as the minimum block allocation of memory for a JVM is 4 bytes so using a short etc.. does not make any difference. *


Constructor Summary
ModbusRegisterBank(int register_size)
          Class constructor that, given the size of the register bank required, will allocate suficient memory for the register bank and initilize all the values to zero
 
Method Summary
 int getNumberRegisters()
          Get the size of this bank of registers.
 int getRegister(int index)
          Gets the value of a particular register.
 int[] getRegisters(int index, int length)
          Gets the value of a particular block of registers.
 void setRegister(int index, int value)
          Sets the value of a particular register.
 void setRegister(int index, int[] regs)
          Sets the value of a particular block of registers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModbusRegisterBank

public ModbusRegisterBank(int register_size)
Class constructor that, given the size of the register bank required, will allocate suficient memory for the register bank and initilize all the values to zero
Parameters:
coils_size - The number of registers to be created in this register bank.
Method Detail

getNumberRegisters

public int getNumberRegisters()
Get the size of this bank of registers.
Returns:
The size of the bank of registers.

getRegister

public int getRegister(int index)
Gets the value of a particular register.

NOTE: Attempting to get a register outside the range of this register bank will result in a ArrayIndexOutOfBoundsException being thrown

Parameters:
index - The address of the desired register (note that this is a zero based index)
Returns:
The value of the requested register.

setRegister

public void setRegister(int index,
                        int value)
Sets the value of a particular register.

NOTE: Attempting to set a register outside the range of this register bank will result in a ArrayIndexOutOfBoundsException being thrown

Parameters:
index - The address of the desired register (note that this is a zero based index)
value - The value of the register to be set.

getRegisters

public int[] getRegisters(int index,
                          int length)
Gets the value of a particular block of registers.

NOTE: Attempting to get a register outside the range of this register bank will result in a ArrayIndexOutOfBoundsException being thrown

Parameters:
index - The address of the desired starting register (note that this is a zero based index)
length - The number of registers to be retrieved
Returns:
Array containing the values of the requested registers.

setRegister

public void setRegister(int index,
                        int[] regs)
Sets the value of a particular block of registers.

NOTE: Attempting to set a register outside the range of this register bank will result in a ArrayIndexOutOfBoundsException being thrown

Parameters:
index - The address of the desired starting register (note that this is a zero based index)
coil_set - Array of ints containing the values of the registers to be set.