1'''
2AIO - AIO_one_channel_loopback.py with synchronous mode.
3
4This example demonstrates the process of AIO loopback with specific channels of WifiDAQE3AOD.
5It involves using AO pins to send signals and AI pins to receive signals on a single device, commonly referred to as "loopback".
6The AI and AO pins are connected using a wire.
7
8Initially, the example demonstrates the steps required to open the AI and AO.
9Next, it reads AI data and displays its corresponding values.
10Following that, it writes digital signals to the AO pins and reads AI on-demand data once again.
11Lastly, it closes the AO and AI ports.
12
13-------------------------------------------------------------------------------------
14Please change correct serial number or IP and port number BEFORE you run example code.
15
16For other examples please check:
17 https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
18See README.md file to get detailed usage of this example.
19
20Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
21'''
22
23## Python
24import time
25
26## WPC
27
28from wpcsys import pywpc
29
30
31def main():
32 ## Get Python driver version
33 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
34
35 ## Create device handle
36 dev = pywpc.WifiDAQE3AOD()
37
38 ## Connect to device
39 try:
40 dev.connect("192.168.5.38") ## Depend on your device
41 except Exception as err:
42 pywpc.printGenericError(err)
43 ## Release device handle
44 dev.close()
45 return
46
47 try:
48 ## Parameters setting
49 port = 0 ## Depend on your device
50 ao_value_list = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5]
51 timeout = 3 ## second
52
53
54 ## Get firmware model & version
55 driver_info = dev.Sys_getDriverInfo(timeout)
56 print("Model name: " + driver_info[0])
57 print("Firmware version: " + driver_info[-1])
58
59 ## Open AI
60 err = dev.AI_open(port, timeout)
61 print(f"AI_open in port {port}, status: {err}")
62
63
64 ## Open AO
65 err = dev.AO_open(port, timeout)
66 print(f"AO_open in port {port}, status: {err}")
67
68 ## Read data acquisition
69 ai_list = dev.AI_readOnDemand(port, timeout)
70 print(f"AI data in port {port}: {ai_list}")
71
72 ## Write AO vaule in channel 0
73 err = dev.AO_writeOneChannel(port, 0, ao_value_list[0], timeout)
74 print(f"In port {port} channel 0, the AO value is {ao_value_list[0]}, status: {err}")
75
76 ## Write AO vaule in channel 1
77 err = dev.AO_writeOneChannel(port, 1, ao_value_list[1], timeout)
78 print(f"In port {port} channel 1, the AO value is {ao_value_list[1]}, status: {err}")
79
80 ## Write AO vaule in channel 2
81 err = dev.AO_writeOneChannel(port, 2, ao_value_list[2], timeout)
82 print(f"In port {port} channel 2, the AO value is {ao_value_list[2]}, status: {err}")
83
84 ## Write AO vaule in channel 3
85 err = dev.AO_writeOneChannel(port, 3, ao_value_list[3], timeout)
86 print(f"In port {port} channel 3, the AO value is {ao_value_list[3]}, status: {err}")
87
88 ## Read data acquisition
89 ai_list = dev.AI_readOnDemand(port, timeout)
90 print(f"AI data in port {port}: {ai_list}")
91
92 ## Close AI
93 err = dev.AI_close(port, timeout)
94 print(f"AI_close in port {port}, status: {err}")
95
96 ## Close AO
97 err = dev.AO_close(port, timeout)
98 print(f"AO_close in port {port}, status: {err}")
99 except Exception as err:
100 pywpc.printGenericError(err)
101
102 ## Disconnect device
103 dev.disconnect()
104
105 ## Release device handle
106 dev.close()
107
108 return
109
110if __name__ == '__main__':
111 main()