Interface

The Interface base class is intended to provide a wrapper around transport layer implementations (like TCP/IP or CAN), with the goal of making each Node instance transport method agnostic.

class pyolcb.Interface(connection=None)

A connection to an OpenLCB/LCC network.

The base class wraps a python-can bus. GridConnect over TCP and over a serial line are provided by pyolcb.gridconnect.GridConnectTcpInterface and pyolcb.gridconnect.GridConnectSerialInterface, which share this API: send() a Message or Frame, and register_listener() to be called with every received frame.

Parameters:

connection (can.BusABC) – The python-can bus to use.

close()

Release the connection.

property connected: bool

True while frames can be sent. A CAN bus is always connected.

register_listener(function: callable)

Register a function to be called with every frame received. On a CAN bus the argument is a can.Message; on GridConnect interfaces it is a Frame. Both have arbitration_id and data.

register_state_listener(function: callable)

Register a function to be called with True when the interface (re)connects and False when it loses its connection. A node uses this to claim a fresh alias after every reconnect.

send(message: Message | Frame)

Send a Message or a raw Frame.