Class NativeSerialDevice

java.lang.Object
com.diozero.internal.provider.builtin.serial.NativeSerialDevice
All Implemented Interfaces:
Closeable, AutoCloseable

public class NativeSerialDevice
extends Object
implements Closeable
  • 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/ttyACM0
      baud - 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_PARITY
      readBlocking - Should blocking I/O be used for read operations?
      minReadChars - Minimum number of characters to read
      readTimeoutMillis - 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 interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getDeviceFile

      public String getDeviceFile()