net.sourceforge.jmodbus
Class ModbusTCPTransport

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

public class ModbusTCPTransport
extends java.lang.Object
implements ModbusTransport

Class to implement a TCP transport mechanisim for Modbus communication. This will allow a decice to communicate via ModbusTCP, also known as Modnet.


Field Summary
static int DATA_MAX
          The maximum number of bytes in the body of a Modbus TCP packet.
static int HEADER_LENGTH
          The length (in bytes) of the header of a Modbus TCP packet.
static int MAX_TRANSACTION_LENGTH
          The maximum length (in bytes) of a Modbus TCP packet.
static int MODBUS_TCP_PORT
          The TCP port number that Modbus TCP services should operate over.
static short PROTOCOL_IDENTIFIER
          The protocol identifier for Modbus TCP.
 
Constructor Summary
ModbusTCPTransport(java.net.Socket socket)
          Constructor for the ModbusTCPTransport.
ModbusTCPTransport(java.lang.String host, int port)
          Constructor for the ModbusTCPTransport.
 
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

MODBUS_TCP_PORT

public static final int MODBUS_TCP_PORT
The TCP port number that Modbus TCP services should operate over.

HEADER_LENGTH

public static final int HEADER_LENGTH
The length (in bytes) of the header of a Modbus TCP packet.

DATA_MAX

public static final int DATA_MAX
The maximum number of bytes in the body of a Modbus TCP packet.

MAX_TRANSACTION_LENGTH

public static final int MAX_TRANSACTION_LENGTH
The maximum length (in bytes) of a Modbus TCP packet.

PROTOCOL_IDENTIFIER

public static final short PROTOCOL_IDENTIFIER
The protocol identifier for Modbus TCP. This value is used to confirm that a message is acually a modbus TCP message and not some other data.
Constructor Detail

ModbusTCPTransport

public ModbusTCPTransport(java.net.Socket socket)
Constructor for the ModbusTCPTransport. The class requires a socket to communicate over. This constructor passes a reference to this socket

ModbusTCPTransport

public ModbusTCPTransport(java.lang.String host,
                          int port)
Constructor for the ModbusTCPTransport. The class requires a socket to communicate over. This constructor will create a new socket on the specified port to the specified host.
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.