1'''
2Find_devices - find_all_devices.py with asynchronous mode.
3
4This example demonstrates how to find all available USB and ethernet devices.
5
6For other examples please check:
7 https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
8See README.md file to get detailed usage of this example.
9
10Copyright (c) 2022-2025 WPC Systems Ltd. All rights reserved.
11'''
12
13## WPC
14from wpcsys import pywpc
15
16## Python
17import asyncio
18import sys
19sys.path.insert(0, 'src/')
20
21
22async def main():
23 ## Get Python driver version
24 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
25
26 ## Create device handle
27 dev = pywpc.DeviceFinder()
28
29 ## Connect to device
30 dev.connect()
31
32 ## Perform USB device information
33 print("Find all USB devices....")
34 try:
35 dev_2d_list = dev.Bcst_enumerateUSBDevices()
36 for device_list in dev_2d_list:
37 print(device_list)
38 except Exception as err:
39 pywpc.printGenericError(err)
40
41 ## Perform network device information
42 print("Find all network devices....")
43 try:
44 dev_2d_list = await dev.Bcst_enumerateNetworkDevices_async()
45 for device_list in dev_2d_list:
46 print(device_list)
47 except Exception as err:
48 pywpc.printGenericError(err)
49
50 finally:
51 ## Disconnect device
52 dev.disconnect()
53
54 ## Release device handle
55 dev.close()
56
57
58def main_for_spyder(*args):
59 if asyncio.get_event_loop().is_running():
60 return asyncio.create_task(main(*args)).result()
61 else:
62 return asyncio.run(main(*args))
63
64
65if __name__ == '__main__':
66 asyncio.run(main()) ## Use terminal
67 # await main() ## Use Jupyter or IPython(>=7.0)
68 # main_for_spyder() ## Use Spyder