Package com.metratec.lib.connection
Class MpsLegacyTunnelConnection
- java.lang.Object
-
- com.metratec.lib.connection.ICommConnection
-
- com.metratec.lib.connection.MpsTunnelConnection
-
- com.metratec.lib.connection.MpsLegacyTunnelConnection
-
public class MpsLegacyTunnelConnection extends MpsTunnelConnection
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 then be used to opaquely tunnel data to and from the slave device. This class uses DAT command to communicate to the slave device instead of BINXT commands used by the `MpsTunnelConnection`. Thus the class supports legacy beacons/MPS version that only use the DAT protocol. Every datastream must at the time of the flush, this includes `send()` call, must end in CR and have CRs in the right distance. This also means that `MpsLegacyTunnelConnection` may not be used as a drop-in for existing ICommConnections in every situation (if the code breaks these restrictions). Just as `MpsTunnelConnection`, both outgoing and incoming data may be duplicated, making this even less fit to drop into some existing ICommConnection-user. `MpsTunnelConnection` should always be preferred if the circumstances allow it. bug Furthermore, you cannot currently send more than one CR-terminated line before flushing and users must check for errors, which are MPS-specific, like `TOE` manually in their code. This can and should all be handled within the class.
-
-
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 MpsLegacyTunnelConnection(ICommConnection connection)
Construct a MPS Tunneling Connection.MpsLegacyTunnelConnection(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.void
disconnect()
Closes the communication interfacejava.io.InputStream
getInputStream()
java.io.OutputStream
getOutputStream()
boolean
isLinked()
Returns whether to use linked communication.void
send(byte[] senddata)
Sends data to the connected devicevoid
setLinked(boolean linked)
Sets whether to use linked communication or not.java.lang.String
toString()
-
Methods inherited from class com.metratec.lib.connection.MpsTunnelConnection
dataAvailable, getConnectionTimeout, getInfo, getLinkTimeout, getMasterConn, getMaxFrameSize, getRecvTimeout, isConnected, receive, recv, recv, setConnectionTimeout, setLinkTimeout, setMaxFrameSize, setRecvTimeout, setSettings
-
Methods inherited from class com.metratec.lib.connection.ICommConnection
recv, recv, send
-
-
-
-
Constructor Detail
-
MpsLegacyTunnelConnection
public MpsLegacyTunnelConnection(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.
-
MpsLegacyTunnelConnection
public MpsLegacyTunnelConnection(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
-
setLinked
public void setLinked(boolean linked)
Sets whether to use linked communication or not. This must only be set before a connection established. Once the connection is established one this value can only be modified after a disconnect is called.- Parameters:
linked
- true if linked communication should be used, false otherwise
-
isLinked
public boolean isLinked()
Returns whether to use linked communication.- Returns:
- true if linked communication is being used, false otherwise
-
connect
public void connect() throws CommConnectionException
Description copied from class:ICommConnection
This method opens a connection. Parameters are passed through the constructor- Overrides:
connect
in classMpsTunnelConnection
- 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:
-
disconnect
public void disconnect() throws CommConnectionException
Description copied from class:ICommConnection
Closes the communication interface- Overrides:
disconnect
in classMpsTunnelConnection
- Throws:
CommConnectionException
- possible Errorcodes:- for TCP Connection:
- UNHANDLED_ERROR
- for USB Connection:
- UNHANDLED_ERROR
- for TCP Connection:
-
getInputStream
public java.io.InputStream getInputStream()
- Overrides:
getInputStream
in classMpsTunnelConnection
- Returns:
- the
InputStream
of this connection
-
getOutputStream
public java.io.OutputStream getOutputStream()
- Overrides:
getOutputStream
in classMpsTunnelConnection
- Returns:
- the
OutputStream
of this connection
-
send
public void send(byte[] senddata) throws CommConnectionException
Description copied from class:ICommConnection
Sends data to the connected device- Overrides:
send
in classMpsTunnelConnection
- 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:
-
toString
public java.lang.String toString()
- Overrides:
toString
in classMpsTunnelConnection
-
-