AO write all channels

 1'''
 2AO - AO_write_all_channels.py with synchronous mode.
 3
 4This example demonstrates the process of writing AO signal of STEM.
 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
 9If your product is "STEM", please invoke the function `Sys_setAIOMode`.
10
11-------------------------------------------------------------------------------------
12Please change correct serial number or IP and port number BEFORE you run example code.
13
14For other examples please check:
15    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
16See README.md file to get detailed usage of this example.
17
18Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
19'''
20
21## Python
22import time
23
24## WPC
25
26from wpcsys import pywpc
27
28
29def main():
30    ## Get Python driver version
31    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
32
33    ## Create device handle
34    dev = pywpc.STEM()
35
36    ## Connect to device
37    try:
38        dev.connect("192.168.1.110") ## Depend on your device
39    except Exception as err:
40        pywpc.printGenericError(err)
41        ## Release device handle
42        dev.close()
43        return
44
45    try:
46        ## Parameters setting
47        slot = 1 ## Connect AIO module to slot
48        ao_value_list = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5]
49        timeout = 3 ## second
50
51        ## Get firmware model & version
52        driver_info = dev.Sys_getDriverInfo(timeout)
53        print("Model name: " + driver_info[0])
54        print("Firmware version: " + driver_info[-1])
55
56        ## Get slot mode
57        slot_mode = dev.Sys_getMode(slot, timeout)
58        print("Slot mode:", slot_mode)
59
60        ## If the slot mode is not set to "AIO", set the slot mode to "AIO"
61        if slot_mode != "AIO":
62            err = dev.Sys_setAIOMode(slot, timeout)
63            print(f"Sys_setAIOMode in slot {slot}, status: {err}")
64
65        ## Get slot mode
66        slot_mode = dev.Sys_getMode(slot, timeout)
67        print("Slot mode:", slot_mode)
68
69        ## Open AO
70        err = dev.AO_open(slot, timeout)
71        print(f"AO_open in slot {slot}, status: {err}")
72
73        ## Write AO value simultaneously
74        err = dev.AO_writeAllChannels(slot, ao_value_list, timeout)
75        print(f"In slot {slot} the AO value is {ao_value_list}, status: {err}")
76
77        ## Close AO
78        err = dev.AO_close(slot)
79        print(f"AO_close in slot {slot}, status: {err}")
80    except Exception as err:
81        pywpc.printGenericError(err)
82
83    ## Disconnect device
84    dev.disconnect()
85
86    ## Release device handle
87    dev.close()
88
89    return
90
91if __name__ == '__main__':
92    main()