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-2025 WPC Systems Ltd. All rights reserved.
19'''
20
21## WPC
22from wpcsys import pywpc
23
24
25def main():
26 ## Get Python driver version
27 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
28
29 ## Create device handle
30 dev = pywpc.STEM()
31
32 ## Connect to device
33 try:
34 dev.connect("192.168.1.110") ## 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 slot = 1 ## Connect AIO module to slot
44 ao_value_list = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5]
45 timeout = 3 ## [sec]
46
47 ## Get firmware model & version
48 driver_info = dev.Sys_getDriverInfo(timeout)
49 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
50
51 ## Get slot mode
52 slot_mode = dev.Sys_getMode(slot, timeout)
53 print("Slot mode:", slot_mode)
54
55 ## If the slot mode is not set to "AIO", set the slot mode to "AIO"
56 if slot_mode != "AIO":
57 err = dev.Sys_setAIOMode(slot, timeout)
58 print(f"Sys_setAIOMode in slot {slot}, status: {err}")
59
60 ## Get slot mode
61 slot_mode = dev.Sys_getMode(slot, timeout)
62 print("Slot mode:", slot_mode)
63
64 ## Open AO
65 err = dev.AO_open(slot, timeout)
66 print(f"AO_open in slot {slot}, status: {err}")
67
68 ## Write AO value simultaneously
69 err = dev.AO_writeAllChannels(slot, ao_value_list, timeout)
70 print(f"In slot {slot} the AO value is {ao_value_list}, status: {err}")
71
72 ## Close AO
73 err = dev.AO_close(slot)
74 print(f"AO_close in slot {slot}, status: {err}")
75 except Exception as err:
76 pywpc.printGenericError(err)
77
78 finally:
79 ## Disconnect device
80 dev.disconnect()
81
82 ## Release device handle
83 dev.close()
84
85
86if __name__ == '__main__':
87 main()