Class SerialIOProcessor

java.lang.Object
de.gmxhome.conrad.jpos.jpos_base.UniqueIOProcessor
de.gmxhome.conrad.jpos.jpos_base.SerialIOProcessor
All Implemented Interfaces:
AutoCloseable

public class SerialIOProcessor extends UniqueIOProcessor
Class to process serial communication. Current implementation uses jSSC implementation for serial communication. Includes functionality for automatic data logging.
  • Field Details

    • BAUDRATE_1200

      public static final int BAUDRATE_1200
      Baudrate constant for 1200 baud.
      See Also:
      Constant Field Values
    • BAUDRATE_2400

      public static final int BAUDRATE_2400
      Baudrate constant for 2400 baud.
      See Also:
      Constant Field Values
    • BAUDRATE_4800

      public static final int BAUDRATE_4800
      Baudrate constant for 4800 baud.
      See Also:
      Constant Field Values
    • BAUDRATE_9600

      public static final int BAUDRATE_9600
      Baudrate constant for 9600 baud.
      See Also:
      Constant Field Values
    • BAUDRATE_19200

      public static final int BAUDRATE_19200
      Baudrate constant for 19200 baud.
      See Also:
      Constant Field Values
    • BAUDRATE_38400

      public static final int BAUDRATE_38400
      Baudrate constant for 38400 baud.
      See Also:
      Constant Field Values
    • BAUDRATE_57600

      public static final int BAUDRATE_57600
      Baudrate constant for 57600 baud.
      See Also:
      Constant Field Values
    • BAUDRATE_115200

      public static final int BAUDRATE_115200
      Baudrate constant for 115200 baud.
      See Also:
      Constant Field Values
    • BAUDRATE_128000

      public static final int BAUDRATE_128000
      Baudrate constant for 128000 baud.
      See Also:
      Constant Field Values
    • BAUDRATE_256000

      public static final int BAUDRATE_256000
      Baudrate constant for 256000 baud.
      See Also:
      Constant Field Values
    • Baudrate

      protected int Baudrate
      Baudrate to be used. Default: BAUDRATE_9600.
    • PARITY_NONE

      public static final int PARITY_NONE
      Parity constant for no parity.
      See Also:
      Constant Field Values
    • PARITY_ODD

      public static final int PARITY_ODD
      Parity constant for odd parity.
      See Also:
      Constant Field Values
    • PARITY_EVEN

      public static final int PARITY_EVEN
      Parity constant for even parity.
      See Also:
      Constant Field Values
    • PARITY_MARK

      public static final int PARITY_MARK
      Parity constant for mark parity.
      See Also:
      Constant Field Values
    • PARITY_SPACE

      public static final int PARITY_SPACE
      Parity constant for space parity.
      See Also:
      Constant Field Values
    • Parity

      protected int Parity
      Parity to be used. Default: PARITY_NONE.
    • DATABITS_7

      public static final int DATABITS_7
      Constant for 7 bit data size.
      See Also:
      Constant Field Values
    • DATABITS_8

      public static final int DATABITS_8
      Constant for 8 bit data size.
      See Also:
      Constant Field Values
    • Databits

      protected int Databits
      Data bits to be used. Default: DATABITS_8.
    • STOPBITS_1

      public static final int STOPBITS_1
      Constant for serial communication using 1 stop bit.
      See Also:
      Constant Field Values
    • STOPBITS_2

      public static final int STOPBITS_2
      Constant for serial communication using 2 stop bits.
      See Also:
      Constant Field Values
    • Stopbits

      protected int Stopbits
      Stop bits to be used. Default: STOPBITS_2.
  • Constructor Details

    • SerialIOProcessor

      public SerialIOProcessor(JposDevice usingDevice, String portName) throws jpos.JposException
      Creates simple serial connector for given port
      Parameters:
      usingDevice - Device that uses the proceessor. Processor uses logging of device to produce logging entries
      portName - Name of port. Example: COM1
      Throws:
      jpos.JposException - Will not be thrown in case of serial communication.
  • Method Details

    • write

      public int write(byte[] buffer) throws jpos.JposException
      Description copied from class: UniqueIOProcessor
      Write a frame to the communication target. If called from a derived class, the byte array must be passed through unchanged for correct logging.
      Overrides:
      write in class UniqueIOProcessor
      Parameters:
      buffer - byte buffer containing the frame
      Returns:
      Number of bytes written to the target
      Throws:
      jpos.JposException - if something goes wrong
    • available

      public int available() throws jpos.JposException
      Description copied from class: UniqueIOProcessor
      Retrieves no. of readable units from communication source. If called from a derived class, LoggingData must be filled with the count to be returned.
      Overrides:
      available in class UniqueIOProcessor
      Returns:
      Unit count
      Throws:
      jpos.JposException - if something goes wrong
    • read

      public byte[] read(int count) throws jpos.JposException
      Description copied from class: UniqueIOProcessor
      Reads a frame of given maximum byte length from communication source. If called from a derived class, LoggingData must be filled with the byte array to be returned. If LoggingData is longer than the maximum length, the remaining bytes will be discarded.
      Overrides:
      read in class UniqueIOProcessor
      Parameters:
      count - Maximum no. of bytes to be read
      Returns:
      byte[] containing received bytes. In case of timeout, less than count bytes will be returned, in extreme case, the array has length zero.
      Throws:
      jpos.JposException - if something goes wrong
    • flush

      public void flush() throws jpos.JposException
      Description copied from class: UniqueIOProcessor
      Empties input and output buffer
      Overrides:
      flush in class UniqueIOProcessor
      Throws:
      jpos.JposException - Iif something goes wrong
    • open

      public void open() throws jpos.JposException
      Opens the port. No error logging occurs in error case to avoid a flood of error messages in error cases.
      Throws:
      jpos.JposException - if an IO error occurs
    • open

      public void open(boolean noErrorLog) throws jpos.JposException
      Description copied from class: UniqueIOProcessor
      Opens processor for communication to specific source / target. Communication parameters must be set previously by specific setup method(s).
      Overrides:
      open in class UniqueIOProcessor
      Parameters:
      noErrorLog - if set, no logging occurs in error case to avoid a flood of error messages.
      Throws:
      jpos.JposException - if an IO error occurs
    • close

      public void close() throws jpos.JposException
      Description copied from class: UniqueIOProcessor
      Finished any communication.
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class UniqueIOProcessor
      Throws:
      jpos.JposException - If an IO error occurs
    • setParameters

      public void setParameters(int baudrate, int databits, int stopbits, int parity) throws jpos.JposException
      Sets communication parameters for serial communication (RS232)
      Parameters:
      baudrate - Baud rate, one of the predefined baudrate values. Default BAUDRATE_9600
      databits - Bits per byte, one of the predefined values. Default DATABITS_8.
      stopbits - Stop bits to be used when sending data, one of the prededined values. Default STOPBITS_2.
      parity - Parity to be used, one of the predefined values. Default PARITY_NONE.
      Throws:
      jpos.JposException - In case of any IO error
    • setTarget

      public String setTarget(String target) throws jpos.JposException
      Description copied from class: UniqueIOProcessor
      Sets communication target. Depending on the IO processor type, setting communication target can be mandatory before calling method open.
      Overrides:
      setTarget in class UniqueIOProcessor
      Parameters:
      target - communication target
      Returns:
      target
      Throws:
      jpos.JposException - if target is not a valid communication target.
    • exists

      public boolean exists()
      Checks whether the serial port (still) exists. This is especially useful in case of virtual COM ports generated by USB devices.
      Returns:
      true if the port exists (even if it is accessible), false if it does not exist.