Class DefaultNativeSerialDevice
java.lang.Object
com.diozero.internal.spi.AbstractDevice
com.diozero.internal.provider.builtin.DefaultNativeSerialDevice
- All Implemented Interfaces:
DeviceInterface
,SerialDeviceInterface
,Closeable
,AutoCloseable
public class DefaultNativeSerialDevice extends AbstractDevice implements SerialDeviceInterface
-
Constructor Summary
Constructors Constructor Description DefaultNativeSerialDevice(DeviceFactoryInterface deviceFactory, String key, String deviceFile, int baud, SerialConstants.DataBits dataBits, SerialConstants.StopBits stopBits, SerialConstants.Parity parity, boolean readBlocking, int minReadChars, int readTimeoutMillis)
-
Method Summary
Modifier and Type Method Description int
bytesAvailable()
Get the number of bytes that are available to be readprotected void
closeDevice()
int
read()
Read a single byte returning error responsesint
read(byte[] buffer)
Attempt to read buffer.length bytes into the specified buffer, throw an exception if unable to read any databyte
readByte()
Read a single byte, throw an exception if unable to read any datavoid
write(byte... data)
Write the byte buffer to the devicevoid
writeByte(byte bVal)
Write a single byte, throw an exception if unable to write the dataMethods inherited from class com.diozero.internal.spi.AbstractDevice
close, getDeviceFactory, getKey, isOpen
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.diozero.api.DeviceInterface
close, getKey, isOpen
-
Constructor Details
-
DefaultNativeSerialDevice
public DefaultNativeSerialDevice(DeviceFactoryInterface deviceFactory, String key, String deviceFile, int baud, SerialConstants.DataBits dataBits, SerialConstants.StopBits stopBits, SerialConstants.Parity parity, boolean readBlocking, int minReadChars, int readTimeoutMillis)
-
-
Method Details
-
closeDevice
- Specified by:
closeDevice
in classAbstractDevice
- Throws:
RuntimeIOException
-
read
public int read()Description copied from interface:SerialDeviceInterface
Read a single byte returning error responses- Specified by:
read
in interfaceSerialDeviceInterface
- Returns:
- Signed integer representation of the data read, including error responses (values < 0)
-
readByte
public byte readByte()Description copied from interface:SerialDeviceInterface
Read a single byte, throw an exception if unable to read any data- Specified by:
readByte
in interfaceSerialDeviceInterface
- Returns:
- The data read
-
writeByte
public void writeByte(byte bVal)Description copied from interface:SerialDeviceInterface
Write a single byte, throw an exception if unable to write the data- Specified by:
writeByte
in interfaceSerialDeviceInterface
- Parameters:
bVal
- The data to write
-
read
public int read(byte[] buffer)Description copied from interface:SerialDeviceInterface
Attempt to read buffer.length bytes into the specified buffer, throw an exception if unable to read any data- Specified by:
read
in interfaceSerialDeviceInterface
- Parameters:
buffer
- The buffer to read into, the length of this buffer specifies the number of bytes to read- Returns:
- The number of bytes read
-
write
public void write(byte... data)Description copied from interface:SerialDeviceInterface
Write the byte buffer to the device- Specified by:
write
in interfaceSerialDeviceInterface
- Parameters:
data
- The data to write
-
bytesAvailable
public int bytesAvailable()Description copied from interface:SerialDeviceInterface
Get the number of bytes that are available to be read- Specified by:
bytesAvailable
in interfaceSerialDeviceInterface
- Returns:
- The number of bytes that are available to read
-