1
2
3
4
5
6
7
8
9
10import isystem.connect as ic
11import os
12
13
14def CreateCConnectionConfig():
15 cfg = ic.CConnectionConfig()
16
17
18
19
20
21
22 return cfg
23
24class contextHandler:
25 def __init__(self):
26 self.isRunning = False
27 self.isRecording = True
28 self.currentMode = "Mode_Manual"
29 self.inputDuty = 0.5
30 self.inputPeriod = 10000
31 self.sensorVout = 1.65
32
33
34def clear():
35 return os.system('cls')
36
37
38if __name__ == "__main__":
39
40 cmgr = ic.ConnectionMgr()
41 cmgr.connect(CreateCConnectionConfig())
42
43
44
50 dbgCtrl = ic.CDebugFacade(cmgr)
51 traceCtrl = ic.CAnalyzerDocController(cmgr,
52 ic.CAnalyzerDocController.ANALYZER,
53 'ADIO_TEST.trd', 'w')
54
55
56 ideCtrl = ic.CIDEController(cmgr)
57 wsCtrl = ic.CWorkspaceController(cmgr)
58
59 urll = traceCtrl.getDocumentOptionURL('Trigger.Items[0].EnableFNet')
60 ideCtrl.setOption(urll, True)
61
63 fnetCtrl = ic.CFNetCtrl(cmgr)
64
65
66
67 dioCtrl = fnetCtrl.DIO('ADIO.DIO1')
68
69
70 optDIOCfg = dioCtrl.cfg()
71
72
73
74 optDIOCfg.set_bank(nBank = 0, bOutput = True, dThreshold = 3.3)
75 optDIOCfg.set_bank(nBank = 1, bOutput = False, dThreshold = 3.3)
76
77
78 optDIOCfg.set_channel(nChannel = 0, strName = 'PWM_IN_MODE', bShow = True, bInitialHi = False)
79 optDIOCfg.set_channel(nChannel = 8, strName = 'PWM_OUT_BACKLIGHT', bShow = True, bInitialHi = False)
80
81 optDIOCfg.set_channel(nChannel = 16, strName = 'SCLK', bShow = True, bInitialHi = False)
82 optDIOCfg.set_channel(nChannel = 17, strName = 'MISO', bShow = True, bInitialHi = False)
83 optDIOCfg.set_channel(nChannel = 18, strName = 'MOSI', bShow = True, bInitialHi = False)
84 optDIOCfg.set_channel(nChannel = 23, strName = 'nCS', bShow = True, bInitialHi = False)
85
86
87 list = [1,2,3,4,5,6,7,9,10,11,12,13,14,15,19,20,21,22,24,25,26,27,28,29,30,31]
88 for i in list:
89 optDIOCfg.set_channel(nChannel = i, strName = '-', bShow = False, bInitialHi = False)
90
91
92 dioCtrl.op_qualifier_enable_on_start(True)
93
94
96 aoutCtrl = fnetCtrl.AOUT('ADIO.AOUT1')
97
98
99 optAOUTCfg = aoutCtrl.cfg()
100
101
102 optAOUTCfg.set_channel(nChannel = 0, strName = 'Sensor_Vout', bShow = True, dInitial = 1.65)
103
104 optAOUTCfg.set_channel(nChannel = 1, strName = '-', bShow = False, dInitial = 0)
105
106
107 aoutCtrl.op_qualifier_enable_on_start(True)
108
109
110 try:
111 contextCtrl = contextHandler()
112 runScript = True
113
114
115 dbgCtrl.reset()
116
117
118
119 optDIOOp = dioCtrl.op()
120 nPattern = 0
121 optPattern = optDIOOp.opt_pattern(nPattern)
122
123
124 vPatternChannels = ic.IntVector([0])
125 optPattern.set_channels(vPatternChannels)
126
127
128 optPattern.set_operation(ic.EOperation_CONTINUOUS)
129
130
131 optPattern.set_pattern('1,{activeDuty}us;0,{inactiveDuty}us'.format(
132 activeDuty=int(contextCtrl.inputPeriod * contextCtrl.inputDuty),
133 inactiveDuty=int(contextCtrl.inputPeriod * (1 - contextCtrl.inputDuty))))
134
135 optPattern.set_start(0, True)
136
137
138 optDIOOp.set_record(ic.ERecord_ALL)
139
140 fnetCtrl.op_apply()
141
142 while runScript:
143 clear()
144 print(f"Current control mode is: \t {contextCtrl.currentMode}")
145 print(f"Current input signal duty:\t {contextCtrl.inputDuty}")
146 print(f"Current sensor output voltage:\t {aoutCtrl.ctrl_read_channel(0)}")
147
148
149 print(f"Choose an option:")
150 print(f" 1. Set control mode: automatic"
151 "(200Hz, backlight intensity controlled by the sensor)")
152 print(f" 2. Set control mode: manual"
153 "(100Hz, backlight intensity controlled by the input signal)")
154 print(f" 3. Change input signal duty ratio (range 0.01 - 0.99)")
155 print(f" 4. Change sensor output voltage (range 0.0 - 3.3 V)")
156 print(f" 5. Run application and start recording")
157 print(f" 6. Stop application and recording")
158 print(f" 7. End session")
159 choice = input('Choice: ')
160
161
162 if choice == '1':
163 clear()
164 contextCtrl.currentMode = "Mode_Automatic"
165 contextCtrl.inputPeriod = 5000
166 optPattern.set_pattern('1,{activeDuty}us;0,{inactiveDuty}us'.format(
167 activeDuty=int(contextCtrl.inputPeriod * contextCtrl.inputDuty),
168 inactiveDuty=int(contextCtrl.inputPeriod*(1-contextCtrl.inputDuty))))
169 optPattern.set_operation(ic.EOperation_CONTINUOUS)
170
171 optPattern.set_start(0, True)
172 fnetCtrl.op_apply()
173
174
175 elif choice == '2':
176 clear()
177 contextCtrl.currentMode = "Mode_Manual"
178 contextCtrl.inputPeriod = 10000
179 optPattern.set_pattern('1,{activeDuty}us;0,{inactiveDuty}us'.format(
180 activeDuty=int(contextCtrl.inputPeriod * contextCtrl.inputDuty),
181 inactiveDuty=int(contextCtrl.inputPeriod*(1-contextCtrl.inputDuty))))
182 optPattern.set_operation(ic.EOperation_CONTINUOUS)
183
184 optPattern.set_start(0, True)
185 fnetCtrl.op_apply()
186
187
188 elif choice == '3':
189 clear()
190 duty = float(input('Enter duty ratio (0-1): '))
191 if duty == 0:
192 contextCtrl.inputDuty = 0.01
193 elif duty == 1:
194 contextCtrl.inputDuty = 0.99
195
196 else:
197 contextCtrl.inputDuty = duty
198
199 optPattern.set_pattern('1,{activeDuty}us;0,{inactiveDuty}us'.format(
200 activeDuty=int(contextCtrl.inputPeriod * contextCtrl.inputDuty),
201 inactiveDuty=int(contextCtrl.inputPeriod*(1-contextCtrl.inputDuty))))
202 optPattern.set_operation(ic.EOperation_CONTINUOUS)
203
204 optPattern.set_start(0, True)
205 fnetCtrl.op_apply()
206
207
208 elif choice == '4':
209 clear()
210 contextCtrl.sensorVout = float(input('Enter input voltage (0.0 - 3.3) [V]: '))
211 aoutCtrl.ctrl_set_channel(0, contextCtrl.sensorVout)
212
213
214 elif choice == '5':
215 traceCtrl.start()
216 dbgCtrl.run()
217
218 elif choice == '6':
219 traceCtrl.stop()
220 dbgCtrl.stop()
221
222 else:
223 traceCtrl.stop()
224 dbgCtrl.stop()
225 cmgr.disconnect()
226 runScript = False
227
228
229
230
231 except Exception as ex:
232 print(ex)
233
234
235 input('Press Enter to quit...')