Package com.metratec.lib.connection
Class MpsTunnelConnection
- java.lang.Object
-
- com.metratec.lib.connection.ICommConnection
-
- com.metratec.lib.connection.MpsTunnelConnection
-
- Direct Known Subclasses:
MpsLegacyTunnelConnection
public class MpsTunnelConnection extends ICommConnection
A connection to a slave device behind a MPS Master (MPS Beacon, BraceID, etc.). The connection to the master can be established by any means. The MPS must be correctly set up before calling MpsTunnelConnection.connect(). The link to the slave device can either be established in advance or you pass an EID to the constructor. This class may than be used to opaquely tunnel data to and from the slave device. Unfortunately at least with some versions of the MPS, due to shortcomings in the retransmission algorithms used, frames may be duplicated, which manifests itself in both outgoing and incoming data duplication not present in other ICommConnection implementations.
-
-
Field Summary
-
Fields inherited from class com.metratec.lib.connection.ICommConnection
CONNECTION_LOST, DEVICE_IN_USE, ETHERNET_TIMEOUT, ETHERNET_UNKNOWN_HOST, NO_DEVICES_FOUND, NO_LIBRARY_FOUND, NOT_AVAILABLE, NOT_INITIALISED, RECV_TIMEOUT, SERIAL_NO_ACCESS, SERIAL_NOT_INITIALISED, SERIAL_PARAMETER_NOT_SET, SERIAL_PORT_NOT_EXIST, SET_CONFIGURATION, UNHANDLED_ERROR, USB_SET_BAUDRATE, USB_SET_DATA_CHARACTERISTICS, USB_SET_FLOWCONTROL, USB_SET_TIMEOUTS, USER_ERRORCODE_01, USER_ERRORCODE_02, USER_ERRORCODE_03, USER_ERRORCODE_04, USER_ERRORCODE_05, WRONG_PARAMETER
-
-
Constructor Summary
Constructors Constructor Description MpsTunnelConnection(ICommConnection connection)
Construct a MPS Tunneling Connection.MpsTunnelConnection(ICommConnection connection, java.lang.String slaveEID)
Construct a MPS Tunneling Connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connect()
This method opens a connection.int
dataAvailable()
void
disconnect()
Closes the communication interfaceint
getConnectionTimeout()
java.util.Hashtable<java.lang.String,java.lang.Object>
getInfo()
Gets Device Informationsjava.io.InputStream
getInputStream()
int
getLinkTimeout()
Gets the link timeout for linking to a slave device.ICommConnection
getMasterConn()
int
getMaxFrameSize()
Gets the maximum BINXT frame size.java.io.OutputStream
getOutputStream()
int
getRecvTimeout()
boolean
isConnected()
java.lang.StringBuilder
receive(int... terminators)
Receives data from the connected device until one of the terminator signs is found.int
recv()
Receives a single byte.void
recv(byte[] b, int off, int len)
Receives until buffer is filled or timeout occurrs.void
send(byte[] senddata)
Sends data to the connected devicevoid
setConnectionTimeout(int time)
Sets the waiting time for the connectionvoid
setLinkTimeout(int linkTimeout)
Sets the link timeout for linking to a slave device.void
setMaxFrameSize(int maxFrameSize)
Sets the maximum BINXT frame size.void
setRecvTimeout(int timeout)
set the receive timeout for read data, if the timeout expires an CommConnectionException is raised with errorcode RECV_TIMEOUT, the connection is still validvoid
setSettings(java.util.Hashtable<java.lang.String,java.lang.String> settings)
Sets connections settingsjava.lang.String
toString()
-
Methods inherited from class com.metratec.lib.connection.ICommConnection
recv, recv, send
-
-
-
-
Constructor Detail
-
MpsTunnelConnection
public MpsTunnelConnection(ICommConnection connection, java.lang.String slaveEID)
Construct a MPS Tunneling Connection. A link to the slave device will be established during connect().- Parameters:
connection
- The connection to the master device (MPS).slaveEID
- The slave's EID (8 bytes hexadecimal string) or null.
-
MpsTunnelConnection
public MpsTunnelConnection(ICommConnection connection)
Construct a MPS Tunneling Connection. The link to the slave device must already be established.- Parameters:
connection
- The connection to the master device (MPS).
-
-
Method Detail
-
getLinkTimeout
public int getLinkTimeout()
Gets the link timeout for linking to a slave device.- Returns:
- the link timeout (in milliseconds)
-
setLinkTimeout
public void setLinkTimeout(int linkTimeout)
Sets the link timeout for linking to a slave device. The parameter controls the time to wait until a response to the link command arrives.- Parameters:
linkTimeout
- the link timeout (in milliseconds)
-
getMaxFrameSize
public int getMaxFrameSize()
Gets the maximum BINXT frame size.- Returns:
- frame size in bytes
-
setMaxFrameSize
public void setMaxFrameSize(int maxFrameSize)
Sets the maximum BINXT frame size.- Parameters:
maxFrameSize
- frame size in bytes
-
connect
public void connect() throws CommConnectionException
Description copied from class:ICommConnection
This method opens a connection. Parameters are passed through the constructor- Specified by:
connect
in classICommConnection
- Throws:
CommConnectionException
- possible Errorcodes:- for TCP Connection:
- ETHERNET_UNKNOWN_HOST
- ETHERNET_TIMEOUT
- WRONG_PARAMETER
- for USB Connection:
- DEVICE_IN_USE
- NO_LIBRARY_FOUND
- NO_DEVICES_FOUND
- USB_SET_BAUDRATE
- USB_SET_DATA_CHARACTERISTICS
- USB_SET_FLOWCONTROL
- USB_SET_TIMEOUTS
- for RS232 Connection:
- NO_LIBRARY_FOUND
- SERIAL_PORT_NOT_EXIST
- SERIAL_PARAMETER_NOT_SET
- DEVICE_IN_USE
- SERIAL_NO_ACCESS
- SERIAL_NO_INITIALISE
- for TCP Connection:
-
isConnected
public boolean isConnected()
- Specified by:
isConnected
in classICommConnection
- Returns:
- true if connected else false
-
disconnect
public void disconnect() throws CommConnectionException
Description copied from class:ICommConnection
Closes the communication interface- Specified by:
disconnect
in classICommConnection
- Throws:
CommConnectionException
- possible Errorcodes:- for TCP Connection:
- UNHANDLED_ERROR
- for USB Connection:
- UNHANDLED_ERROR
- for TCP Connection:
-
getInputStream
public java.io.InputStream getInputStream()
- Specified by:
getInputStream
in classICommConnection
- Returns:
- the
InputStream
of this connection
-
getOutputStream
public java.io.OutputStream getOutputStream()
- Specified by:
getOutputStream
in classICommConnection
- Returns:
- the
OutputStream
of this connection
-
dataAvailable
public int dataAvailable() throws CommConnectionException
- Specified by:
dataAvailable
in classICommConnection
- Returns:
- number of available signs
- Throws:
CommConnectionException
- possible Errorcodes:- for all connections
- CONNECTION_LOST
- NOT_INITIALISE
- for all connections
-
recv
public void recv(byte[] b, int off, int len) throws CommConnectionException
Description copied from class:ICommConnection
Receives until buffer is filled or timeout occurrs.- Overrides:
recv
in classICommConnection
- Parameters:
b
- Byte array to filloff
- Offset into array (it is filled beginning with the offset)len
- Number of bytes to read.- Throws:
CommConnectionException
- possible Errorcodes:- for TCP Connection:
- CONNECTION_LOST
- RECV_TIMEOUT
- UNHANDLED_ERROR
- NOT_INITIALISE
- for USB Connection:
- CONNECTION_LOST
- RECV_TIMEOUT
- UNHANDLED_ERROR
- NOT_INITIALISE
- for RS232 Connection:
- CONNECTION_LOST
- RECV_TIMEOUT
- UNHANDLED_ERROR
- NOT_INITIALISE
- for TCP Connection:
-
receive
public java.lang.StringBuilder receive(int... terminators) throws CommConnectionException
Description copied from class:ICommConnection
Receives data from the connected device until one of the terminator signs is found. The result is returned as a StringBuilder for performance reasons.- Overrides:
receive
in classICommConnection
- Parameters:
terminators
- A list of terminator signs. Note that this may be a list of parameters or an array.- Returns:
- a StringBuilder object, including the termination sign
- Throws:
CommConnectionException
- possible Errorcodes:- for TCP Connection:
- CONNECTION_LOST
- RECV_TIMEOUT
- UNHANDLED_ERROR
- NOT_INITIALISE
- for USB Connection:
- CONNECTION_LOST
- RECV_TIMEOUT
- UNHANDLED_ERROR
- NOT_INITIALISE
- for RS232 Connection:
- CONNECTION_LOST
- RECV_TIMEOUT
- UNHANDLED_ERROR
- NOT_INITIALISE
- for TCP Connection:
-
recv
public int recv() throws CommConnectionException
Description copied from class:ICommConnection
Receives a single byte.- Specified by:
recv
in classICommConnection
- Returns:
- byte or -1 if no Data available (timeout)
- Throws:
CommConnectionException
- possible Errorcodes:- for TCP Connection:
- CONNECTION_LOST
- UNHANDLED_ERROR
- NOT_INITIALISE
- for USB Connection:
- CONNECTION_LOST
- UNHANDLED_ERROR
- NOT_INITIALISE
- for RS232 Connection:
- CONNECTION_LOST
- UNHANDLED_ERROR
- NOT_INITIALISE
- for TCP Connection:
-
send
public void send(byte[] senddata) throws CommConnectionException
Description copied from class:ICommConnection
Sends data to the connected device- Specified by:
send
in classICommConnection
- Parameters:
senddata
- data/command send to the connected device- Throws:
CommConnectionException
- possible Errorcodes:- for TCP Connection:
- WRONG_PARAMETER
- UNHANDLED_ERROR
- NOT_INITIALISE
- for USB Connection:
- WRONG_PARAMETER
- UNHANDLED_ERROR
- NOT_INITIALISE
- for RS232 Connection:
- WRONG_PARAMETER
- CONNECTION_LOST
- UNHANDLED_ERROR
- NOT_INITIALISE
- for TCP Connection:
-
getInfo
public java.util.Hashtable<java.lang.String,java.lang.Object> getInfo()
Description copied from class:ICommConnection
Gets Device Informations- Specified by:
getInfo
in classICommConnection
- Returns:
- Hashtable with the information
-
setSettings
public void setSettings(java.util.Hashtable<java.lang.String,java.lang.String> settings)
Description copied from class:ICommConnection
Sets connections settings- Specified by:
setSettings
in classICommConnection
- Parameters:
settings
- Hashtable with the special settings
-
setRecvTimeout
public void setRecvTimeout(int timeout) throws CommConnectionException
Description copied from class:ICommConnection
set the receive timeout for read data, if the timeout expires an CommConnectionException is raised with errorcode RECV_TIMEOUT, the connection is still valid- Specified by:
setRecvTimeout
in classICommConnection
- Parameters:
timeout
- time in milliseconds- Throws:
CommConnectionException
- possible Errorcodes:- for all connections
- SET_CONFIGURATION
- for all connections
-
getRecvTimeout
public int getRecvTimeout()
- Specified by:
getRecvTimeout
in classICommConnection
- Returns:
- the receive timeout
-
setConnectionTimeout
public void setConnectionTimeout(int time)
Description copied from class:ICommConnection
Sets the waiting time for the connection- Specified by:
setConnectionTimeout
in classICommConnection
- Parameters:
time
- connection timeout
-
getConnectionTimeout
public int getConnectionTimeout()
- Specified by:
getConnectionTimeout
in classICommConnection
- Returns:
- the waiting time for the connection
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getMasterConn
public ICommConnection getMasterConn()
- Returns:
- the masterConn
-
-