AbstractSerialPortWrapper

Abstract serial port implementation.

This class abstracts away the common logic expected of any serial port implementations.

Inheritors

SerialPortWrapper
UsfaPortWrapper

Constructors

Link copied to clipboard
constructor()

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
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
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
abstract suspend fun readBytes(buffer: ByteArray): Int

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

Link copied to clipboard
abstract 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
abstract 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
abstract suspend fun writeBytes(buffer: ByteArray): Int

Writes the provided byte data to the serial port.