Class JSCSerial

java.lang.Object
de.gmxhome.conrad.jSerialComm.JSCSerial
All Implemented Interfaces:
SerialIOAdapter, AutoCloseable

public class JSCSerial extends Object implements SerialIOAdapter
Implementation of SerialIOAdapter using jSerialComm framework.
  • Constructor Details

    • JSCSerial

      public JSCSerial()
      Constructor. Creates communication adapter.
  • Method Details

    • open

      public void open(String port) throws IOException
      Description copied from interface: SerialIOAdapter
      Opens a port for serial IO.
      Specified by:
      open in interface SerialIOAdapter
      Parameters:
      port - Port. e.g. COM2
      Throws:
      IOException - If the port does not exist or in case of IO errors.
    • close

      public void close() throws IOException
      Description copied from interface: SerialIOAdapter
      Close the communication port.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SerialIOAdapter
      Throws:
      IOException - In case of IO error.
    • setParameters

      public void setParameters(int baudrate, int databits, int stopbits, int parity) throws IOException
      Description copied from interface: SerialIOAdapter
      Set communication parameters for speed, data size and frame structure.
      baudrate specifies the baud rate, databits the number of data bits, stopbits the number of stop bits per data unit and parity the kind of parity bit, if parity shall be used. Keep in mind that these constants can vary between adapter implementations. The application should use method getCommunicationConstants to retrieve the valid constant values and the corresponding adapter independent values.
      Specified by:
      setParameters in interface SerialIOAdapter
      Parameters:
      baudrate - Baud rate.
      databits - Bits per date unit.
      stopbits - Number of stop bits to be used.
      parity - Parity constant.
      Throws:
      IOException - If an IO error occurs of if a parameter is invalid.
    • available

      public int available() throws IOException
      Description copied from interface: SerialIOAdapter
      Returns the number of received bytes that can be read without blocking.
      Specified by:
      available in interface SerialIOAdapter
      Returns:
      Number of bytes just in device input buffer.
      Throws:
      IOException - In case of an IO error
    • read

      public byte[] read(int count, int timeout) throws IOException
      Description copied from interface: SerialIOAdapter
      Reads data from a communication port. If no data are available, read blocks until data are available or the specified timeout has been reached.
      Specified by:
      read in interface SerialIOAdapter
      Parameters:
      count - Maximum number of bytes to be read.
      timeout - Maximum time to wait for data in milliseconds.
      Returns:
      byte array holding all available data bytes
      Throws:
      IOException - In case of an IO error.
    • write

      public void write(byte[] buffer) throws IOException
      Description copied from interface: SerialIOAdapter
      Write the given byte buffer to the com port.
      Specified by:
      write in interface SerialIOAdapter
      Parameters:
      buffer - Buffer to be written
      Throws:
      IOException - If the port has not been opened or in case of an IO error.
    • flush

      public void flush() throws IOException
      Description copied from interface: SerialIOAdapter
      Flushed input and output buffers.
      Specified by:
      flush in interface SerialIOAdapter
      Throws:
      IOException - In case of an IO error.
    • exits

      public boolean exits(String port)
      Description copied from interface: SerialIOAdapter
      Checks whether a port still exists. In case of serial communication via Bluetooth or USB, ports can go lost.
      Specified by:
      exits in interface SerialIOAdapter
      Parameters:
      port - Port to be checked.
      Returns:
      true if the port still exists, false otherwise-
    • getCommunicationConstants

      public int[][] getCommunicationConstants(int constantType)
      Description copied from interface: SerialIOAdapter
      Retrieves an array of integer pairs specifying all valid parameters for the given constant type. constantType can be one of T_BAUD, T_DATA, T_STOP or T_PARITY. The method returns an array of integer pairs where the first element specifies the constant value to be passed to the setParameters method of the SerialIOProcessor and the second element specifies the corresponding value to be passed to the setParameters method of the specific SerialIOAdapter implementation.
      Specified by:
      getCommunicationConstants in interface SerialIOAdapter
      Parameters:
      constantType - Type of constants to be requested.
      Returns:
      Array of integer pairs containing the adapter independent and adapter specific constants of the requested type. null if constantType is invalid.