Node

The Node is the building block of an OpenLCB/LCC network. Each Node can communicate with any other Node on the network by sending events or datagrams over the common bus. Each Node object can be attached to an Interface (or multiple) to allow for complex network architectures. Each Message should originate from one Node.

class pyolcb.Node(address: Address, interfaces: Interface | list[Interface])

Implementation of an OpenLCB/LCC Node.

Parameters:
  • address (Address) – The address (full and alias) to be associated with the Node.

  • interfaces (int, Interface | list[Interface]) – An Interface or list thereof to connect the Node to.

add_consumer(event: Event | int, function: callable)

Register a function to be run on receipt of a specific Event.

Parameters:
  • event (int | Event) – The ID or Event to consume. By default, if an int is provided for this parameter, and the (unsigned) value fits within two bytes, the Event will be tagged with the address of the Node. This behavior can be overridden by passing an Event object with no source address.

  • function (callable) – The function to be called upon receipt of the specified Event. Must be able to take no parameters.

consume(event: Event | int)

Run the consumer for a specific Event.

Parameters:

event (int | Event) – The ID or Event to consume. By default, if an int is provided for this parameter, and the (unsigned) value fits within two bytes, the Event will be tagged with the address of the Node. This behavior can be overridden by passing an Event object with no source address.

Returns:

Returns what the registered consumer function returns.

Return type:

any

get_alias() int

Get the Node’s alias.

Returns:

Returns the Node’s alias as an int.

Return type:

int

get_consumer(event: Event | int)

Run the consumer for a specific Event.

Parameters:

event (int | Event) – The ID or Event to consume. By default, if an int is provided for this parameter, and the (unsigned) value fits within two bytes, the Event will be tagged with the address of the Node. This behavior can be overridden by passing an Event object with no source address.

Returns:

Returns the registered consumer function.

Return type:

callable

produce(event: int | Event)

Produce an Event and send the resulting message on all interfaces.

Parameters:

event (int | Event) – The ID or Event to produce and send. By default, if an int is provided for this parameter, and the (unsigned) value fits within two bytes, the Event will be tagged with the address of the Node. This behavior can be overridden by passing an Event object with no source address.

remove_consumer(event: Event | int)

Deregister the function to be run on receipt of a specific Event.

Parameters:

event (int | Event) – The ID or Event to consume. By default, if an int is provided for this parameter, and the (unsigned) value fits within two bytes, the Event will be tagged with the address of the Node. This behavior can be overridden by passing an Event object with no source address.

replace_consumer(event: Event | int, function: callable)

Replace a function that is run on receipt of a specific Event.

Parameters:
  • event (int | Event) – The ID or Event to consume. By default, if an int is provided for this parameter, and the (unsigned) value fits within two bytes, the Event will be tagged with the address of the Node. This behavior can be overridden by passing an Event object with no source address.

  • function (callable) – The function to be called upon receipt of the specified Event. Must be able to take no parameters.

send(messages: Message | list[Message])

Send a Message (or sequence thereof) from this Node on all registered interfaces.

Parameters:

messages (Message | list[Message]) – The Message (or ordered list thereof) to send

set_datagram_handler(datagram_handler: callable)

Register a function to be run on receipt of a Datagram.

Parameters:

datagram_handler (callable) – The function to be called upon receipt of a Datagram packet. Must take a Datagram as the first parameter.

set_unknown_message_processor(function: callable)

Register a function to be run on receipt of a message of unknown type.

Parameters:

function (callable) – The function to be called upon receipt of an unknown message. Must take a Message as the first parameter.

verify_node_id(address: Address | int | None = None)

Send a request to verify aliases on an OpenLCB/LCC network.

Parameters:

address (Address | int = None) – If specified, only request a response for a Node with a given alias. Otherwise, request responses from each Node attached to all registered interfaces.