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-2024 WPC Systems Ltd. All rights reserved.
17'''
18
19## Python
20import asyncio
21
22## WPC
23
24from wpcsys import pywpc
25
26
27async def main():
28    ## Get Python driver version
29    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
30
31    ## Create device handle
32    dev = pywpc.WifiDAQE3AOD()
33
34    ## Connect to device
35    try:
36        dev.connect("192.168.5.38") ## Depend on your device
37    except Exception as err:
38        pywpc.printGenericError(err)
39        ## Release device handle
40        dev.close()
41        return
42
43    try:
44        ## Parameters setting
45        port = 0 ## Depend on your device
46        ao_value_list = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5]
47
48        ## Get firmware model & version
49        driver_info = await dev.Sys_getDriverInfo_async()
50        print("Model name: " + driver_info[0])
51        print("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    ## Disconnect device
68    dev.disconnect()
69
70    ## Release device handle
71    dev.close()
72
73    return
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))
80if __name__ == '__main__':
81    asyncio.run(main()) ## Use terminal
82    # await main() ## Use Jupyter or IPython(>=7.0)
83    # main_for_spyder() ## Use Spyder