winIDEA SDK
ADIO_usecases_example.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# This Python example demonstrates the automated usage of ADIO Add-on
4# module in different use cases, as described in winIDEA Help:
5# Close-up SPI recording, AOUT, AIN, SPI and Pattern Generator,
6# Pattern Generator, and HIL Monitor Plugin.
7#
8# (c) TASKING Germany GmbH, 2023
9
10import isystem.connect as ic
11import os
12
13# creates a connection configuration struct which instructs connects to the last used winIDEA
14def CreateCConnectionConfig():
15 cfg = ic.CConnectionConfig()
16 # cfg.cmdLineParams("/LOG:6")
17 # cfg.instanceId("sdk_example")
18 # cfg.udpDiscoveryPort(5345) # see 'isystem.connect' options dialog for range
19 # cfg.useIPCDiscovery(True)
20 # cfg.visibility(ic.IConnect.lfShowHidden) # use winIDEA in headless mode
21 # cfg.waitTime(ic.IConnect.lfWait100ms)
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(): return os.system('cls')
35
36# create a connection manager and connect to most recently used winIDEA workspace
37cmgr = ic.ConnectionMgr()
38cmgr.connect(CreateCConnectionConfig())
39
40
41
47dbgCtrl = ic.CDebugFacade(cmgr)
48traceCtrl = ic.CAnalyzerDocController(cmgr,
49 ic.CAnalyzerDocController.ANALYZER,
50 'ADIO_TEST.trd', 'w')
51
52
53ideCtrl = ic.CIDEController(cmgr)
54wsCtrl = ic.CWorkspaceController(cmgr)
55
56urll = traceCtrl.getDocumentOptionURL('Trigger.Items[0].EnableFNet') # in Analayzer - Profiler enable Fnet
57ideCtrl.setOption(urll, True)
58
60fnetCtrl = ic.CFNetCtrl(cmgr)
61
62
63# initialize FNet DIO Controller
64dioCtrl = fnetCtrl.DIO('ADIO.DIO1')
65
66# get DIO configuration controller
67optDIOCfg = dioCtrl.cfg()
68
69# configure DIO channels
70# set bank 0 as 3.3V outputs, set bank 1 as 3.3V inputs.
71optDIOCfg.set_bank(nBank = 0, bOutput = True, dThreshold = 3.3) #output
72optDIOCfg.set_bank(nBank = 1, bOutput = False, dThreshold = 3.3) #input
73
74# set Channel visibility and names
75optDIOCfg.set_channel(nChannel = 0, strName = 'PWM_IN_MODE', bShow = True, bInitialHi = False)
76optDIOCfg.set_channel(nChannel = 8, strName = 'PWM_OUT_BACKLIGHT', bShow = True, bInitialHi = False)
77
78optDIOCfg.set_channel(nChannel = 16, strName = 'SCLK', bShow = True, bInitialHi = False)
79optDIOCfg.set_channel(nChannel = 17, strName = 'MISO', bShow = True, bInitialHi = False)
80optDIOCfg.set_channel(nChannel = 18, strName = 'MOSI', bShow = True, bInitialHi = False)
81optDIOCfg.set_channel(nChannel = 23, strName = 'nCS', bShow = True, bInitialHi = False)
82
83# hide unused channels
84list = [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]
85for i in list:
86 optDIOCfg.set_channel(nChannel = i, strName = '-', bShow = False, bInitialHi = False)
87
88# enable DIO recording in Analyzer
89dioCtrl.op_qualifier_enable_on_start(True)
90
91
93aoutCtrl = fnetCtrl.AOUT('ADIO.AOUT1')
94
95# get AOUT configuration controller
96optAOUTCfg = aoutCtrl.cfg()
97
98# set channel 0 initial state, set show flag
99optAOUTCfg.set_channel(nChannel = 0, strName = 'Sensor_Vout', bShow = True, dInitial = 1.65)
100# hide unused channel
101optAOUTCfg.set_channel(nChannel = 1, strName = '-', bShow = False, dInitial = 0)
102
103# enable recording on start
104aoutCtrl.op_qualifier_enable_on_start(True)
105
106# Example:
107try:
108 contextCtrl = contextHandler()
109 runScript = True
110 # dbgCtrl.download() # downloads application to target, not needed if application already loaded
111 # loaderCtrl.downloadWithoutCode()
112 dbgCtrl.reset()
113
114 #DIO****************************************************************
115 # configure pattern slot
116 optDIOOp = dioCtrl.op()
117 nPattern = 0
118 optPattern = optDIOOp.opt_pattern(nPattern)
119
120 # pattern will use one channel
121 vPatternChannels = ic.IntVector([0])
122 optPattern.set_channels(vPatternChannels)
123
124 # when started, it will run until explicitly stopped
125 optPattern.set_operation(ic.EOperation_CONTINUOUS)
126
127 # pattern waveform according to default values
128 optPattern.set_pattern('1,{activeDuty}us;0,{inactiveDuty}us'.format(
129 activeDuty=int(contextCtrl.inputPeriod * contextCtrl.inputDuty),
130 inactiveDuty=int(contextCtrl.inputPeriod * (1 - contextCtrl.inputDuty))))
131
132 optPattern.set_start(0, True)
133
134 # Record Inputs and outputs
135 optDIOOp.set_record(ic.ERecord_ALL)
136
137 fnetCtrl.op_apply()
138
139 while runScript:
140 clear()
141 print(f"Current control mode is: \t {contextCtrl.currentMode}")
142 print(f"Current input signal duty:\t {contextCtrl.inputDuty}")
143 print(f"Current sensor output voltage:\t {aoutCtrl.ctrl_read_channel(0)}")
144
145
146 print(f"Choose an option:")
147 print(f" 1. Set control mode: automatic"
148 "(200Hz, backlight intensity controlled by the sensor)")
149 print(f" 2. Set control mode: manual"
150 "(100Hz, backlight intensity controlled by the input signal)")
151 print(f" 3. Change input signal duty ratio (range 0.01 - 0.99)")
152 print(f" 4. Change sensor output voltage (range 0.0 - 3.3 V)")
153 print(f" 5. Run application and start recording")
154 print(f" 6. Stop application and recording")
155 print(f" 7. End session")
156 choice = input('Choice: ')
157
158
159 if choice == '1':
160 clear()
161 contextCtrl.currentMode = "Mode_Automatic"
162 contextCtrl.inputPeriod = 5000
163 optPattern.set_pattern('1,{activeDuty}us;0,{inactiveDuty}us'.format(
164 activeDuty=int(contextCtrl.inputPeriod * contextCtrl.inputDuty),
165 inactiveDuty=int(contextCtrl.inputPeriod*(1-contextCtrl.inputDuty))))
166 optPattern.set_operation(ic.EOperation_CONTINUOUS)
167
168 optPattern.set_start(0, True)
169 fnetCtrl.op_apply()
170
171
172 elif choice == '2':
173 clear()
174 contextCtrl.currentMode = "Mode_Manual"
175 contextCtrl.inputPeriod = 10000
176 optPattern.set_pattern('1,{activeDuty}us;0,{inactiveDuty}us'.format(
177 activeDuty=int(contextCtrl.inputPeriod * contextCtrl.inputDuty),
178 inactiveDuty=int(contextCtrl.inputPeriod*(1-contextCtrl.inputDuty))))
179 optPattern.set_operation(ic.EOperation_CONTINUOUS)
180
181 optPattern.set_start(0, True)
182 fnetCtrl.op_apply()
183
184
185 elif choice == '3':
186 clear()
187 duty = float(input('Enter duty ratio (0-1): '))
188 if duty == 0:
189 contextCtrl.inputDuty = 0.01
190 elif duty == 1:
191 contextCtrl.inputDuty = 0.99
192
193 else:
194 contextCtrl.inputDuty = duty
195
196 optPattern.set_pattern('1,{activeDuty}us;0,{inactiveDuty}us'.format(
197 activeDuty=int(contextCtrl.inputPeriod * contextCtrl.inputDuty),
198 inactiveDuty=int(contextCtrl.inputPeriod*(1-contextCtrl.inputDuty))))
199 optPattern.set_operation(ic.EOperation_CONTINUOUS)
200
201 optPattern.set_start(0, True)
202 fnetCtrl.op_apply()
203
204
205 elif choice == '4':
206 clear()
207 contextCtrl.sensorVout = float(input('Enter input voltage (0.0 - 3.3) [V]: '))
208 aoutCtrl.ctrl_set_channel(0, contextCtrl.sensorVout)
209
210
211 elif choice == '5':
212 traceCtrl.start()
213 dbgCtrl.run()
214
215 elif choice == '6':
216 traceCtrl.stop()
217 dbgCtrl.stop()
218
219 else:
220 traceCtrl.stop()
221 dbgCtrl.stop()
222 cmgr.disconnect()
223 runScript = False
224
225
226
227
228except Exception as ex:
229 print(ex)
230
231
232input('Press Enter to quit...')