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.6.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

easycom-0.0.6-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: easycom-0.0.6.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.6.tar.gz
Algorithm Hash digest
SHA256 d18fcc3eac4dc74a7338308fe3c3f16b5dd4a045256b980bdb8892617f193370
MD5 a67d771664ee84ac4b977faa30704a18
BLAKE2b-256 6a266092d37fe14c73fc92d7fa33290430c0140f2e58952c9343cf94b0ad9388

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: easycom-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 6.5 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d6e5e1df6bd78c369a5ace978e8d8c88b2f09ae3abd029b1ad08228bf8a108d2
MD5 fa72cc7de33e722b15ed2ab0019e0304
BLAKE2b-256 d6c795c16367a9a5a2a80275e301c74f0818445b82c724931cb3703758c4caa8

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