Interface SerialDeviceInterface

All Superinterfaces:
AutoCloseable, Closeable, DeviceInterface
All Known Implementing Classes:
DefaultNativeSerialDevice, SerialDevice

public interface SerialDeviceInterface
extends DeviceInterface
  • Method Summary

    Modifier and Type Method Description
    int bytesAvailable()
    Get the number of bytes that are available to be read
    int read()
    Read a single byte returning error responses
    int read​(byte[] buffer)
    Attempt to read buffer.length bytes into the specified buffer, returning the number of bytes actually read; throw a RuntimeIOException if an I/O error occurs
    byte readByte()
    Read a single byte, throw an exception if unable to read any data
    void write​(byte... data)
    Write the byte buffer to the device
    void writeByte​(byte bVal)
    Write a single byte, throw an exception if unable to write the data

    Methods inherited from interface com.diozero.api.DeviceInterface

    close, getKey, isOpen
  • Method Details

    • read

      int read() throws RuntimeIOException
      Read a single byte returning error responses
      Returns:
      Signed integer representation of the data read, including error responses (values < 0)
      Throws:
      RuntimeIOException - if an I/O error occurs
    • readByte

      byte readByte() throws RuntimeIOException
      Read a single byte, throw an exception if unable to read any data
      Returns:
      The data read
      Throws:
      RuntimeIOException - if an I/O error occurs
    • writeByte

      void writeByte​(byte bVal) throws RuntimeIOException
      Write a single byte, throw an exception if unable to write the data
      Parameters:
      bVal - The data to write
      Throws:
      RuntimeIOException - if an I/O error occurs
    • read

      int read​(byte[] buffer) throws RuntimeIOException
      Attempt to read buffer.length bytes into the specified buffer, returning the number of bytes actually read; throw a RuntimeIOException if an I/O error occurs
      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
      Throws:
      RuntimeIOException - if an I/O error occurs
    • write

      void write​(byte... data) throws RuntimeIOException
      Write the byte buffer to the device
      Parameters:
      data - The data to write
      Throws:
      RuntimeIOException - if an I/O error occurs
    • bytesAvailable

      int bytesAvailable() throws RuntimeIOException
      Get the number of bytes that are available to be read
      Returns:
      The number of bytes that are available to read
      Throws:
      RuntimeIOException - if an I/O error occurs