1
2'''
3AI - AI_continuous_multi_slot.py.
4
5This example demonstrates the process of obtaining AI data in continuous mode with multi slot from STEM.
6
7To begin with, it demonstrates the steps to open the AI and configure the AI parameters.
8Next, it outlines the procedure for reading the streaming AI data.
9Finally, it concludes by explaining how to close the AI.
10
11Please invoke the function `Sys_setAIOMode_async`and `AI_enableCS_async`.
12Example: AI_enableCS_async is {0, 2}
13Subsequently, the returned value of AI_readOnDemand_async and AI_readStreaming_async will be displayed as follows.
14data:
15 CH0, CH1, CH2, CH3, CH4, CH5, CH6, CH7, CH0, CH1, CH2, CH3, CH4, CH5, CH6, CH7
16 | | |
17 |---------------- CS0-----------------|---------------- CS2------------------|
18[sample0]
19[sample1]
20 .
21 .
22 .
23[sampleN]
24
25-------------------------------------------------------------------------------------
26Please change correct serial number or IP and port number BEFORE you run example code.
27
28For other examples please check:
29 https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
30See README.md file to get detailed usage of this example.
31
32Copyright (c) 2022-2025 WPC Systems Ltd. All rights reserved.
33'''
34
35## WPC
36from wpcsys import pywpc
37
38
39def main():
40 ## Get Python driver version
41 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
42
43 ## Create device handle
44 dev = pywpc.STEM()
45
46 ## Connect to device
47 try:
48 dev.connect("192.168.1.110") ## Depend on your device
49 except Exception as err:
50 pywpc.printGenericError(err)
51 ## Release device handle
52 dev.close()
53 return
54
55 try:
56 ## Parameters setting
57 slot_list = [1, 2] ## Connect AIO module to slot
58 chip_select = [0, 1]
59 mode = 2 ## 0: On demand, 1: N-samples, 2: Continuous
60 sampling_rate = 200
61 read_points = 200
62 read_delay = 2 ## [sec]
63 timeout = 3 ## [sec]
64
65 ## Get firmware model & version
66 driver_info = dev.Sys_getDriverInfo(timeout)
67 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
68
69 for slot in slot_list:
70 ## Get slot mode
71 slot_mode = dev.Sys_getMode(slot, timeout)
72 print("Slot mode:", slot_mode)
73
74 ## If the slot mode is not set to "AIO", set the slot mode to "AIO"
75 if slot_mode != "AIO":
76 err = dev.Sys_setAIOMode(slot, timeout)
77 print(f"Sys_setAIOMod in slot {slot}, status: {err}")
78
79 ## Get slot mode
80 slot_mode = dev.Sys_getMode(slot, timeout)
81 print("Slot mode:", slot_mode)
82
83 ## Open AI
84 err = dev.AI_open(slot, timeout)
85 print(f"AI_open in slot {slot}, status: {err}")
86
87 ## Enable CS
88 err = dev.AI_enableCS(slot, chip_select, timeout)
89 print(f"AI_enableCS in slot {slot}, status: {err}")
90
91 ## Set AI acquisition mode to continuous mode (2)
92 err = dev.AI_setMode(slot, mode, timeout)
93 print(f"AI_setMode {mode} in slot {slot}, status: {err}")
94
95 ## Set AI sampling rate
96 err = dev.AI_setSamplingRate(slot, sampling_rate, timeout)
97 print(f"AI_setSamplingRate {sampling_rate} in slot {slot}, status: {err}")
98
99 ## Open AI streaming
100 err = dev.AI_openStreaming(slot, timeout)
101 print(f"AI_openStreaming in slot {slot}, status: {err}")
102
103 ## Start AI streaming
104 err = dev.AI_startStreaming(slot, timeout)
105 print(f"AI_startStreaming in slot {slot}, status: {err}")
106
107 data_len = 1
108 while data_len > 0:
109 for slot in slot_list:
110 ## Read data acquisition
111 ai_2Dlist = dev.AI_readStreaming(slot, read_points, read_delay)
112 print(f"Slot{slot}: data len {len(ai_2Dlist)}")
113
114 ## Update data len and counter
115 data_len = len(ai_2Dlist)
116
117 except Exception as err:
118 pywpc.printGenericError(err)
119 except KeyboardInterrupt:
120 print("Press keyboard")
121 finally:
122 for slot in slot_list:
123 ## Close AI streaming
124 err = dev.AI_closeStreaming(slot, timeout)
125 print(f"AI_closeStreaming in slot {slot}, status: {err}")
126
127 ## Close AI
128 err = dev.AI_close(slot, timeout)
129 print(f"AI_close in slot {slot}, status: {err}")
130
131 ## Disconnect device
132 dev.disconnect()
133
134 ## Release device handle
135 dev.close()
136
137
138if __name__ == '__main__':
139 main()