-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_discover_devices.py
38 lines (27 loc) · 1 KB
/
example_discover_devices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import asyncio
import logging
import sys
from aioxcom import XcomApiTcp, XcomDataset, XcomDiscover, VOLTAGE
# Setup logging to StdOut
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger(__name__)
async def main():
# Discover all Xcom devices
api = XcomApiTcp(4001) # port number configured in Xcom-LAN/Moxa NPort
dataset = await XcomDataset.create(VOLTAGE.AC240) # or use VOLTAGE.AC120
try:
if not await api.start():
logger.info(f"Did not connect to Xcom")
return
helper = XcomDiscover(api, dataset)
devices = await helper.discoverDevices(getExtendedInfo=True, verbose=False)
logger.info(f"\n\n")
for device in devices:
logger.info(f"Discovered {device}")
# Log diagnostic information
diag = await api.getDiagnostics()
logger.info(f"Diagnostics: {diag}")
finally:
await api.stop()
dataset = None
asyncio.run(main()) # main loop