Note
Go to the end to download the full example code.
Automatic node discovery#
Showcases how the client automatically discovers nodes and gets their description.
from pyaseba.client import Client
client = Client()
connection = client.connect("tcp", port=33333)
connection
1
The client regularly broadcasts a discovery message. Remote nodes that answer are asked to send their description. The following method waits until the descriptions are received.
client.wait_nodes(wait_ms=500)
{1: {0}}
Discovered node IDs are kept in memory
{1: {0}}
as well as their description.
{1: {0: Description(name='SimpleNode', protocol_version=9, variables={'_productId': (34, 1), 'args': (2, 32), 'counter': (35, 1), 'id': (0, 1), 'source': (1, 1), 'value': (36, 1)}, local_events={'event': 'emitted at each control step after incrementing counter'}, user_events={}, functions={'duplicate': ('duplicates the input', [('input', 1), ('result', 1)]), 'square': ('set value to the square of the input', [('input', 1)])})}}
Alternatively, if we wait for a single node, we can call
node_id, connection = client.wait_node(wait_ms=500)
node_id, connection
(0, 1)
and
client.get_description(node_id=node_id)
Description(name='SimpleNode', protocol_version=9, variables={'_productId': (34, 1), 'args': (2, 32), 'counter': (35, 1), 'id': (0, 1), 'source': (1, 1), 'value': (36, 1)}, local_events={'event': 'emitted at each control step after incrementing counter'}, user_events={}, functions={'duplicate': ('duplicates the input', [('input', 1), ('result', 1)]), 'square': ('set value to the square of the input', [('input', 1)])})
Total running time of the script: (0 minutes 1.050 seconds)