Class TcpConnection

    • Constructor Detail

      • TcpConnection

        public TcpConnection​(java.lang.String ip,
                             int port)
        Construct a new TCPIPConnection class, with the given parameters.
        Parameters:
        ip - Device IP address
        port - Device port
      • TcpConnection

        public TcpConnection​(java.net.Socket socket,
                             boolean isServerConnection)
                      throws CommConnectionException
        Parameters:
        socket - the new socket
        isServerConnection - set to true if the connection is created by accepting a client - so no reconnect is available
        Throws:
        CommConnectionException - throwed with error code ICommConnection.NOT_INITIALISED if the given socket is not connected
    • Method Detail

      • 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
      • send

        public void send​(java.lang.String senddata)
                  throws CommConnectionException
        Description copied from class: ICommConnection
        Sends data to the connected device
        Overrides:
        send in class ICommConnection
        Parameters:
        senddata - data/command send to the 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
      • 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
      • toString

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