Class NativeSerialDevice
java.lang.Object
com.diozero.internal.provider.builtin.serial.NativeSerialDevice
- All Implemented Interfaces:
AutoCloseable
public class NativeSerialDevice extends Object implements AutoCloseable
-
Constructor Summary
Constructors Constructor Description NativeSerialDevice(String deviceFile, int baud, SerialConstants.DataBits dataBits, SerialConstants.StopBits stopBits, SerialConstants.Parity parity, boolean readBlocking, int minReadChars, int readTimeoutMillis)
Open a new serial device -
Method Summary
Modifier and Type Method Description int
bytesAvailable()
void
close()
String
getDeviceFile()
int
read()
int
read(byte[] buffer)
byte
readByte()
void
write(byte[] data)
void
writeByte(byte value)
-
Constructor Details
-
NativeSerialDevice
public NativeSerialDevice(String deviceFile, int baud, SerialConstants.DataBits dataBits, SerialConstants.StopBits stopBits, SerialConstants.Parity parity, boolean readBlocking, int minReadChars, int readTimeoutMillis)Open a new serial device- Parameters:
deviceFile
- Serial device filename including path, e.g. /dev/ttyACM0baud
- Default is 9600.dataBits
- The number of data bits to use per word; default is 8, values from 5 to 8 are acceptable.stopBits
- The number of stop bits; default is 1, but 2 bits can also be used or even 1.5 on Windows machines.parity
- Specifies how error detection is carried out; valid values are NO_PARITY, EVEN_PARITY, ODD_PARITY, MARK_PARITY, and SPACE_PARITYreadBlocking
- Should blocking I/O be used for read operations?minReadChars
- Minimum number of characters to readreadTimeoutMillis
- Duration in milliseconds for read timeouts; must be in units of 100.
-
-
Method Details
-
read
public int read() -
readByte
public byte readByte() -
writeByte
public void writeByte(byte value) -
read
public int read(byte[] buffer) -
write
public void write(byte[] data) -
bytesAvailable
public int bytesAvailable() -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
getDeviceFile
-