Hi all; this is something I have been working on to power my PrintEYE replacement but it took on a life of it's own and I'd like to get it out of my system.. so here goes.
serialOM.py
is a self-contained python class that connects to the OM on a RRF device via USB or UART, and provides a local copy of the OM that can be periodically updated.
https://github.com/easytarget/serialOM
The readme
there does a proper TL;DR but the highlights are:
- Python3/microPython cross-compatible with both PySerial and the mpy UART support
- Keys to be fetched can be specified on a per-mode basis and the 'seqs' key is used to only do verbose fetches when needed.
- Controller reboots and mode changes are handled appropriately. soft failures (timeouts) are tolerated and detectable. Hard (comms port) errors trigger a custom exception.
- more.. see readme.
Basic use can be as simple as:
from serialOM import serialOM
from serial import Serial
rrf = Serial('/dev/ttyACM0',57600)
OM = serialOM(rrf, {'FFF':[],'CNC':[],'Laser':[]}, quiet=True)
print('state: ' + OM.model['state']['status']
+ ', up: ' + str(OM.model['state']['upTime']) + 's')
There is an associated printPy program that implements a robust logging / console info loop. It reconnects as USB ports change etc. and logs human-readable print/CNC/Laser status, value and progress data to the console and an optional file.
I consider the CPython side of this 'done' (unless bugs.. quite likely because I'm no Pythonista), it runs well from a Pi3 with a USB connection to my Duet2 WiFi.
There is a work in progress microPython version of this loop; printMPy
which can do the same console output, but also has RGB 'mood/activity' light control and button/status controls being implemented.
Both of the print*Py loops use a separate output class. currently the same 'TXT' demo works on both. This is a template for my in-progress I2C output class can be run in a thread to allow screen animations independent of the serial comms.