Find all devices

 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-2024 WPC Systems Ltd. All rights reserved.
11'''
12
13## Python
14import asyncio
15
16## WPC
17
18from wpcsys import pywpc
19
20async def main():
21    ## Get Python driver version
22    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
23
24    ## Create device handle
25    dev = pywpc.DeviceFinder()
26
27    ## Connect to device
28    dev.connect()
29
30    ## Perform USB device information
31    print("Find all USB devices....")
32    try:
33        dev_2d_list = dev.Bcst_enumerateUSBDevices()
34        for device_list in dev_2d_list:
35            print(device_list)
36    except Exception as err:
37        pywpc.printGenericError(err)
38
39    ## Perform network device information
40    print("Find all network devices....")
41    try:
42        dev_2d_list = await dev.Bcst_enumerateNetworkDevices_async()
43        for device_list in dev_2d_list:
44            print(device_list)
45    except Exception as err:
46        pywpc.printGenericError(err)
47
48    ## Disconnect to device
49    dev.disconnect()
50
51    ## Release device handle
52    dev.close()
53
54    return
55
56def main_for_spyder(*args):
57    if asyncio.get_event_loop().is_running():
58        return asyncio.create_task(main(*args)).result()
59    else:
60        return asyncio.run(main(*args))
61
62if __name__ == '__main__':
63    asyncio.run(main()) ## Use terminal
64    # await main() ## Use Jupyter or IPython(>=7.0)
65    # main_for_spyder() ## Use Spyder