Package de.gmxhome.conrad.jpos.jpos_base
Interface SerialIOAdapter
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
JnaLinuxSerial
,JnaSerial
,JSCSerial
,JSSCSerial
Wrapper interface that provides the interface used by SerialIOProcessor, to be implemented for different
implementations for serial communication, such as jSSC, jSerialComm or others.
Each SerialIOAdapter is a very simple class that holds the absolute minimum of functionality to support serial IO. It contains at least a default constructor.
Each SerialIOAdapter is a very simple class that holds the absolute minimum of functionality to support serial IO. It contains at least a default constructor.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
Special exception to be used when the port is not available. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic 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.static Integer
Current baud rate.static int
Constant for 7 bit data size.static int
Constant for 8 bit data size.static int
Constant for even parity.static int
Constant for mark parity.static int
Constant for no parity.static int
Constant for odd parity.static int
Constant for space parity.static int
Constant for serial communication using 1 stop bit.static int
Constant for serial communication using 2 stop bits.static int
Constant for requesting valid baud rate constants.static int
Constant for requesting valid baud rate constants.static int
Constant for requesting valid baud rate constants.static int
Constant for requesting valid baud rate constants. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the number of received bytes that can be read without blocking.void
close()
Close the communication port.boolean
Checks whether a port still exists.void
flush()
Flushed input and output buffers.int[][]
getCommunicationConstants(int constantType)
Retrieves an array of integer pairs specifying all valid parameters for the given constant type.void
Opens a port for serial IO.byte[]
read(int count, int timeout)
Reads data from a communication port.void
setParameters(int baudrate, int databits, int stopbits, int parity)
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.void
write(byte[] buffer)
Write the given byte buffer to the com port.
-
Field Details
-
B_1200
static final int B_1200Baudrate constant for 1200 baud.- See Also:
- Constant Field Values
-
B_2400
static final int B_2400Baudrate constant for 2400 baud.- See Also:
- Constant Field Values
-
B_4800
static final int B_4800Baudrate constant for 4800 baud.- See Also:
- Constant Field Values
-
B_9600
static final int B_9600Baudrate constant for 9600 baud.- See Also:
- Constant Field Values
-
B_19200
static final int B_19200Baudrate constant for 19200 baud.- See Also:
- Constant Field Values
-
B_38400
static final int B_38400Baudrate constant for 38400 baud.- See Also:
- Constant Field Values
-
B_57600
static final int B_57600Baudrate constant for 57600 baud.- See Also:
- Constant Field Values
-
B_115200
static final int B_115200Baudrate constant for 115200 baud.- See Also:
- Constant Field Values
-
B_128000
static final int B_128000Baudrate constant for 128000 baud.- See Also:
- Constant Field Values
-
B_256000
static final int B_256000Baudrate constant for 256000 baud.- See Also:
- Constant Field Values
-
D_7
static final int D_7Constant for 7 bit data size.- See Also:
- Constant Field Values
-
D_8
static final int D_8Constant for 8 bit data size.- See Also:
- Constant Field Values
-
S_1
static final int S_1Constant for serial communication using 1 stop bit.- See Also:
- Constant Field Values
-
S_2
static final int S_2Constant for serial communication using 2 stop bits.- See Also:
- Constant Field Values
-
P_NO
static final int P_NOConstant for no parity.- See Also:
- Constant Field Values
-
P_ODD
static final int P_ODDConstant for odd parity.- See Also:
- Constant Field Values
-
P_EVEN
static final int P_EVENConstant for even parity.- See Also:
- Constant Field Values
-
P_MARK
static final int P_MARKConstant for mark parity.- See Also:
- Constant Field Values
-
P_SPACE
static final int P_SPACEConstant for space parity.- See Also:
- Constant Field Values
-
T_BAUD
static final int T_BAUDConstant for requesting valid baud rate constants.- See Also:
- Constant Field Values
-
T_DATA
static final int T_DATAConstant for requesting valid baud rate constants.- See Also:
- Constant Field Values
-
T_STOP
static final int T_STOPConstant for requesting valid baud rate constants.- See Also:
- Constant Field Values
-
T_PARITY
static final int T_PARITYConstant for requesting valid baud rate constants.- See Also:
- Constant Field Values
-
Baudrate
Current baud rate. Set to null as long as it has not been set to a valid baud rate.
-
-
Method Details
-
open
Opens a port for serial IO.- Parameters:
port
- Port. e.g. COM2- Throws:
IOException
- If the port does not exist or in case of IO errors.
-
close
Close the communication port.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- In case of IO error.
-
setParameters
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.- 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
Returns the number of received bytes that can be read without blocking.- Returns:
- Number of bytes just in device input buffer.
- Throws:
IOException
- In case of an IO error
-
read
Reads data from a communication port. If no data are available, read blocks until data are available or the specified timeout has been reached.- 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
Write the given byte buffer to the com port.- Parameters:
buffer
- Buffer to be written- Throws:
IOException
- If the port has not been opened or in case of an IO error.
-
flush
Flushed input and output buffers.- Throws:
IOException
- In case of an IO error.
-
exits
Checks whether a port still exists. In case of serial communication via Bluetooth or USB, ports can go lost.- Parameters:
port
- Port to be checked.- Returns:
- true if the port still exists, false otherwise-
-
getCommunicationConstants
int[][] getCommunicationConstants(int constantType)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.- 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.
-