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-2024 WPC Systems Ltd. All rights reserved.
17'''
18
19## Python
20import time
21
22## WPC
23
24from wpcsys import pywpc
25
26
27def main():
28 ## Get Python driver version
29 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
30
31 ## Create device handle
32 dev = pywpc.USBDAQF1AOD()
33
34 ## Connect to device
35 try:
36 dev.connect("default") ## 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 timeout = 3 ## second
48
49 ## Get firmware model & version
50 driver_info = dev.Sys_getDriverInfo(timeout)
51 print("Model name: " + driver_info[0])
52 print("Firmware version: " + driver_info[-1])
53
54 ## Open AO
55 err = dev.AO_open(port, timeout)
56 print(f"AO_open in port {port}, status: {err}")
57
58 ## Write AO vaule in channel 0
59 err = dev.AO_writeOneChannel(port, 0, ao_value_list[0], timeout)
60 print(f"In port {port} channel 0, the AO value is {ao_value_list[0]}, status: {err}")
61
62 ## Write AO vaule in channel 1
63 err = dev.AO_writeOneChannel(port, 1, ao_value_list[1], timeout)
64 print(f"In port {port} channel 1, the AO value is {ao_value_list[1]}, status: {err}")
65
66 ## Write AO vaule in channel 2
67 err = dev.AO_writeOneChannel(port, 2, ao_value_list[2], timeout)
68 print(f"In port {port} channel 2, the AO value is {ao_value_list[2]}, status: {err}")
69
70 ## Write AO vaule in channel 3
71 err = dev.AO_writeOneChannel(port, 3, ao_value_list[3], timeout)
72 print(f"In port {port} channel 3, the AO value is {ao_value_list[3]}, status: {err}")
73
74 ## Close AO
75 err = dev.AO_close(port)
76 print(f"AO_close in port {port}, status: {err}")
77 except Exception as err:
78 pywpc.printGenericError(err)
79
80 ## Disconnect device
81 dev.disconnect()
82
83 ## Release device handle
84 dev.close()
85
86 return
87
88if __name__ == '__main__':
89 main()