1
2'''
3AO - AO_waveform_gen.py with synchronous mode.
4
5This example demonstrates the process of writing AO signal of USBDAQF1AOD.
6To begin with, it demonstrates the steps to open AO and configure the AO parameters.
7Next, it outlines the procedure for AO streaming.
8Finally, it concludes by explaining how to close AO.
9
10-------------------------------------------------------------------------------------
11Please change correct serial number or IP and port number BEFORE you run example code.
12
13For other examples please check:
14 https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
15See README.md file to get detailed usage of this example.
16
17Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
18'''
19
20## Python
21import time
22
23## WPC
24
25from wpcsys import pywpc
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 mode = 2 ## 0: on demand, 1: N-samples, 2: Continuous
47 sampling_rate = 1000
48 number_of_sample = 1000
49 form_mode = 3 ## 0:DC voltage, 1: retangular, 2: triangular, 3: sine.
50 amplitude = 1
51 offset = 0.1
52 freq_0 = 10
53 freq_1 = 20
54 timeout = 3 ## second
55
56 ## Get firmware model & version
57 driver_info = dev.Sys_getDriverInfo(timeout)
58 print("Model name: " + driver_info[0])
59 print("Firmware version: " + driver_info[-1])
60
61 ## Open AO
62 err = dev.AO_open(port, timeout)
63 print(f"AO_open in port {port}, status: {err}")
64
65 ## Set AO generation mode
66 err = dev.AO_setMode(port, mode, timeout)
67 print(f"AO_setMode in port {port}, status: {err}")
68
69 ## Set AO sampling rate to 10k (Hz)
70 err = dev.AO_setSamplingRate(port, sampling_rate, timeout)
71 print(f"AO_setSamplingRate in port {port}, status: {err}")
72
73 ## Set AO NumSamples to 10000
74 err = dev.AO_setNumSamples(port, number_of_sample, timeout)
75 print(f"AO_setNumSamples in port {port}, status: {err}")
76
77 ## Set AO enabled channels
78 err = dev.AO_setEnableChannels(port, [0, 1], timeout)
79 print(f"AO_setEnableChannels in port {port}, status: {err}")
80
81 ## Set AO form in channel 0
82 err = dev.AO_setForm(port, 0, form_mode, timeout)
83 print(f"AO_setForm in channel 0 in port {port}, status: {err}")
84
85 ## Set AO form in channel 1
86 err = dev.AO_setForm(port, 1, form_mode, timeout)
87 print(f"AO_setForm in channel 1 in port {port}, status: {err}")
88
89 ## Set Channel 0 form parameters
90 err = dev.AO_setFormParam(port, 0, amplitude, offset, freq_0, timeout)
91 print(f"AO_setFormParam in channel 0 in port {port}, status: {err}")
92
93 ## Set Channel 1 form parameters
94 err = dev.AO_setFormParam(port, 1, amplitude, offset, freq_1, timeout)
95 print(f"AO_setFormParam in channel 1 in port {port}, status: {err}")
96
97 ## Open AO streaming
98 info = dev.AO_openStreaming(port, timeout)
99 print(f"Mode {info[0]}, sampling rate {info[1]}")
100
101 ## Start AO streaming
102 err = dev.AO_startStreaming(port)
103 print(f"AO_startStreaming in port {port}, status: {err}")
104
105 ## Wait for 10 seconds to generate form
106 time.sleep(10) ## delay [s]
107
108 ## Close AO streaming
109 err = dev.AO_closeStreaming(port, timeout)
110 print(f"AO_closeStreaming in port {port}, status: {err}")
111
112 ## Close AO
113 err = dev.AO_close(port)
114 print(f"AO_close in port {port}, status: {err}")
115 except Exception as err:
116 pywpc.printGenericError(err)
117
118 ## Disconnect device
119 dev.disconnect()
120
121 ## Release device handle
122 dev.close()
123
124 return
125if __name__ == '__main__':
126 main()