Class ICommConnection

    • Constructor Summary

      Constructors 
      Constructor Description
      ICommConnection()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract void connect()
      This method opens a connection.
      abstract int dataAvailable()  
      abstract void disconnect()
      Closes the communication interface
      abstract int getConnectionTimeout()  
      abstract java.util.Hashtable<java.lang.String,​java.lang.Object> getInfo()
      Gets Device Informations
      abstract java.io.InputStream getInputStream()  
      abstract java.io.OutputStream getOutputStream()  
      abstract int getRecvTimeout()  
      abstract boolean isConnected()  
      java.lang.StringBuilder receive​(int... terminators)
      Receives data from the connected device until one of the terminator signs is found.
      abstract int recv()
      Receives a single byte.
      void recv​(byte[] b)
      Receive bytes until buffer is filled or timeout occurrs.
      void recv​(byte[] b, int off, int len)
      Receives until buffer is filled or timeout occurrs.
      java.lang.String recv​(int... terminators)
      Receives data from the connected device until one of the terminator signs is found.
      abstract void send​(byte[] senddata)
      Sends data to the connected device
      void send​(java.lang.String senddata)
      Sends data to the connected device
      abstract void setConnectionTimeout​(int timeout)
      Sets the waiting time for the connection
      abstract 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 valid
      abstract void setSettings​(java.util.Hashtable<java.lang.String,​java.lang.String> settings)
      Sets connections settings
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SERIAL_PORT_NOT_EXIST

        public static final int SERIAL_PORT_NOT_EXIST
        specified serial port not exist
        See Also:
        Constant Field Values
      • SERIAL_PARAMETER_NOT_SET

        public static final int SERIAL_PARAMETER_NOT_SET
        could not set interface parameter
        See Also:
        Constant Field Values
      • SERIAL_NO_ACCESS

        public static final int SERIAL_NO_ACCESS
        no access to the input/output stream
        See Also:
        Constant Field Values
      • SERIAL_NOT_INITIALISED

        public static final int SERIAL_NOT_INITIALISED
        could not initialize the rs232 connection
        See Also:
        Constant Field Values
      • USB_SET_BAUDRATE

        public static final int USB_SET_BAUDRATE
        Set baudrate for the usb connection failed
        See Also:
        Constant Field Values
      • USB_SET_DATA_CHARACTERISTICS

        public static final int USB_SET_DATA_CHARACTERISTICS
        set data characteristics for the usb connection failed
        See Also:
        Constant Field Values
      • USB_SET_FLOWCONTROL

        public static final int USB_SET_FLOWCONTROL
        set flow control for the usb connection failed
        See Also:
        Constant Field Values
      • USB_SET_TIMEOUTS

        public static final int USB_SET_TIMEOUTS
        set timeouts for the usb connection failed
        See Also:
        Constant Field Values
      • ETHERNET_TIMEOUT

        public static final int ETHERNET_TIMEOUT
        Ethernet connection timeout
        See Also:
        Constant Field Values
      • ETHERNET_UNKNOWN_HOST

        public static final int ETHERNET_UNKNOWN_HOST
        host not found
        See Also:
        Constant Field Values
      • USER_ERRORCODE_01

        public static final int USER_ERRORCODE_01
        for individual use
        See Also:
        Constant Field Values
      • USER_ERRORCODE_02

        public static final int USER_ERRORCODE_02
        for individual use
        See Also:
        Constant Field Values
      • USER_ERRORCODE_03

        public static final int USER_ERRORCODE_03
        for individual use
        See Also:
        Constant Field Values
      • USER_ERRORCODE_04

        public static final int USER_ERRORCODE_04
        for individual use
        See Also:
        Constant Field Values
      • USER_ERRORCODE_05

        public static final int USER_ERRORCODE_05
        for individual use
        See Also:
        Constant Field Values
      • UNHANDLED_ERROR

        public static final int UNHANDLED_ERROR
        error which is not specifically defined
        See Also:
        Constant Field Values
      • NO_LIBRARY_FOUND

        public static final int NO_LIBRARY_FOUND
        could not find the needed java library for the connection
        See Also:
        Constant Field Values
      • NO_DEVICES_FOUND

        public static final int NO_DEVICES_FOUND
        no devices for a connection found
        See Also:
        Constant Field Values
      • DEVICE_IN_USE

        public static final int DEVICE_IN_USE
        device is in use, could no connect
        See Also:
        Constant Field Values
      • WRONG_PARAMETER

        public static final int WRONG_PARAMETER
        wrong parameter
        See Also:
        Constant Field Values
      • CONNECTION_LOST

        public static final int CONNECTION_LOST
        lost the connection
        See Also:
        Constant Field Values
      • SET_CONFIGURATION

        public static final int SET_CONFIGURATION
        error while setting parameters
        See Also:
        Constant Field Values
      • NOT_INITIALISED

        public static final int NOT_INITIALISED
        connection is not initializes
        See Also:
        Constant Field Values
      • RECV_TIMEOUT

        public static final int RECV_TIMEOUT
        no data arrive during the receive timeout
        See Also:
        Constant Field Values
      • NOT_AVAILABLE

        public static final int NOT_AVAILABLE
        not available - method is not available
        See Also:
        Constant Field Values
    • Constructor Detail

      • ICommConnection

        public ICommConnection()
    • Method Detail

      • connect

        public abstract void connect()
                              throws CommConnectionException
        This method opens a connection. Parameters are passed through the constructor
        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
      • disconnect

        public abstract void disconnect()
                                 throws CommConnectionException
        Closes the communication interface
        Throws:
        CommConnectionException - possible Errorcodes:
        • for TCP Connection:
          • UNHANDLED_ERROR
        • for USB Connection:
          • UNHANDLED_ERROR
      • send

        public void send​(java.lang.String senddata)
                  throws CommConnectionException
        Sends data to the connected device
        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
      • send

        public abstract void send​(byte[] senddata)
                           throws CommConnectionException
        Sends data to the connected device
        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
      • recv

        public java.lang.String recv​(int... terminators)
                              throws CommConnectionException
        Receives data from the connected device until one of the terminator signs is found.
        Parameters:
        terminators - A list of terminator signs. Note that this may be a list of parameters or an array.
        Returns:
        String with the data, 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
      • receive

        public java.lang.StringBuilder receive​(int... terminators)
                                        throws CommConnectionException
        Receives data from the connected device until one of the terminator signs is found. The result is returned as a StringBuilder for performance reasons.
        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 abstract int recv()
                          throws CommConnectionException
        Receives a single byte.
        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
      • recv

        public void recv​(byte[] b,
                         int off,
                         int len)
                  throws CommConnectionException
        Receives until buffer is filled or timeout occurrs.
        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
      • recv

        public void recv​(byte[] b)
                  throws CommConnectionException
        Receive bytes until buffer is filled or timeout occurrs.
        Parameters:
        b - Buffer to fill.
        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
      • isConnected

        public abstract boolean isConnected()
        Returns:
        true if connected else false
      • getInfo

        public abstract java.util.Hashtable<java.lang.String,​java.lang.Object> getInfo()
        Gets Device Informations
        Returns:
        Hashtable with the information
      • setSettings

        public abstract void setSettings​(java.util.Hashtable<java.lang.String,​java.lang.String> settings)
        Sets connections settings
        Parameters:
        settings - Hashtable with the special settings
      • getInputStream

        public abstract java.io.InputStream getInputStream()
        Returns:
        the InputStream of this connection
      • getOutputStream

        public abstract java.io.OutputStream getOutputStream()
        Returns:
        the OutputStream of this connection
      • setRecvTimeout

        public abstract void setRecvTimeout​(int timeout)
                                     throws CommConnectionException
        set the receive timeout for read data, if the timeout expires an CommConnectionException is raised with errorcode RECV_TIMEOUT, the connection is still valid
        Parameters:
        timeout - time in milliseconds
        Throws:
        CommConnectionException - possible Errorcodes:
        • for all connections
          • SET_CONFIGURATION
      • getRecvTimeout

        public abstract int getRecvTimeout()
        Returns:
        the receive timeout
      • setConnectionTimeout

        public abstract void setConnectionTimeout​(int timeout)
        Sets the waiting time for the connection
        Parameters:
        timeout - connection timeout
      • getConnectionTimeout

        public abstract int getConnectionTimeout()
        Returns:
        the waiting time for the connection