AO write all channels

 1'''
 2AO - AO_write_all_channels.py with asynchronous mode.
 3
 4This example demonstrates the process of writing AO signal of WifiDAQE3AOD.
 5To begin with, it demonstrates the steps to open AO.
 6Next, it outlines the procedure for writing digital signals simultaneously to the AO pins.
 7Finally, it concludes by explaining how to close AO.
 8
 9-------------------------------------------------------------------------------------
10Please change correct serial number or IP and port number BEFORE you run example code.
11
12For other examples please check:
13    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
14See README.md file to get detailed usage of this example.
15
16Copyright (c) 2022-2025 WPC Systems Ltd. All rights reserved.
17'''
18
19## WPC
20from wpcsys import pywpc
21
22## Python
23import asyncio
24import sys
25sys.path.insert(0, 'src/')
26
27
28async def main():
29    ## Get Python driver version
30    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
31
32    ## Create device handle
33    dev = pywpc.WifiDAQE3AOD()
34
35    ## Connect to device
36    try:
37        dev.connect("192.168.5.38")  ## Depend on your device
38    except Exception as err:
39        pywpc.printGenericError(err)
40        ## Release device handle
41        dev.close()
42        return
43
44    try:
45        ## Parameters setting
46        port = 0  ## Depend on your device
47        ao_value_list = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5]
48
49        ## Get firmware model & version
50        driver_info = await dev.Sys_getDriverInfo_async()
51        print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
52
53        ## Open AO
54        err = await dev.AO_open_async(port)
55        print(f"AO_open_async in port {port}, status: {err}")
56
57        ## Write AO value simultaneously
58        err = await dev.AO_writeAllChannels_async(port, ao_value_list)
59        print(f"In port {port} the AO value is {ao_value_list}, status: {err}")
60
61        ## Close AO
62        err = await dev.AO_close_async(port)
63        print(f"AO_close_async in port {port}, status: {err}")
64    except Exception as err:
65        pywpc.printGenericError(err)
66
67    finally:
68        ## Disconnect device
69        dev.disconnect()
70
71        ## Release device handle
72        dev.close()
73
74
75def main_for_spyder(*args):
76    if asyncio.get_event_loop().is_running():
77        return asyncio.create_task(main(*args)).result()
78    else:
79        return asyncio.run(main(*args))
80
81
82if __name__ == '__main__':
83    asyncio.run(main())  ## Use terminal
84    # await main()  ## Use Jupyter or IPython(>=7.0)
85    # main_for_spyder()  ## Use Spyder