Class 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.
    • 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 class ICommConnection
        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
      • isConnected

        public boolean isConnected()
        Specified by:
        isConnected in class ICommConnection
        Returns:
        true if connected else false
      • getInputStream

        public java.io.InputStream getInputStream()
        Specified by:
        getInputStream in class ICommConnection
        Returns:
        the InputStream of this connection
      • getOutputStream

        public java.io.OutputStream getOutputStream()
        Specified by:
        getOutputStream in class ICommConnection
        Returns:
        the OutputStream of this connection
      • 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 class ICommConnection
        Parameters:
        b - Byte array to fill
        off - 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
      • 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 class ICommConnection
        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
      • recv

        public int recv()
                 throws CommConnectionException
        Description copied from class: ICommConnection
        Receives a single byte.
        Specified by:
        recv in class ICommConnection
        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
      • send

        public void send​(byte[] senddata)
                  throws CommConnectionException
        Description copied from class: ICommConnection
        Sends data to the connected device
        Specified by:
        send in class ICommConnection
        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
      • getInfo

        public java.util.Hashtable<java.lang.String,​java.lang.Object> getInfo()
        Description copied from class: ICommConnection
        Gets Device Informations
        Specified by:
        getInfo in class ICommConnection
        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 class ICommConnection
        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 class ICommConnection
        Parameters:
        timeout - time in milliseconds
        Throws:
        CommConnectionException - possible Errorcodes:
        • for all connections
          • SET_CONFIGURATION
      • setConnectionTimeout

        public void setConnectionTimeout​(int time)
        Description copied from class: ICommConnection
        Sets the waiting time for the connection
        Specified by:
        setConnectionTimeout in class ICommConnection
        Parameters:
        time - connection timeout
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getMasterConn

        public ICommConnection getMasterConn()
        Returns:
        the masterConn