Package de.gmxhome.conrad.jpos.jpos_base
Class SerialIOProcessor
java.lang.Object
de.gmxhome.conrad.jpos.jpos_base.UniqueIOProcessor
de.gmxhome.conrad.jpos.jpos_base.SerialIOProcessor
- All Implemented Interfaces:
AutoCloseable
Class to process serial communication. Current implementation uses jSSC implementation
for serial communication. Includes functionality for automatic data logging.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
Baudrate to be used.static int
Baudrate constant for 115200 baud.static int
Baudrate constant for 1200 baud.static int
Baudrate constant for 128000 baud.static int
Baudrate constant for 19200 baud.static int
Baudrate constant for 2400 baud.static int
Baudrate constant for 256000 baud.static int
Baudrate constant for 38400 baud.static int
Baudrate constant for 4800 baud.static int
Baudrate constant for 57600 baud.static int
Baudrate constant for 9600 baud.protected int
Data bits to be used.static int
Constant for 7 bit data size.static int
Constant for 8 bit data size.protected int
Parity to be used.static int
Parity constant for even parity.static int
Parity constant for mark parity.static int
Parity constant for no parity.static int
Parity constant for odd parity.static int
Parity constant for space parity.protected int
Stop bits to be used.static int
Constant for serial communication using 1 stop bit.static int
Constant for serial communication using 2 stop bits.Fields inherited from class de.gmxhome.conrad.jpos.jpos_base.UniqueIOProcessor
Dev, InitialPort, IOProcessorError, LoggingData, LoggingPrefix, LoggingType, LoggingTypeEscapeString, LoggingTypeHexString, LoggingTypeNoLogging, Port, Source, Target, Timeout
-
Constructor Summary
ConstructorsConstructorDescriptionSerialIOProcessor(JposDevice usingDevice, String portName)
Creates simple serial connector for given port -
Method Summary
Modifier and TypeMethodDescriptionint
Retrieves no.void
close()
Finished any communication.boolean
exists()
Checks whether the serial port (still) exists.void
flush()
Empties input and output buffervoid
open()
Opens the port.void
open(boolean noErrorLog)
Opens processor for communication to specific source / target.byte[]
read(int count)
Reads a frame of given maximum byte length from communication source.void
setParameters(int baudrate, int databits, int stopbits, int parity)
Sets communication parameters for serial communication (RS232)Sets communication target.int
write(byte[] buffer)
Write a frame to the communication target.Methods inherited from class de.gmxhome.conrad.jpos.jpos_base.UniqueIOProcessor
getSource, getTarget, location, logerror, logerror, logerror, setLoggingType, setTimeout, toLogString
-
Field Details
-
BAUDRATE_1200
public static final int BAUDRATE_1200Baudrate constant for 1200 baud.- See Also:
- Constant Field Values
-
BAUDRATE_2400
public static final int BAUDRATE_2400Baudrate constant for 2400 baud.- See Also:
- Constant Field Values
-
BAUDRATE_4800
public static final int BAUDRATE_4800Baudrate constant for 4800 baud.- See Also:
- Constant Field Values
-
BAUDRATE_9600
public static final int BAUDRATE_9600Baudrate constant for 9600 baud.- See Also:
- Constant Field Values
-
BAUDRATE_19200
public static final int BAUDRATE_19200Baudrate constant for 19200 baud.- See Also:
- Constant Field Values
-
BAUDRATE_38400
public static final int BAUDRATE_38400Baudrate constant for 38400 baud.- See Also:
- Constant Field Values
-
BAUDRATE_57600
public static final int BAUDRATE_57600Baudrate constant for 57600 baud.- See Also:
- Constant Field Values
-
BAUDRATE_115200
public static final int BAUDRATE_115200Baudrate constant for 115200 baud.- See Also:
- Constant Field Values
-
BAUDRATE_128000
public static final int BAUDRATE_128000Baudrate constant for 128000 baud.- See Also:
- Constant Field Values
-
BAUDRATE_256000
public static final int BAUDRATE_256000Baudrate constant for 256000 baud.- See Also:
- Constant Field Values
-
Baudrate
protected int BaudrateBaudrate to be used. Default: BAUDRATE_9600. -
PARITY_NONE
public static final int PARITY_NONEParity constant for no parity.- See Also:
- Constant Field Values
-
PARITY_ODD
public static final int PARITY_ODDParity constant for odd parity.- See Also:
- Constant Field Values
-
PARITY_EVEN
public static final int PARITY_EVENParity constant for even parity.- See Also:
- Constant Field Values
-
PARITY_MARK
public static final int PARITY_MARKParity constant for mark parity.- See Also:
- Constant Field Values
-
PARITY_SPACE
public static final int PARITY_SPACEParity constant for space parity.- See Also:
- Constant Field Values
-
Parity
protected int ParityParity to be used. Default: PARITY_NONE. -
DATABITS_7
public static final int DATABITS_7Constant for 7 bit data size.- See Also:
- Constant Field Values
-
DATABITS_8
public static final int DATABITS_8Constant for 8 bit data size.- See Also:
- Constant Field Values
-
Databits
protected int DatabitsData bits to be used. Default: DATABITS_8. -
STOPBITS_1
public static final int STOPBITS_1Constant for serial communication using 1 stop bit.- See Also:
- Constant Field Values
-
STOPBITS_2
public static final int STOPBITS_2Constant for serial communication using 2 stop bits.- See Also:
- Constant Field Values
-
Stopbits
protected int StopbitsStop bits to be used. Default: STOPBITS_2.
-
-
Constructor Details
-
SerialIOProcessor
Creates simple serial connector for given port- Parameters:
usingDevice
- Device that uses the proceessor. Processor uses logging of device to produce logging entriesportName
- 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.JposExceptionDescription 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 classUniqueIOProcessor
- 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.JposExceptionDescription 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 classUniqueIOProcessor
- Returns:
- Unit count
- Throws:
jpos.JposException
- if something goes wrong
-
read
public byte[] read(int count) throws jpos.JposExceptionDescription 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 classUniqueIOProcessor
- 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.JposExceptionDescription copied from class:UniqueIOProcessor
Empties input and output buffer- Overrides:
flush
in classUniqueIOProcessor
- Throws:
jpos.JposException
- Iif something goes wrong
-
open
public void open() throws jpos.JposExceptionOpens 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.JposExceptionDescription 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 classUniqueIOProcessor
- 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.JposExceptionDescription copied from class:UniqueIOProcessor
Finished any communication.- Specified by:
close
in interfaceAutoCloseable
- Overrides:
close
in classUniqueIOProcessor
- Throws:
jpos.JposException
- If an IO error occurs
-
setParameters
public void setParameters(int baudrate, int databits, int stopbits, int parity) throws jpos.JposExceptionSets communication parameters for serial communication (RS232)- Parameters:
baudrate
- Baud rate, one of the predefined baudrate values. Default BAUDRATE_9600databits
- 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
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 classUniqueIOProcessor
- 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.
-