Hardware Interface Reference
kevinbotlib.hardware.interfaces.serial
kevinbotlib.hardware.interfaces.serial.SerialDeviceInfo
Information about a serial device link.
device
instance-attribute
Device
device_path
instance-attribute
Device path. Ex: /dev/ttyAMA0.
name
instance-attribute
Device name.
description
instance-attribute
Device description.
manufacturer
instance-attribute
Device manufacturer.
pid
instance-attribute
Device PID.
hwid
instance-attribute
Device HWID.
kevinbotlib.hardware.interfaces.serial.SerialIdentification
Identify serial ports
list_device_info()
staticmethod
List of available connected serial ports
Returns:
Type | Description |
---|---|
list[SerialDeviceInfo]
|
list[SerialDeviceInfo]: List of port info |
kevinbotlib.hardware.interfaces.serial.SerialParity
Bases: StrEnum
Serial parity types
NONE = serial.PARITY_NONE
class-attribute
instance-attribute
No parity checking.
EVEN = serial.PARITY_EVEN
class-attribute
instance-attribute
Even parity checking.
ODD = serial.PARITY_ODD
class-attribute
instance-attribute
Odd parity checking.
MARK = serial.PARITY_MARK
class-attribute
instance-attribute
Mark parity checking.
SPACE = serial.PARITY_SPACE
class-attribute
instance-attribute
Space parity checking.
kevinbotlib.hardware.interfaces.serial.RawSerialInterface
Bases: IOBase
Raw serial interface
port
property
writable
The serial port device name (e.g., COM3 or /dev/ttyAMA0)
baudrate
property
writable
The baud rate of the serial connection in bits per second
bytesize
property
writable
The number of bits per byte (typically 8)
parity
property
writable
The parity checking mode (e.g., NONE, EVEN, ODD)
stopbits
property
writable
The number of stop bits (typically 1 or 2)
timeout
property
writable
The read timeout value in seconds (None for no timeout)
write_timeout
property
writable
The write timeout value in seconds (None for no timeout)
inter_byte_timeout
property
writable
The timeout between bytes in seconds (None to disable)
xonxoff
property
writable
Whether software flow control (XON/XOFF) is enabled
rtscts
property
writable
Whether hardware RTS/CTS flow control is enabled
dsrdtr
property
writable
Whether hardware DSR/DTR flow control is enabled
exclusive
property
writable
Whether POSIX exclusive access mode is enabled (None for platform default)
is_open
property
Is the serial port open?
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Open state |
in_waiting
property
Get the number of bytes in the transmit buffer
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of bytes |
out_waiting
property
Get the number of bytes in the receive buffer
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of bytes |
break_condition
property
writable
Serial BREAK
condition, no transmit when active
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
BREAK condition |
rts
property
writable
Serial RTS
line, setting before connecting is possible
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
RTS |
dtr
property
writable
Serial DTR
line, setting before connecting is possible
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
DTR |
cts
property
Get the state if the CTS
line
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
CTS state |
ri
property
Get the state if the RI
line
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
RI state |
cd
property
Get the state if the CD
line
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
CD state |
device_name
property
Device name
Returns:
Type | Description |
---|---|
str | None
|
str | None: Device name, if available |
__init__(robot, port=None, baudrate=9600, bytesize=8, parity=SerialParity.NONE, stopbits=1, timeout=None, write_timeout=None, inter_byte_timeout=None, *, xonxoff=False, rtscts=False, dsrdtr=False, exclusive=None)
Initialize a new serial port connection
Parameters:
Name | Type | Description | Default |
---|---|---|---|
robot
|
BaseRobot | None
|
Robot instance for simulation support. Defaults to None. |
required |
port
|
str | None
|
The device to connect to e.g., COM3 of /dev/ttyAMA0. Defaults to None. |
None
|
baudrate
|
int
|
The baud rate to use. Defaults to 9600. |
9600
|
bytesize
|
int
|
Size of each byte to be sent. The default works for most use cases. Defaults to 8. |
8
|
parity
|
SerialParity
|
Parity type. Defaults to SerialParity.NONE. |
NONE
|
stopbits
|
float
|
Number of stop bits to use. Defaults to 1. |
1
|
timeout
|
float | None
|
Read timeout in seconds. Defaults to None. |
None
|
write_timeout
|
float | None
|
Write timeout in seconds. Defaults to None. |
None
|
inter_byte_timeout
|
float | None
|
Timeout between characters. Set to None to disable. Defaults to None. |
None
|
xonxoff
|
bool
|
Enable software flow control. Defaults to False. |
False
|
rtscts
|
bool
|
Enable hardware RTS/CTS flow control. Defaults to False. |
False
|
dsrdtr
|
bool
|
Enable hardware DSR/DTR flow control. Defaults to False. |
False
|
exclusive
|
bool | None
|
POSIX exclusive access mode. Defaults to None. |
None
|
open()
read(n=1)
Reads n
bytes from the serial port
Blocks until n
number of bytes are read, or read timeout
May return fewer than n
characters on timeout
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
Number of bytes to read. Defaults to 1. |
1
|
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
Character array |
read_until(term=b'\n', size=None)
Reads until `term` is found, `size` bytes is reached, or read timeout
Args:
term (bytes, optional): Termination bytes. Defaults to b'
'. size (int | None, optional): Maximum bytes to read. Defaults to None.
Returns:
bytes: Character array
write(data)
Write bytes to the serial port
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
bytes
|
Bytes to write |
required |
Returns:
Type | Description |
---|---|
int | None
|
int | None: Number of bytes written |
flush()
Wait until all serial data is written
reset_input_buffer()
Clear the input buffer, delete and ignore all data
reset_output_buffer()
Clear the output buffer, delete and ignore all data
reset_buffers()
Reset input and output buffers, delete and ignore all data
send_break(duration=0.25)
Send the break condition for duration
, then return to idle state
Parameters:
Name | Type | Description | Default |
---|---|---|---|
duration
|
float
|
Seconds for BREAK condition. Defaults to 0.25. |
0.25
|
kevinbotlib.hardware.interfaces.exceptions
kevinbotlib.hardware.interfaces.exceptions.SerialPortOpenFailure
Bases: BaseException
Exception that is raised on failure to open serial port
kevinbotlib.hardware.interfaces.exceptions.BaseSerialTimeoutException
Bases: BaseException
Exception that is raised on a serial operation timeout
kevinbotlib.hardware.interfaces.exceptions.SerialWriteTimeout
Bases: BaseSerialTimeoutException
Exception that is raised on a serial write timeout
kevinbotlib.hardware.interfaces.exceptions.SerialException
Bases: BaseException
Exception that is raised on a general serial communication failure