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:
- 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 anint
is provided for this parameter, and the (unsigned) value fits within two bytes, theEvent
will be tagged with the address of theNode
. This behavior can be overridden by passing anEvent
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 anint
is provided for this parameter, and the (unsigned) value fits within two bytes, theEvent
will be tagged with the address of theNode
. This behavior can be overridden by passing anEvent
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 anint
.- 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 anint
is provided for this parameter, and the (unsigned) value fits within two bytes, theEvent
will be tagged with the address of theNode
. This behavior can be overridden by passing anEvent
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 anint
is provided for this parameter, and the (unsigned) value fits within two bytes, theEvent
will be tagged with the address of theNode
. This behavior can be overridden by passing anEvent
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 anint
is provided for this parameter, and the (unsigned) value fits within two bytes, theEvent
will be tagged with the address of theNode
. This behavior can be overridden by passing anEvent
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 anint
is provided for this parameter, and the (unsigned) value fits within two bytes, theEvent
will be tagged with the address of theNode
. This behavior can be overridden by passing anEvent
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 thisNode
on all registered interfaces.
- set_datagram_handler(datagram_handler: callable)
Register a function to be run on receipt of a
Datagram
.
- 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.