net.sourceforge.jmodbus
Class Modbus

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

public class Modbus
extends java.lang.Object

Class to represent a Modbus device. This is a base class that will be extended by classes representing both Master and Slave implementations.


Field Summary
static int ADDRESS_MAX
          Highest permissible address value.
static byte COIL_OFF
          Command code to turn a single coil off.
static byte COIL_ON
          Command code to turn a single coil on.
static int debug
          Flag to adjust the debug output level at compile time.
static byte EXCEPTION_MODIFIER
          Function code modfifer for exceptions.
static byte ILLEGAL_DATA_ADDRESS
          Exception code to signify that the request contains an illegal data address.
static byte ILLEGAL_DATA_VALUE
          Exception code to signify that the request contains an illegal data value.
static byte ILLEGAL_FUNCTION
          Exception code to signify that the function code is unknown or illegal.
static byte ILLEGAL_RESPONSE_LENGTH
          Exception code to signify that the request whould have generated an illegaly long response.
static int MAX_MESSAGE_LENGTH
          Longest legal message length.
static byte READ_COILS
          Command code to read multiple coils.
static byte READ_EXCEPTION_STATUS
          Command code to read the exception status.
static byte READ_INPUT_DISCRETES
          Command code to read read input discretes.
static byte READ_INPUT_REGISTERS
          Command code to read imput registers.
static byte READ_MULTIPLE_REGISTERS
          Command code to read multiple registers.
protected  ModbusTransport transport
          Modbus transport object that will be used to perform all communication of Modbus messages.
static int UINT16_MAX
          The maximum value for a 16 bit unsigend integer.
static int UINT16_MIN
          The minimum value for a 16 bit unsigned integer.
static int UINT8_MAX
          The maximum value for a 8 bit unsigend integer.
static int UINT8_MIN
          The minimum value for a 8 bit unsigned integer.
static byte WRITE_COIL
          Command code to write a single coil.
static byte WRITE_MULTIPLE_REGISTERS
          Command code to write multiple registers.
static byte WRITE_SINGLE_REGISTER
          Command code to write a single register.
 
Constructor Summary
protected Modbus(ModbusTransport transport)
          Class constructor.
 
Method Summary
 boolean receiveFrame(ModbusMessage msg)
          Method to receive a Modbus frame via the transport media.
 boolean sendFrame(ModbusMessage msg)
          Method to send a Modbus frame via the transport media.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public static final int debug
Flag to adjust the debug output level at compile time.

The debug levels are as follows:


READ_MULTIPLE_REGISTERS

public static final byte READ_MULTIPLE_REGISTERS
Command code to read multiple registers.

READ_INPUT_REGISTERS

public static final byte READ_INPUT_REGISTERS
Command code to read imput registers.

WRITE_MULTIPLE_REGISTERS

public static final byte WRITE_MULTIPLE_REGISTERS
Command code to write multiple registers.

WRITE_SINGLE_REGISTER

public static final byte WRITE_SINGLE_REGISTER
Command code to write a single register.

READ_COILS

public static final byte READ_COILS
Command code to read multiple coils.

WRITE_COIL

public static final byte WRITE_COIL
Command code to write a single coil.

READ_INPUT_DISCRETES

public static final byte READ_INPUT_DISCRETES
Command code to read read input discretes.

COIL_OFF

public static final byte COIL_OFF
Command code to turn a single coil off.

COIL_ON

public static final byte COIL_ON
Command code to turn a single coil on.

READ_EXCEPTION_STATUS

public static final byte READ_EXCEPTION_STATUS
Command code to read the exception status.

EXCEPTION_MODIFIER

public static final byte EXCEPTION_MODIFIER
Function code modfifer for exceptions. This value is added to the function code to signify that some sort of error has occured in the function

ILLEGAL_FUNCTION

public static final byte ILLEGAL_FUNCTION
Exception code to signify that the function code is unknown or illegal.

ILLEGAL_DATA_ADDRESS

public static final byte ILLEGAL_DATA_ADDRESS
Exception code to signify that the request contains an illegal data address.

ILLEGAL_DATA_VALUE

public static final byte ILLEGAL_DATA_VALUE
Exception code to signify that the request contains an illegal data value.

ILLEGAL_RESPONSE_LENGTH

public static final byte ILLEGAL_RESPONSE_LENGTH
Exception code to signify that the request whould have generated an illegaly long response.

ADDRESS_MAX

public static final int ADDRESS_MAX
Highest permissible address value. This corresponds to a full scale 16 bit unsigned integer.

MAX_MESSAGE_LENGTH

public static final int MAX_MESSAGE_LENGTH
Longest legal message length.

UINT16_MAX

public static int UINT16_MAX
The maximum value for a 16 bit unsigend integer.

UINT16_MIN

public static int UINT16_MIN
The minimum value for a 16 bit unsigned integer.

UINT8_MAX

public static int UINT8_MAX
The maximum value for a 8 bit unsigend integer.

UINT8_MIN

public static int UINT8_MIN
The minimum value for a 8 bit unsigned integer.

transport

protected ModbusTransport transport
Modbus transport object that will be used to perform all communication of Modbus messages.
Constructor Detail

Modbus

protected Modbus(ModbusTransport transport)
Class constructor. This passes the class a ModbusTransport object that will be used for communications.
Parameters:
transport - The ModbusTransport object that should be used by this Modbus object to send and receive Modbus frames.
Method Detail

sendFrame

public boolean sendFrame(ModbusMessage msg)
Method to send a Modbus frame via the transport media. The return status of the function indicates if the transmission sucedded. The frame is send via the underlying transport mechanisim.
Parameters:
msg - The Modbus Message to be sent.
Returns:
Transmission sucess flag, to indicate if the transmission was sucessful.

receiveFrame

public boolean receiveFrame(ModbusMessage msg)
Method to receive a Modbus frame via the transport media. The return value indicates the length of the frame. This method will block until the comminication path is terminated or a frame is sucessfully received. The frame is received from the underlying transport mechanisim.
Parameters:
msg - The Modbus Message object for received data to be written into
Returns:
Receive sucess flag, to indicate if the receive was sucessful.