1'''
2AIO - AIO_all_channels_loopback.py with synchronous mode.
3
4This example demonstrates the process of AIO loopback across all channels of USBDAQF1AOD.
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-2025 WPC Systems Ltd. All rights reserved.
21'''
22
23## WPC
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 ## [sec]
48 channel = 8
49 ## Get firmware model & version
50 driver_info = dev.Sys_getDriverInfo(timeout)
51 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
52
53 ## Open AI
54 err = dev.AI_open(port, timeout)
55 print(f"AI_open in port {port}, status: {err}")
56
57
58 ## Set AI channel
59 err = dev.AI_enableChannel(port, channel, timeout)
60 print(f"AI_enableChannel in port {port}, status: {err}")
61
62 ## Open AO
63 err = dev.AO_open(port, timeout)
64 print(f"AO_open in port {port}, status: {err}")
65
66 ## Read data acquisition
67 ai_list = dev.AI_readOnDemand(port, timeout)
68 print(f"AI data in port {port}: {ai_list}")
69
70 ## Write AO value simultaneously
71 err = dev.AO_writeAllChannels(port, ao_value_list, timeout)
72 print(f"In port {port} the AO value is {ao_value_list}, status: {err}")
73
74 ## Read data acquisition
75 ai_list = dev.AI_readOnDemand(port, timeout)
76 print(f"AI data in port {port}: {ai_list}")
77
78 ## Close AI
79 err = dev.AI_close(port, timeout)
80 print(f"AI_close in port {port}, status: {err}")
81
82 ## Close AO
83 err = dev.AO_close(port, timeout)
84 print(f"AO_close in port {port}, status: {err}")
85 except Exception as err:
86 pywpc.printGenericError(err)
87
88 finally:
89 ## Disconnect device
90 dev.disconnect()
91
92 ## Release device handle
93 dev.close()
94
95
96if __name__ == '__main__':
97 main()