net.sourceforge.jmodbus
Class ModbusRTUTransport

java.lang.Object
  |
  +--net.sourceforge.jmodbus.ModbusRTUTransport
All Implemented Interfaces:
ModbusTransport

public class ModbusRTUTransport
extends java.lang.Object
implements ModbusTransport

Class to implement a RTU transport mechanisim for Modbus communication. This will allow a decice to communicate a serial link, using RTU (binary) encoding of the data.


Field Summary
static double FRAME_SEPERATOR_LENGTH
          Frame seperator length.
static int MAX_RTU_MESSAGE_LENGTH
          The maximum length of a Modbus RTU message which is the maximum Modbus message length plus one byte for the CRC16.
 
Constructor Summary
ModbusRTUTransport()
          Default constructor that will create it's own serial port connection with the default port settings.
ModbusRTUTransport(javax.comm.SerialPort port)
          Constructor that passes a open serial port.
 
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

FRAME_SEPERATOR_LENGTH

public static double FRAME_SEPERATOR_LENGTH
Frame seperator length. This is the number of character times that is defined as a break in the modbus RTU protocol.

MAX_RTU_MESSAGE_LENGTH

public static int MAX_RTU_MESSAGE_LENGTH
The maximum length of a Modbus RTU message which is the maximum Modbus message length plus one byte for the CRC16.
Constructor Detail

ModbusRTUTransport

public ModbusRTUTransport()
Default constructor that will create it's own serial port connection with the default port settings.

ModbusRTUTransport

public ModbusRTUTransport(javax.comm.SerialPort port)
Constructor that passes a open serial port. The serial port may have any parameters, but must alredy be opened, ready for communication.
Parameters:
port - The serial port to conduct serial communications over.
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.
Specified by:
sendFrame in interface ModbusTransport
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.
Specified by:
receiveFrame in interface ModbusTransport
Parameters:
msg - The Modbus Message object for received data to be written into
Returns:
Receive sucess flag, to indicate if the receive was sucessful.