k804IO
A small Python library for driving the digital I/O (and LED) outputs of OnLogic Karbon/K804-series computers over their onboard MCU serial console.
It wraps the dio set <group> <channel> <true|false> shell command
exposed by the OnLogic firmware, so instead of opening a serial port and
writing raw commands by hand you get a small Python object model:
find the device, open the port, declare the channels you want to drive,
and turn them on/off.
How it works
OnLogic Karbon/K804 units expose an MCU shell over a USB-serial interface. That shell accepts commands such as:
dio set LED0 0 true # turn on LED channel 0 of group LED0
dio set DIO0 2 false # turn off digital output channel 2 of group DIO0
See OnLogic's firmware shell documentation for the full command reference: https://static.onlogic.com/resources/firmware/documentation/shell.html
k804IO automates:
- Finding the device — polling
/dev/serial/by-idfor an entry matchingusb-OnLogic_*if00. - Opening and quieting the serial console — disabling the
shell_uartandonlogic_vcom_canlogs and shell echo so the port only carries the commands you send. - Modeling digital channels as Python objects you can turn on, turn off, or pulse for a duration, with optional inverted logic.
Requirements
- Python >= 3.8
pyserial- Linux, with the device enumerated under
/dev/serial/by-id/(relies on udev'sby-idsymlinks) - Permission to access the serial device (typically membership in the
dialoutgroup, or running as root)
Installation
From the project root:
pip install .
or, for local development:
pip install -e .
Usage
Karbon804Terminal is a context manager: on __enter__ it searches for
the OnLogic serial device, opens the port, silences shell logging/echo,
and hands you a kK804DigitalIOController at
terminal.digitalIoController. On __exit__ it closes the port.
from time import sleep
from k804IO.k804 import Karbon804Terminal
with Karbon804Terminal() as terminal:
# Declare the channels you intend to drive before using them.
terminal.digitalIoController.createDigitalChannel("LED0", 0)
terminal.digitalIoController.createDigitalChannel(
"DIO0", 0, invertLogic=True
)
# Turn a channel on / off.
terminal.digitalIoController.setDigitalOutput("LED0", 0, True)
sleep(0.5)
terminal.digitalIoController.setDigitalOutput("LED0", 0, False)
# Pulse a channel on, then off, after a delay.
terminal.digitalIoController.setOnAndOff("LED0", 0, 0.05)
See src/k804IO/example.py for a longer
example that cycles through the four LED0 channels and declares an
inverted-logic DIO0 group.
Digital groups and channels
- A digital group (e.g.
"LED0","DIO0") is a named array of outputs on the MCU firmware side; a channel is that array's index (e.g.0-3). invertLogic=Trueflips the electrical sense of a channel — callingturnOn()sends the firmware afalsecommand and vice versa. Use it for outputs wired active-low.- Channels must be created with
createDigitalChannelbefore they can be addressed bysetDigitalOutput/setOnAndOff— the controller keeps them in a{group: {channel: OnlogicDigitalOutput}}dict and will raise aKeyErrorfor an undeclared group/channel.
Device discovery and timeouts
Karbon804Terminal.findOnlogicSerialPort() polls
/dev/serial/by-id once a second for up to 60 seconds looking for an
entry named usb-OnLogic_*if00. If no matching device shows up in
that window, or the port can't be opened, the terminal prints the
error and exits the process (sys.exit(1)) rather than raising.
Project layout
src/k804IO/
├── k804.py # Karbon804Terminal: device discovery + serial session context manager
├── k804_digital_controller.py # kK804DigitalIOController: channel registry / high-level API
├── onlogic_driver.py # OnlogicDigitalOutput: builds and sends the raw `dio set` commands
└── example.py # Runnable example cycling the LED0 and DIO0 groups
License
MIT — see LICENSE.
Metadata
Release files for k804IO 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| k804io-0.1.2.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| k804io-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.8 kB
Release files / k804io-0.1.2.tar.gz
| Download URL | k804io-0.1.2.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
59cc866ddbecbd1e4a74442e0133c510435ff92901b6d247e06173fe837e15ee
|
|
BLAKE2b-256 checksum How to use checksums |
e65770b5c21cb466bf0faa6898153b68a311911fdbb21b3a5b8f768fa25206af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.12
|
Release files / k804io-0.1.2-py3-none-any.whl
| Download URL | k804io-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
79fe16e04aace30aafec2976157aa052bb02c584a263dbad522a6a2e683425f4
|
|
BLAKE2b-256 checksum How to use checksums |
3866de45ade4c12c52645d5e05fda9b8e6122efd0da8bfe732364828858e0df2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.12
|