Skip to content

Python library

python/mscb.py implements the Ethernet/UDP MSCB transport directly. It does not load src/mscb.cxx, a shared library, USB drivers, or RPC components.

python/msc.py finds it through Python's ordinary import mechanism:

import mscb

When python/msc.py is run as a script, Python adds its containing python/ directory to sys.path, so the adjacent python/mscb.py is imported. No pip installation is needed for this repository layout.

Direct use

import mscb

fd = mscb.mscb_init("192.0.2.40")
if fd < 0:
    raise ConnectionError(fd)

try:
    if mscb.mscb_ping(fd, 1) == mscb.MSCB_SUCCESS:
        print("node 1 is alive")
finally:
    mscb.mscb_exit(fd)

These public module functions deliberately keep the familiar C names, so msc.py calls mscb.mscb_ping(...), mscb.mscb_read(...), and similar functions directly. mscb is the imported module; the name after the dot is an object defined in that module. It is not a dynamic link or an include directive.

For small new programs, the optional MSCB context-manager façade provides shorter ping(), read(), and write() methods:

with mscb.MSCB("192.0.2.40") as bus:
    if bus.ping(1):
        print(bus.read(1, 0))

Installation choices

For in-tree use, run:

python3 python/msc.py -d 192.0.2.40

For another application, either put python/ on PYTHONPATH, copy/package the module with the application, or add standard package metadata and install it. The current source tree itself does not require a published pip package.

XML snapshots

The Python CLI can save a node as readable XML. The writer applies element indentation and appends a final newline, so every entry is on its own line and the result remains friendly to version control and comparison with C-client output.

Scope

Only UDB/Ethernet communication is implemented. USB device discovery, direct parallel-port access, and MSCB RPC forwarding are deliberately absent. The node-bus protocol and typed-variable behavior remain compatible with the C implementation.