Registry / communication / uart-devices

uart-devices

JSON →
library0.1.1pypypi✓ verified 89d ago

uart-devices is a Python library for interacting with UART (Universal Asynchronous Receiver-Transmitter) devices on Linux systems. It provides an asynchronous, structured way to define and communicate with serial devices, abstracting away some of the lower-level details. The current version is 0.1.1, with initial development starting in April 2024 and a low release cadence.

pip install uart-devices
INSTALL
IMPORT
SIG · UART-DEVICES
U
uart-devices
communicationpythonv0.1.1
Install
1.5s avg
Import
205ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.218s · 17.8MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.192s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

UARTDevice
✓ from uart_devices import UARTDevice

This quickstart demonstrates how to initialize and interact with a UART device using `uart-devices`. It defines a simple device class, opens the port asynchronously, simulates a brief interaction, and then closes it. It includes common troubleshooting tips for permission and device path errors.

import asyncio import logging import os from uart_devices import UARTDevice logging.basicConfig(level=logging.INFO) # Set UART_DEVICE_PORT environment variable before running, e.g.: # export UART_DEVICE_PORT=/dev/ttyUSB0 # For demonstration, we use a common default like /dev/ttyS0 if not set. # Ensure this port exists and you have permissions. UART_PORT = os.environ.get("UART_DEVICE_PORT", "/dev/ttyS0") class MySimpleUARTDevice(UARTDevice): port = UART_PORT baudrate = 115200 # Common baud rate async def _async_on_open(self) -> None: logging.info(f"UART device {self.port} opened successfully.") async def _async_on_close(self) -> None: logging.info(f"UART device {self.port} closed.") async def _async_read_data(self, data: bytes) -> None: """Called when data is received.""" logging.info(f"Received data: {data.hex()}") async def main(): device = MySimpleUARTDevice() print(f"Attempting to interact with UART device on port: {device.port}...") try: await device.open() # In a real application, you would perform async read/write operations here. # For this example, we just keep it open briefly and then close. await asyncio.sleep(0.5) await device.close() print(f"Successfully interacted with and closed device on {device.port}.") except Exception as e: logging.error(f"Failed to interact with UART device on {device.port}: {type(e).__name__}: {e}") print("\n--- Troubleshooting Tips ---") print("1. Check permissions: Ensure your user is in the 'dialout' or 'uucp' group. (e.g., `sudo usermod -a -G dialout $USER` then log out and back in).") print("2. Verify device path: Ensure `UART_DEVICE_PORT` (e.g., /dev/ttyUSB0, /dev/ttyS0) is correct and the device is connected.") print("3. Check baud rate: Ensure 115200 matches your device's baud rate.") if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
gotchaAccessing serial ports on Linux often requires specific user permissions. If your user is not part of the 'dialout' or 'uucp' group, you will encounter `PermissionError`.
fix
Add your user to the 'dialout' group (or 'uucp' on some systems) using `sudo usermod -a -G dialout $USER`. Then, log out and log back in for the changes to take effect.
affects: All
gotchaThe specified UART device path (e.g., `/dev/ttyUSB0`) must exist and refer to an actual connected serial device. Incorrect paths will lead to `FileNotFoundError` or similar issues.
fix
Verify the correct device path by checking `/dev/` directory after plugging in your device (e.g., `ls /dev/tty*`). Update the `port` attribute in your `UARTDevice` subclass accordingly.
affects: All
gotchaEnsure the `baudrate` configured in your `UARTDevice` subclass matches the baud rate of your physical serial device. A mismatch will result in corrupted or unreadable data.
fix
Consult your device's documentation for the correct baud rate and set the `baudrate` attribute (e.g., `baudrate = 9600`) to match.
affects: All
Errors
Common errors & fixes
[Errno 13] Permission denied: '/dev/ttyUSB0'
The current user does not have read/write permissions for the specified serial port.
fix
Add your user to the 'dialout' group (or 'uucp' on some systems) using `sudo usermod -a -G dialout $USER`. Then, log out and log back in for the changes to take effect.
FileNotFoundError: [Errno 2] No such file or directory: '/dev/ttyS0'
The specified serial port path does not exist, or the device is not connected/enumerated.
fix
Check if the serial device is properly connected and recognized by the system. Verify the correct device path (e.g., `/dev/ttyUSB0`, `/dev/ttyACM0`) using `ls /dev/tty*` and update your code.
serial.serialutil.SerialException: Cannot configure port, something went wrong. Original message: 'I/O operation in progress'
The serial port is already in use by another application or process.
fix
Ensure no other program (e.g., a terminal emulator, another script) is currently accessing the serial port. You might need to restart the device or your system in some cases.
Upgrade
Version history
0.1.1latest on PyPI · released Feb 22, 2025
Audit
Dependencies
pyserialrequiredProvides the low-level serial port communication interface.
Agent activity
41 hits · last 30 days
node
38
OpenAI (training)
1
Resources
uart-devices — pip install uart-devices · libregistry