net.sourceforge.jmodbus
Class ModbusASCIITransport

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

public class ModbusASCIITransport
extends java.lang.Object
implements ModbusTransport

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


Field Summary
static byte END_FRAME_MARKER_1
          The first character of the end of frame marker for Modbus ASCII messages.
static byte END_FRAME_MARKER_2
          The first character of the end of frame marker for Modbus ASCII messages.
static int MAX_ASCII_MESSAGE_LENGTH
          The maximum length of a Modbus ASCII message that is based on the maximum length of a Modbus message, with 2 characters per byte encoding and start and end delimiters.
static byte START_FRAME_MARKER
          The start of frame marker for Modbus ASCII messages.
 
Constructor Summary
ModbusASCIITransport()
          Default constructor that will create it's own serial port connection with the default port settings.
ModbusASCIITransport(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

START_FRAME_MARKER

public static final byte START_FRAME_MARKER
The start of frame marker for Modbus ASCII messages.

END_FRAME_MARKER_1

public static final byte END_FRAME_MARKER_1
The first character of the end of frame marker for Modbus ASCII messages.

END_FRAME_MARKER_2

public static final byte END_FRAME_MARKER_2
The first character of the end of frame marker for Modbus ASCII messages.

MAX_ASCII_MESSAGE_LENGTH

public static final int MAX_ASCII_MESSAGE_LENGTH
The maximum length of a Modbus ASCII message that is based on the maximum length of a Modbus message, with 2 characters per byte encoding and start and end delimiters.

  1. start delimeter (1 byte)
  2. message body (2 * MAX_MESSAGE_LENGTH bytes)
  3. LRC (2 bytes)
  4. CR LF (2 bytes)
Constructor Detail

ModbusASCIITransport

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

ModbusASCIITransport

public ModbusASCIITransport(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.

Even if false is return the Modbus Message that is passed may be modified. It's buffer is used to save excessive array copying.

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.