ISerialPortWrapper

Interface from which any serial port implementations should inherit.

Inheritors

Properties

Link copied to clipboard
abstract var defaultReadTimeout: Long

Timeout in milliseconds after which a read operation should abort.

Link copied to clipboard

Timeout in milliseconds after which a write operation should abort.

Link copied to clipboard
abstract var productId: Int

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

Link copied to clipboard
abstract var vendorId: Int

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

Functions

Link copied to clipboard
abstract fun bytesAvailable(): Int

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

Link copied to clipboard
abstract fun close()

Closes a connection to the serial port.

Link copied to clipboard
abstract fun isOpen(): Boolean

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

Link copied to clipboard
abstract fun open()

Opens a connection to the serial port.

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

Reads the specified number of bytes from the port.

abstract fun read(numBytes: Int, scope: CoroutineScope): Deferred<ByteArray>
abstract 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
abstract fun setBaudRate(rate: Int)

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

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

Sets the values of the port read and write timeouts.

Link copied to clipboard
abstract suspend 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
abstract suspend fun write(bytes: ByteArray): Int
abstract suspend fun write(bytes: ByteArray, timeout: Long): Int

Writes the provided bytes to the serial port.

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

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