Class SerialDevice
java.lang.Object
com.tccc.kos.core.service.udev.serial.SerialDevice
Wraps a
UdevDevice
and provides easy access to serial specific data.- Since:
- 1.0
- Version:
- 2023-09-18
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Claim the device so no other serial matchers will attempt to use the device.void
claimDevice
(UdevDeviceOwner owner) Claim the device so no other serial matchers will attempt to use the device.void
close()
Close the serial device.void
drain()
Drain all input from the serial deviceint
Return the device index of the serial device.Return the device path of the serial device.Return the device name of the device.getId()
Return the id of the device.int
Return the product id of the device.long
Return how long the device has been running in ms.int
Return the vendor id of the device.void
open
(int baud) Open a serial device for probing.int
read
(byte[] buf, int len) Read from the serial devicereadStr
(int len) Read a string from the serial device.int
write
(byte[] buf) Write bytes to the serial deviceint
write
(byte[] buf, int off, int len) Write to the serial deviceint
Write to the serial device
-
Constructor Details
-
SerialDevice
public SerialDevice()
-
-
Method Details
-
getId
Return the id of the device. This uniquely defines the device and can be used as a device key. -
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
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
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 beSerialService
which will automatically cleanup the device when removed.- Throws:
IllegalStateException
- if the device is already owned
-
open
Open a serial device for probing.- Parameters:
baud
- the baud rate- Throws:
IOException
-
close
public void close()Close the serial device. -
drain
Drain all input from the serial device- Throws:
IOException
-
write
Write to the serial device- Parameters:
str
- the string to write- Returns:
- the number of bytes written
- Throws:
IOException
-
write
Write bytes to the serial device- Parameters:
buf
- the bytes to write- Returns:
- the number of bytes written
- Throws:
IOException
-
write
Write to the serial device- Parameters:
buf
- the buffer to writeoff
- offset into the bufferlen
- the number of bytes to write- Returns:
- the number of bytes written
- Throws:
IOException
-
read
Read from the serial device- Parameters:
buf
- the buffer to read tolen
- the number of bytes to read- Returns:
- the number of bytes read
- Throws:
IOException
-
readStr
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
-
getUdevDevice
-