1'''
2System_USB - set_device_alias.py with asynchronous mode.
3
4This example demonstrates how to set device alias from USBDAQF1AOD.
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.USBDAQF1AOD()
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 ## Parameters setting
43 alias_name = "WPC_1234"
44
45 ## Get firmware model & version
46 driver_info = await dev.Sys_getDriverInfo_async()
47 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
48
49 ## Set device alias
50 err = await dev.Sys_setDeviceAlias_async(alias_name)
51 print(f"Sys_setDeviceAlias_async, status: {err}")
52 except Exception as err:
53 pywpc.printGenericError(err)
54
55 finally:
56 ## Disconnect UDB device
57 dev.disconnect()
58
59 ## Release device handle
60 dev.close()
61
62
63def main_for_spyder(*args):
64 if asyncio.get_event_loop().is_running():
65 return asyncio.create_task(main(*args)).result()
66 else:
67 return asyncio.run(main(*args))
68
69
70if __name__ == '__main__':
71 asyncio.run(main()) ## Use terminal
72 # await main() ## Use Jupyter or IPython(>=7.0)
73 # main_for_spyder() ## Use Spyder