Class SerialDevice

java.lang.Object
com.tccc.kos.core.service.udev.serial.SerialDevice

public class SerialDevice extends Object
Wraps a UdevDevice and provides easy access to serial specific data.
Since:
1.0
Version:
2023-09-18
  • Constructor Details

    • SerialDevice

      public SerialDevice()
  • Method Details

    • getId

      public String getId()
      Return the id of the device. This uniquely defines the device and can be used as a device key.
    • getDevname

      public String getDevname()
      Return the device name of the device. This is the name used to open the serial port.
    • getRunTimeMs

      public long getRunTimeMs()
      Return how long the device has been running in ms.
    • getVendorId

      public int getVendorId()
      Return the vendor id of the device.
    • getProductId

      public int getProductId()
      Return the product id of the device.
    • getDevicePath

      public String getDevicePath()
      Return the device path of the serial device. This is the ID_PATH of the device without the final device index. This is useful for identifying multiple serial ports that are part of the same usb device.
    • getDeviceIndex

      public int getDeviceIndex()
      Return the device index of the serial device. This is the final digit of the ID_PATH and is useful for identifying which serial device this is when part of a multi-port usb device.
    • claimDevice

      public void claimDevice(UdevDeviceOwner owner)
      Claim the device so no other serial matchers will attempt to use the device. The owner will be notified when the device is removed.
      Parameters:
      owner - the owner of the device
      Throws:
      IllegalStateException - if the device is already owned
    • claimDevice

      public void claimDevice()
      Claim the device so no other serial matchers will attempt to use the device. The owner will be SerialService which will automatically cleanup the device when removed.
      Throws:
      IllegalStateException - if the device is already owned
    • open

      public void open(int baud) throws IOException
      Open a serial device for probing.
      Parameters:
      baud - the baud rate
      Throws:
      IOException
    • close

      public void close()
      Close the serial device.
    • drain

      public void drain() throws IOException
      Drain all input from the serial device
      Throws:
      IOException
    • write

      public int write(String str) throws IOException
      Write to the serial device
      Parameters:
      str - the string to write
      Returns:
      the number of bytes written
      Throws:
      IOException
    • write

      public int write(byte[] buf) throws IOException
      Write bytes to the serial device
      Parameters:
      buf - the bytes to write
      Returns:
      the number of bytes written
      Throws:
      IOException
    • write

      public int write(byte[] buf, int off, int len) throws IOException
      Write to the serial device
      Parameters:
      buf - the buffer to write
      off - offset into the buffer
      len - the number of bytes to write
      Returns:
      the number of bytes written
      Throws:
      IOException
    • read

      public int read(byte[] buf, int len) throws IOException
      Read from the serial device
      Parameters:
      buf - the buffer to read to
      len - the number of bytes to read
      Returns:
      the number of bytes read
      Throws:
      IOException
    • readStr

      public String readStr(int len) throws IOException
      Read a string from the serial device. This will read up to the specified number of bytes and then convert the bytes to a string.
      Parameters:
      len - the max number of bytes to read
      Returns:
      the string read from the device
      Throws:
      IOException
    • getSerialService

      public SerialService getSerialService()
    • getUdevDevice

      public UdevDevice getUdevDevice()