Skip to main content

A simple library for asynchronous serial communication

Project description

EasyCom

EasyCom is a Python library for asynchronous serial communication with USB UART devices. It supports hardware like Arduino, ESP32, Raspberry Pi Pico, Teensy, and others. EasyCom offers non-blocking communication with an easy-to-use API and allows you to dynamically register new devices at runtime.


Features

  • Asynchronous Communication using threads for non-blocking operations.
  • Pre-configured and Dynamically Registered Devices support.
  • Automatic Port Detection via PID/VID pairs.
  • Thread-safe Writes using queue-based management.
  • Customizable Data Handlers for processing incoming data.

Installation

Install EasyCom and its dependencies via pip:

pip install easycom pyserial

Usage

Example: Arduino Communication

This example demonstrates sending and receiving data using an Arduino device with a callback function:

from easycom.devices import Arduino

# Callback function to handle received data
def handle_data(data):
    print(f"Received: {data}")

# Initialize the Arduino with the callback function
arduino = Arduino(port="/dev/ttyUSB0", data_handler=handle_data)

# Send data to the Arduino
arduino.write(b"Hello, Arduino!")

# Keep the program running to receive data
input("Press Enter to disconnect...")

# Disconnect the Arduino
arduino.disconnect()

Registering a New Device at Runtime

You can dynamically register a new device using the register_device function:

from easycom.devices import register_device

# Register a new device class named "MyDevice"
MyDevice = register_device(
    name="MyDevice",
    pidvids=["1234:5678"],
    default_baudrate=115200,
    default_timeout=3
)

# Use the registered device
device = MyDevice(port="/dev/ttyUSB0")
device.write(b"Hello, MyDevice!")
device.disconnect()

Supported Devices

Here are some devices supported by EasyCom:

Device PID/VIDs Default Baudrate Default Timeout
Arduino 2341:0043, 2341:0010, 0403:6001 9600 2
Pico 2E8A:0005 115200 2
Teensy 16C0:0483, 16C0:0487 9600 2
ESP32 10C4:EA60, 1A86:7523 115200 3
FTDI 0403:6001, 0403:6015 9600 2
CH340 1A86:7523 9600 3

Logging

Enable detailed logging for debugging:

import logging
logging.basicConfig(level=logging.DEBUG)

License

This project is licensed under the MIT License.


Contributing

We welcome contributions! Please open an issue or submit a pull request if you encounter any problems or have suggestions.


Links


Authors


Conclusion

With EasyCom, working with USB UART devices is simple and efficient. Whether you're using pre-configured devices or dynamically registering new ones, EasyCom ensures reliable, non-blocking serial communication for your projects.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easycom-0.0.5.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

easycom-0.0.5-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file easycom-0.0.5.tar.gz.

File metadata

  • Download URL: easycom-0.0.5.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for easycom-0.0.5.tar.gz
Algorithm Hash digest
SHA256 53c26cea2d8b980824c1dd30dc17f70c665019e1194b2a39c42eae6c80154b14
MD5 68c6ad2b60bb2108331ae2dceed699bf
BLAKE2b-256 77ffe60309aa67c95f453b65b2e18100c9ccd9433c8312e8836e663469842274

See more details on using hashes here.

Provenance

File details

Details for the file easycom-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: easycom-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for easycom-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d33115e896ed2c8aedd8535784607769a7564f67b77654b48b346228557f43f4
MD5 02c61d76bd3f50dd3e7cbdac0b629082
BLAKE2b-256 f887b18be48d7e1c640397dd62b0f2e701ce9212387a3081309dc140930d9a54

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page