Sets the serial port read and write timeout parameters.
Note that time-based write timeouts are only available on Windows systems. There is no functionality to set a write timeout on other operating systems.
The built-in timeout mode constants should be used (
#TIMEOUT_NONBLOCKING,
#TIMEOUT_READ_SEMI_BLOCKING,
#TIMEOUT_READ_BLOCKING,
#TIMEOUT_WRITE_BLOCKING,
#TIMEOUT_SCANNER) to specify how timeouts are to be handled.
Valid modes are:
Non-blocking:
#TIMEOUT_NONBLOCKING
Write Blocking:
#TIMEOUT_WRITE_BLOCKING
Read Semi-blocking:
#TIMEOUT_READ_SEMI_BLOCKING
Read Full-blocking:
#TIMEOUT_READ_BLOCKING
Scanner:
#TIMEOUT_SCANNER
The
#TIMEOUT_NONBLOCKING mode specifies that corresponding
#readBytes(byte[],long) and
#writeBytes(byte[],long) calls will return
immediately with any available data.
The
#TIMEOUT_WRITE_BLOCKING mode specifies that a corresponding write call will block until all data bytes have been successfully written to the
output serial device.
The
#TIMEOUT_READ_SEMI_BLOCKING mode specifies that a corresponding read call will block until either newReadTimeout milliseconds of inactivity
have elapsed or at least 1 byte of data can be read.
The
#TIMEOUT_READ_BLOCKING mode specifies that a corresponding read call will block until either newReadTimeout milliseconds have elapsed since
the start of the call or the total number of requested bytes can be returned.
The
#TIMEOUT_SCANNER mode is intended for use with the Java
java.util.Scanner class for reading from the serial port. In this mode,
manually specified timeouts are ignored to ensure compatibility with the Java specification.
A value of 0 for either newReadTimeout or newWriteTimeout indicates that a
#readBytes(byte[],long) or
#writeBytes(byte[],long) call should block forever until it can return successfully (based upon the current timeout mode specified).
In order to specify that both a blocking read and write mode should be used,
#TIMEOUT_WRITE_BLOCKING can be OR'd together with any of the read modes to pass
to the first parameter.
It is important to note that non-Windows operating systems only allow decisecond (1/10th of a second) granularity for serial port timeouts. As such, your
millisecond timeout value will be rounded to the nearest decisecond under Linux or Mac OS. To ensure consistent performance across multiple platforms, it is
advisable that you set your timeout values to be multiples of 100, although this is not strictly enforced.