net.sourceforge.jmodbus
Class ModbusCoilBank

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

public class ModbusCoilBank
extends java.lang.Object

Class to represent the coils (1 bit data items) in a Modbus device. The class uses boolean varibales internally to represent coils as the minimum block allocation of memory for a JVM is 4 bytes so type does not matter. Thus booleans were chosed to make logic comparisons easy.


Constructor Summary
ModbusCoilBank(int coils_size)
          Class constructor that, given the size of the coil bank required, will allocate suficient memory for the coil bank and initilize all the values to zero
 
Method Summary
 boolean getCoil(int index)
          Gets the value of a particular coil.
 boolean[] getCoils(int index, int length)
          Gets the value of a particular block of coils.
 int getNumberCoils()
          Get the size of this bank of coils.
 void setCoil(int index, boolean value)
          Sets the value of a particular coil.
 void setCoils(int index, boolean[] coil_set)
          Sets the value of a particular block of coils.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModbusCoilBank

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

getNumberCoils

public int getNumberCoils()
Get the size of this bank of coils.
Returns:
The size of the bank of coils.

getCoil

public boolean getCoil(int index)
Gets the value of a particular coil.

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

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

setCoil

public void setCoil(int index,
                    boolean value)
Sets the value of a particular coil.

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

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

getCoils

public boolean[] getCoils(int index,
                          int length)
Gets the value of a particular block of coils.

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

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

setCoils

public void setCoils(int index,
                     boolean[] coil_set)
Sets the value of a particular block of coils.

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

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