net.wimpi.modbus.net
Class TCPMasterConnection

java.lang.Object
  extended by net.wimpi.modbus.net.TCPMasterConnection

public class TCPMasterConnection
extends Object

Class that implements a TCPMasterConnection.

Version:
1.2 (@date@)
Author:
Dieter Wimberger

Field Summary
private  InetAddress m_Address
           
private  boolean m_Connected
           
private  ModbusTCPTransport m_ModbusTransport
           
private  int m_Port
           
private  Socket m_Socket
           
private  int m_Timeout
           
 
Constructor Summary
TCPMasterConnection(InetAddress adr)
          Constructs a TCPMasterConnection instance with a given destination address.
 
Method Summary
 void close()
          Closes this TCPMasterConnection.
 void connect()
          Opens this TCPMasterConnection.
 InetAddress getAddress()
          Returns the destination InetAddress of this TCPMasterConnection.
 ModbusTransport getModbusTransport()
          Returns the ModbusTransport associated with this TCPMasterConnection.
 int getPort()
          Returns the destination port of this TCPMasterConnection.
 int getTimeout()
          Returns the timeout for this TCPMasterConnection.
 boolean isConnected()
          Tests if this TCPMasterConnection is connected.
private  void prepareTransport()
          Prepares the associated ModbusTransport of this TCPMasterConnection for use.
 void setAddress(InetAddress adr)
          Sets the destination InetAddress of this TCPMasterConnection.
 void setPort(int port)
          Sets the destination port of this TCPMasterConnection.
 void setTimeout(int timeout)
          Sets the timeout for this TCPMasterConnection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_Socket

private Socket m_Socket

m_Timeout

private int m_Timeout

m_Connected

private boolean m_Connected

m_Address

private InetAddress m_Address

m_Port

private int m_Port

m_ModbusTransport

private ModbusTCPTransport m_ModbusTransport
Constructor Detail

TCPMasterConnection

public TCPMasterConnection(InetAddress adr)
Constructs a TCPMasterConnection instance with a given destination address.

Parameters:
adr - the destination InetAddress.
Method Detail

connect

public void connect()
             throws Exception
Opens this TCPMasterConnection.

Throws:
Exception - if there is a network failure.

close

public void close()
Closes this TCPMasterConnection.


getModbusTransport

public ModbusTransport getModbusTransport()
Returns the ModbusTransport associated with this TCPMasterConnection.

Returns:
the connection's ModbusTransport.

prepareTransport

private void prepareTransport()
                       throws IOException
Prepares the associated ModbusTransport of this TCPMasterConnection for use.

Throws:
IOException - if an I/O related error occurs.

getTimeout

public int getTimeout()
Returns the timeout for this TCPMasterConnection.

Returns:
the timeout as int.

setTimeout

public void setTimeout(int timeout)
Sets the timeout for this TCPMasterConnection.

Parameters:
timeout - the timeout as int.

getPort

public int getPort()
Returns the destination port of this TCPMasterConnection.

Returns:
the port number as int.

setPort

public void setPort(int port)
Sets the destination port of this TCPMasterConnection. The default is defined as Modbus.DEFAULT_PORT.

Parameters:
port - the port number as int.

getAddress

public InetAddress getAddress()
Returns the destination InetAddress of this TCPMasterConnection.

Returns:
the destination address as InetAddress.

setAddress

public void setAddress(InetAddress adr)
Sets the destination InetAddress of this TCPMasterConnection.

Parameters:
adr - the destination address as InetAddress.

isConnected

public boolean isConnected()
Tests if this TCPMasterConnection is connected.

Returns:
true if connected, false otherwise.


Copyright © 2012. All Rights Reserved.