Class FileConnection


  • public class FileConnection
    extends ICommConnection
    This is an implementation of ICommConnection that relies only on standard JRE file APIs. This is useful on embedded systems instead of Rs232Connection/UsbConnection since it does not require any JNI. Line settings can be set externally on the device node using `stty` before launching the program.
    • Constructor Detail

      • FileConnection

        public FileConnection​(java.lang.String portName)
    • Method Detail

      • connect

        public void connect()
                     throws CommConnectionException
        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
      • 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
      • 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
      • isConnected

        public boolean isConnected()
        Specified by:
        isConnected in class ICommConnection
        Returns:
        true if connected else false
      • 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
      • 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
      • setRecvTimeout

        public void setRecvTimeout​(int timeout)
        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
      • setConnectionTimeout

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