Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

Module for handling pySerial Serial objects connecting and disconnecting

Project Description

Installation

$ pip install watchedserial

Description

WatchedReaderThread is a subclass of pySerial’s serial.threaded.ReaderThread. Similar to ReaderThread, WatchedReaderThread implements a serial port read loop in it’s own thread but instead of killing the thread on a serial disconnection, it calls a callback and waits for the port to become available again before attempting a reconnect. On reconnect it calls a reconnect callback. This should make writing apps that need to deal with unreliable serial connections more seamless and make it easier to write apps that should allow the user to disconnect and reconnect a serial device safely.

Usage

Subclass watchedserial.WatchedReaderThread to implement the handle_reconnect() and handle_disconnect() callbacks. Both of these functions should be non-blocking (similar to an ISR).

import time

import serial
from watchedserial import WatchedReaderThread


PORT = "COM3"

class MyPacket(serial.threaded.FramedPacket):
    def handle_packet(self, packet):
        print(packet)


class MyWatchedReaderThread(WatchedReaderThread):
    def handle_reconnect(self):
        print("Reconnected")

    def handle_disconnect(self, error):
        print("Disconnected")


ser = serial.Serial(PORT, baudrate=115200)
with MyWatchedReaderThread(ser, MyPacket) as protocol:
    while True:
        time.sleep(1)
Release History

Release History

This version
History Node

1.0.1

History Node

1.0.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
watchedserial-1.0.1.tar.gz (3.2 kB) Copy SHA256 Checksum SHA256 Source Apr 28, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting