Get device alias

 1'''
 2System_USB - get_device_alias.py with asynchronous mode.
 3
 4This example demonstrates how to get device alias from USBDAQF1DSNK.
 5
 6-------------------------------------------------------------------------------------
 7Please change correct serial number or IP and port number BEFORE you run example code.
 8
 9For other examples please check:
10    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
11See README.md file to get detailed usage of this example.
12
13Copyright (c) 2022-2025 WPC Systems Ltd. All rights reserved.
14'''
15
16## WPC
17from wpcsys import pywpc
18
19## Python
20import asyncio
21import sys
22sys.path.insert(0, 'src/')
23
24
25async def main():
26    ## Get Python driver version
27    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
28
29    ## Create device handle
30    dev = pywpc.USBDAQF1DSNK()
31
32    ## Connect to device
33    try:
34        dev.connect("default")  ## Depend on your device
35    except Exception as err:
36        pywpc.printGenericError(err)
37        ## Release device handle
38        dev.close()
39        return
40
41    try:
42        ## Get firmware model & version
43        driver_info = await dev.Sys_getDriverInfo_async()
44        print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
45
46        ## Get device alias
47        device_alias = await dev.Sys_getDeviceAlias_async()
48        print(f"Device alias: {device_alias}")
49    except Exception as err:
50        pywpc.printGenericError(err)
51
52    finally:
53        ## Disconnect UDB device
54        dev.disconnect()
55
56        ## Release device handle
57        dev.close()
58
59
60def main_for_spyder(*args):
61    if asyncio.get_event_loop().is_running():
62        return asyncio.create_task(main(*args)).result()
63    else:
64        return asyncio.run(main(*args))
65
66
67if __name__ == '__main__':
68    asyncio.run(main())  ## Use terminal
69    # await main()  ## Use Jupyter or IPython(>=7.0)
70    # main_for_spyder()  ## Use Spyder