UsfaPortWrapper

class UsfaPortWrapper(c: Context, val driver: UsbSerialDriver) : AbstractSerialPortWrapper

"Usb Serial For Android" port wrapper class.

Parameters

c

Context

driver

USB driver/device to interact with

Constructors

Link copied to clipboard
constructor(c: Context, driver: UsbSerialDriver)

Properties

Link copied to clipboard
open override var defaultReadTimeout: Long

Timeout in milliseconds after which a read operation should abort.

Link copied to clipboard
open override var defaultWriteTimeout: Long

Timeout in milliseconds after which a write operation should abort.

Link copied to clipboard
val driver: UsbSerialDriver
Link copied to clipboard
Link copied to clipboard
lateinit var port: UsbSerialPort
Link copied to clipboard
open override var productId: Int

PID value of the serial port, or -1 if unavailable

Link copied to clipboard
open override var vendorId: Int

VID value of the serial port, or -1 if unavailable

Functions

Link copied to clipboard
open override fun bytesAvailable(): Int

Checks how many bytes are available to be read from the serial port.

Link copied to clipboard
open override fun close()

Closes a connection to the serial port.

Link copied to clipboard
open override fun isOpen(): Boolean

Checks if there is an open connection to the serial port.

Link copied to clipboard
open override fun open()

Opens a connection to the serial port.

Link copied to clipboard
open suspend override fun read(numBytes: Int): ByteArray
open suspend override fun read(numBytes: Int, timeout: Long): ByteArray

Reads the specified number of bytes from the port.

open override fun read(numBytes: Int, scope: CoroutineScope): Deferred<ByteArray>
open override fun read(numBytes: Int, timeout: Long, scope: CoroutineScope): Deferred<ByteArray>

Reads the specified number of bytes from the port in an asynchronous manner.

Link copied to clipboard
open suspend override fun readBytes(buffer: ByteArray): Int

Reads data from the serial port until the provided buffer is filled.

Link copied to clipboard
open override fun setBaudRate(rate: Int)

Sets the baud rate of the connection to the serial port.

Link copied to clipboard
open override fun setDefaultTimeouts(readTimeout: Long, writeTimeout: Long)

Sets the values of the port read and write timeouts.

Link copied to clipboard
open override fun setTimeout()

Sets the timeout behavior of the underlying serial port library.

Link copied to clipboard
open suspend override fun <T> use(callback: suspend (ISerialPortWrapper) -> T): T

Opens a connection to the serial port and closes it automatically after the callback has completed.

Link copied to clipboard
open suspend override fun write(bytes: ByteArray): Int
open suspend override fun write(bytes: ByteArray, timeout: Long): Int

Writes the provided bytes to the serial port.

open override fun write(bytes: ByteArray, scope: CoroutineScope): Deferred<Int>
open override fun write(bytes: ByteArray, timeout: Long, scope: CoroutineScope): Deferred<Int>

Writes the provided bytes to the serial port in an asynchronous manner.

Link copied to clipboard
open suspend override fun writeBytes(buffer: ByteArray): Int

Writes the provided byte data to the serial port.