Note
Go to the end to download the full example code.
Manual node discovery#
This script showcases how the client can discover nodes and query their description manually.
from pyaseba.client import Client
We set up the client to not discover nodes automatically
client = Client(automatic_query=False, ping_period_ms=0)
connection = client.connect("tcp", port=33333)
connection
1
With this configuration, waiting for nodes will not discover them
client.wait_nodes(wait_ms=500)
{}
Instead, we need to first manually scan for node IDs
scan = client.scan(wait_ms=500)
scan
{1: {0}}
and then query them for a description
for target, node_ids in scan.items():
for node_id in node_ids:
desc = client.query_description(node_id=node_id, wait_ms=500)
print(f"Node {node_id}: {desc}")
Node 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)])})
Once we have received them, IDs and descriptions are accessible like for automatically discovered nodes.
{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)])})}}
Total running time of the script: (0 minutes 1.034 seconds)