Python Examples

Python serial examples for Koheron V1 firmware controllers.

This page shows simple Python patterns for the V1 firmware serial protocol.

from serial import Serial

PORT = "/dev/ttyUSB0"
BAUD = 115200

def read_until_prompt(ser):
    return ser.read_until(b">>").decode("ascii", errors="replace")

def query(ser, command):
    ser.write((command + "\r\n").encode("ascii"))
    ser.flush()
    return read_until_prompt(ser)

Terminal equivalent:

>> version
V1.x
>> tboard
25.45

For memr and raw-binary memw, use byte-counted reads and writes for their size-prefixed binary responses instead of line-oriented helpers.