1'''
2AO - AO_write_one_channel.py with synchronous mode.
3
4This example demonstrates the process of writing AO signal of USBDAQF1AOD.
5To begin with, it demonstrates the steps to open AO.
6Next, it outlines the procedure for writing digital signals with channel 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
23def main():
24 ## Get Python driver version
25 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
26
27 ## Create device handle
28 dev = pywpc.USBDAQF1AOD()
29
30 ## Connect to device
31 try:
32 dev.connect("default") ## Depend on your device
33 except Exception as err:
34 pywpc.printGenericError(err)
35 ## Release device handle
36 dev.close()
37 return
38
39 try:
40 ## Parameters setting
41 port = 0 ## Depend on your device
42 ao_value_list = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5]
43 timeout = 3 ## [sec]
44
45 ## Get firmware model & version
46 driver_info = dev.Sys_getDriverInfo(timeout)
47 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
48
49 ## Open AO
50 err = dev.AO_open(port, timeout)
51 print(f"AO_open in port {port}, status: {err}")
52
53 ## Write AO vaule in channel 0
54 err = dev.AO_writeOneChannel(port, 0, ao_value_list[0], timeout)
55 print(f"In port {port} channel 0, the AO value is {ao_value_list[0]}, status: {err}")
56
57 ## Write AO vaule in channel 1
58 err = dev.AO_writeOneChannel(port, 1, ao_value_list[1], timeout)
59 print(f"In port {port} channel 1, the AO value is {ao_value_list[1]}, status: {err}")
60
61 ## Write AO vaule in channel 2
62 err = dev.AO_writeOneChannel(port, 2, ao_value_list[2], timeout)
63 print(f"In port {port} channel 2, the AO value is {ao_value_list[2]}, status: {err}")
64
65 ## Write AO vaule in channel 3
66 err = dev.AO_writeOneChannel(port, 3, ao_value_list[3], timeout)
67 print(f"In port {port} channel 3, the AO value is {ao_value_list[3]}, status: {err}")
68
69 ## Close AO
70 err = dev.AO_close(port)
71 print(f"AO_close in port {port}, status: {err}")
72 except Exception as err:
73 pywpc.printGenericError(err)
74
75 finally:
76 ## Disconnect device
77 dev.disconnect()
78
79 ## Release device handle
80 dev.close()
81
82
83if __name__ == '__main__':
84 main()