PYTHON · 0.2.0 · MIT

KymoCore Python 0.2.0 documentation

Install kymocore from PyPI and connect Python to KymoStudio: Core lifecycle, Plot, Parameter, Watch, Memory, Trace and transport configuration.

Product overview · PyPI 0.2.0 · Versions

Install from PyPI

Use Python 3.10 or newer. UDP and TCP need only the standard library. Install an extra for serial (pyserial) or MQTT (paho-mqtt).

python -m pip install --upgrade "kymocore==0.2.0"
python -m pip install "kymocore[serial]==0.2.0"
python -m pip install "kymocore[mqtt]==0.2.0"

The examples use KymoStudio 2.10.0. Python uses the released Embedded 8.0.0 feature contracts: DATA/control framing v6.2 and Trace wire v2.

Plot and change a parameter

import time
from kymocore import Core, Parameter, Plot

gain = Parameter(50, 1., minimum=0., maximum=5., name='gain', unit='V')
with Core.tcp_server(5025, '127.0.0.1',
                     plots=[Plot(0, lambda: gain.value * 2, period_ms=20)],
                     parameters=[gain]) as core:
    deadline = time.monotonic() + 30
    while time.monotonic() < deadline:
        core.main()
        time.sleep(.001)
  1. Save as demo.py and run python demo.py.
  2. In KymoStudio add and start a Telnet/TCP source at 127.0.0.1, port 5025.
  3. Add channel 0 to a chart. Open Parameters through Add and discover the source’s parameters.
  4. Write gain between 0 and 5. Readback confirms the actual value; the plotted value becomes twice the gain.

The script runs for 30 seconds and then drains its pending output.

Plot & Parameter

Plot(channel, read, period_ms=20) calls a reader returning a number or Sample(y, x=None, z=None). Late cycles do not produce a catch-up burst. Parameters can own their value or use paired get= and set= callbacks. Names are limited to 24 UTF-8 bytes, units to 8; use descriptive names.

Only valid CRC-protected scalar writes change registered parameters. Out-of-range writes return the unchanged value. Values and limits use float32. Keep Plot, Parameter and Memory channels distinct and outside the entire Watch interval (default 200–215).

Named live variables

After defining gain and before creating Core, add:

from kymocore import Watch, WatchVariable, WatchType

watch = Watch.from_variables([
    WatchVariable('gain', WatchType.F32, lambda: gain.value),
], build_tag='my-application-1')
watch.export_elf('python-watch.elf')

Add watch=watch to Core.tcp_server(...). In Studio open Live variables through Add, load python-watch.elf and select gain. The exported ELF supplies names, types and a matching build ID.

This file is a data-only symbol map, not firmware or a process-memory dump. Virtual slots call your registered readers. Up to 256 names can be registered, with eight active sampling slots by default. Keep declaration order, names, types and build tag unchanged to retain the mapping; re-export and reload it when these change. Manual WatchRange readers can expose explicit little-endian layouts; they do not get automatic symbol export.

Memory telemetry in bytes

Memory(channel, kind, read, name="", total=0, period_ms=1000, info_period_ms=5000) samples an unsigned 32-bit byte count. Supported kinds are MemoryKind.STACK_PEAK, HEAP_FREE and HEAP_MIN_FREE. Pass definitions as memory=[...] to Core; metadata describes the name, kind and optional total.

Supply actual measurements from an application allocator or native extension. Python allocation totals from tracemalloc and free operating-system memory are different measurements from a device’s free heap. The library does not calculate these counters automatically. The complete example below explicitly uses a synthetic memory pool.

Trace scopes and functions

Register contexts and symbols before starting Core:

from kymocore import Trace

trace = Trace(device_id='test-bench', build_id='experiment-1')
trace.context(1, 'main')
trace.symbol(1, 'read-sensors', kind='scope')
trace.symbol(2, 'sample-ready', kind='marker')

Pass trace=trace to Core. Inside its with block, wrap application work with:

with trace.scope(1, 1):
    trace.mark(1, 2, 42)

scope() pairs ENTER/EXIT even on exceptions. @trace.instrument(context, symbol) supports normal and async functions. Use different context IDs for concurrent tasks or threads. Open the source in Studio’s runtime trace to inspect spans and markers.

Task, flow and ISR hooks emit events explicitly supplied by your application. They do not automatically capture the OS scheduler, physical CPU assignment or hardware interrupts, and cannot establish complete CPU utilization. The bounded ring holds 64 events per logical core by default; inspect trace.diagnostics for drops and errors. Metadata repeats every five seconds by default.

One connection for all features

CoreKymoStudio
Core.udp(host, port, bind=None, **features)Studio listens on the destination port. Replies use the last received sender. Set bind=(host, port) for a known local port.
Core.tcp_server(port, host='0.0.0.0', **features)Studio connects as TCP client. Use 127.0.0.1 for a local-only server, as in the example.
Core.serial(port, baudrate=115200, **features)Install the serial extra. Use matching baud rates on both endpoints of the serial link.
Core.mqtt(host, topic, rx_topic=..., **features)Install the MQTT extra. Studio receives telemetry on topic and publishes commands to the separate rx_topic. Retained commands are ignored.

Pass the same plots, parameters, watch, memory and trace arguments to each constructor. The package has no CAN driver.

Lifecycle and migration from 0.1

Call core.main() regularly from one owner. It receives bounded input, samples features and sends queued frames without interleaving partial writes. Callbacks run in that calling thread and must not block. Python offers no hard-real-time guarantee. All measurement features share Core’s monotonic clock; timestamps default to microseconds and are captured when sampled.

Stop trace producers and finish scopes before shutdown. request_stop() starts draining; continue main() until stopped, or use close(timeout=2) or a with block. A close timeout is reported and the transport is released. An exception escaping the Core context does not claim a complete trace session. Network acceptance is not proof of remote delivery.

Existing Sender, frame() and transport constructors remain available. Keep Sender for simple immediate measurements; use Core for the return channel and bounded handling of transport backpressure. Core.send(channel, y, x=..., z=...) queues immediate values on unreserved channels and raises BufferError if the queue is full. Do not mutate feature definitions after constructing Core; a new run needs new Core and Trace instances.

Complete example and release reference

Download the all-features script from the linked release source, then run python all_features.py --transport tcp --port 5025. Connect Studio as above and load the generated python-watch.elf for named variables. Plot 0, parameter 50, Watch channels 200–215 and memory 220 have separate channel ranges.

Release tests cover Studio decoding, TCP/UDP loopback, serial loopback and simulated MQTT callbacks. Physical hardware and an external MQTT broker need their own environment check.