net.sourceforge.jmodbus
Class ModbusMaster

java.lang.Object
  |
  +--net.sourceforge.jmodbus.Modbus
        |
        +--net.sourceforge.jmodbus.ModbusMaster
Direct Known Subclasses:
ModbusASCIIMaster, ModbusRTUMaster, ModbusTCPMaster

public class ModbusMaster
extends Modbus

Class to represent a Modbus Master device. This is a base class that will be extended by classes representing the different transports. This class contains the knowledge that is required to generate a modbus request and parse the response.


Fields inherited from class net.sourceforge.jmodbus.Modbus
ADDRESS_MAX, COIL_OFF, COIL_ON, debug, EXCEPTION_MODIFIER, ILLEGAL_DATA_ADDRESS, ILLEGAL_DATA_VALUE, ILLEGAL_FUNCTION, ILLEGAL_RESPONSE_LENGTH, MAX_MESSAGE_LENGTH, READ_COILS, READ_EXCEPTION_STATUS, READ_INPUT_DISCRETES, READ_INPUT_REGISTERS, READ_MULTIPLE_REGISTERS, transport, UINT16_MAX, UINT16_MIN, UINT8_MAX, UINT8_MIN, WRITE_COIL, WRITE_MULTIPLE_REGISTERS, WRITE_SINGLE_REGISTER
 
Constructor Summary
ModbusMaster(ModbusTransport transport)
          Class constructor.
 
Method Summary
 boolean readInputRegisters(int reference, int length, int[] results)
          Function to read input registers from the slave device.
 boolean readInputRegisters(int unitID, int reference, int length, int transID, int[] results)
          Function to read input registers from the slave device.
 boolean readMultipleRegisters(int reference, int length, int[] results)
          Function to read multiple registers from the slave device.
 boolean readMultipleRegisters(int unitID, int reference, int length, int transID, int[] results)
          Function to read multiple registers from the slave device.
 boolean writeMultipleRegisters(int reference, int length, int[] values)
          Function to write multiple registers from the slave device.
 boolean writeMultipleRegisters(int unitID, int reference, int length, int transID, int[] values)
          Function to write multiple registers to the slave device.
 
Methods inherited from class net.sourceforge.jmodbus.Modbus
receiveFrame, sendFrame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModbusMaster

public ModbusMaster(ModbusTransport transport)
Class constructor. Accepts a ModbusTransport object that is passed to the master.
Parameters:
transport - The ModbusTransport object that should be used by this Modbus object to send and recieve Modbus frames.
Method Detail

readMultipleRegisters

public boolean readMultipleRegisters(int reference,
                                     int length,
                                     int[] results)
                              throws java.lang.IllegalArgumentException
Function to read multiple registers from the slave device. The function is passed a reference to an int array, the reference of the first register and the number of registers to read. A boolean is returned indicating if the function returned sucessfully. The the int array is too small then an array index out of bounds exception will be thrown.
Parameters:
reference - The refernece number of the first register to read.
length - The number of register to be read.
results - Refernce to the int array to which results should be written.

readMultipleRegisters

public boolean readMultipleRegisters(int unitID,
                                     int reference,
                                     int length,
                                     int transID,
                                     int[] results)
                              throws java.lang.IllegalArgumentException
Function to read multiple registers from the slave device. The function is passed a reference to an int array, the reference of the first register and the number of registers to read. A boolean is returned indicating if the function returned sucessfully. The the int array is too small then an array index out of bounds exception will be thrown.
Parameters:
unitID - The unit ID of the device to talk to (set to zero is unknown).
reference - The refernece number of the first register to read.
length - The number of register to be read.
transID - The transaction ID to use for this transaction.
results - Refernce to the int array to which results should be written.

readInputRegisters

public boolean readInputRegisters(int reference,
                                  int length,
                                  int[] results)
                           throws java.lang.IllegalArgumentException
Function to read input registers from the slave device. The function is passed a reference to an int array, the reference of the first register and the number of registers to read. A boolean is returned indicating if the function returned sucessfully. The the int array is too small then an array index out of bounds exception will be thrown.
Parameters:
reference - The refernece number of the first register to read.
length - The number of register to be read.
results - Refernce to the int array to which results should be written.

readInputRegisters

public boolean readInputRegisters(int unitID,
                                  int reference,
                                  int length,
                                  int transID,
                                  int[] results)
                           throws java.lang.IllegalArgumentException
Function to read input registers from the slave device. The function is passed a reference to an int array, the reference of the first register and the number of registers to read. A boolean is returned indicating if the function returned sucessfully. The the int array is too small then an array index out of bounds exception will be thrown.
Parameters:
unitID - The unit ID of the device to talk to (set to zero is unknown).
reference - The refernece number of the first register to read.
length - The number of register to be read.
transID - The transaction ID to use for this transaction.
results - Refernce to the int array to which results should be written.

writeMultipleRegisters

public boolean writeMultipleRegisters(int reference,
                                      int length,
                                      int[] values)
                               throws java.lang.IllegalArgumentException
Function to write multiple registers from the slave device. The function is passed a reference to an int array, the reference of the first register and the number of registers to read. A boolean is returned indicating if the function returned sucessfully. The the int array is too small then an array index out of bounds exception will be thrown.
Parameters:
reference - The refernece number of the first register to read.
length - The number of register to be read.
valuess - Refernce to the int array to which results should be written.

writeMultipleRegisters

public boolean writeMultipleRegisters(int unitID,
                                      int reference,
                                      int length,
                                      int transID,
                                      int[] values)
                               throws java.lang.IllegalArgumentException
Function to write multiple registers to the slave device. The function is passed a reference to an int array, the reference of the first register and the number of registers to write. A boolean is returned indicating if the function returned sucessfully. The the int array is too small then an array index out of bounds exception will be thrown.
Parameters:
unitID - The unit ID of the device to talk to (set to zero is unknown).
reference - The refernece number of the first register to read.
length - The number of register to be read.
transID - The transaction ID to use for this transaction.
values - Refernce to the int array to which results should be written.