10import isystem.connect
as ic
14def CreateCConnectionConfig():
15 cfg = ic.CConnectionConfig()
26 self.isRunning =
False
27 self.isRecording =
True
28 self.currentMode =
"Mode_Manual"
30 self.inputPeriod = 10000
31 self.sensorVout = 1.65
34def clear():
return os.system(
'cls')
37cmgr = ic.ConnectionMgr()
38cmgr.connect(CreateCConnectionConfig())
47dbgCtrl = ic.CDebugFacade(cmgr)
48traceCtrl = ic.CAnalyzerDocController(cmgr,
49 ic.CAnalyzerDocController.ANALYZER,
53ideCtrl = ic.CIDEController(cmgr)
54wsCtrl = ic.CWorkspaceController(cmgr)
56urll = traceCtrl.getDocumentOptionURL(
'Trigger.Items[0].EnableFNet')
57ideCtrl.setOption(urll,
True)
60fnetCtrl = ic.CFNetCtrl(cmgr)
64dioCtrl = fnetCtrl.DIO(
'ADIO.DIO1')
67optDIOCfg = dioCtrl.cfg()
71optDIOCfg.set_bank(nBank = 0, bOutput =
True, dThreshold = 3.3)
72optDIOCfg.set_bank(nBank = 1, bOutput =
False, dThreshold = 3.3)
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)
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)
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]
86 optDIOCfg.set_channel(nChannel = i, strName =
'-', bShow =
False, bInitialHi =
False)
89dioCtrl.op_qualifier_enable_on_start(
True)
93aoutCtrl = fnetCtrl.AOUT(
'ADIO.AOUT1')
96optAOUTCfg = aoutCtrl.cfg()
99optAOUTCfg.set_channel(nChannel = 0, strName =
'Sensor_Vout', bShow =
True, dInitial = 1.65)
101optAOUTCfg.set_channel(nChannel = 1, strName =
'-', bShow =
False, dInitial = 0)
104aoutCtrl.op_qualifier_enable_on_start(
True)
108 contextCtrl = contextHandler()
116 optDIOOp = dioCtrl.op()
118 optPattern = optDIOOp.opt_pattern(nPattern)
121 vPatternChannels = ic.IntVector([0])
122 optPattern.set_channels(vPatternChannels)
125 optPattern.set_operation(ic.EOperation_CONTINUOUS)
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))))
132 optPattern.set_start(0,
True)
135 optDIOOp.set_record(ic.ERecord_ALL)
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)}")
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: ')
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)
168 optPattern.set_start(0,
True)
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)
181 optPattern.set_start(0,
True)
187 duty = float(input(
'Enter duty ratio (0-1): '))
189 contextCtrl.inputDuty = 0.01
191 contextCtrl.inputDuty = 0.99
194 contextCtrl.inputDuty = duty
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)
201 optPattern.set_start(0,
True)
207 contextCtrl.sensorVout = float(input(
'Enter input voltage (0.0 - 3.3) [V]: '))
208 aoutCtrl.ctrl_set_channel(0, contextCtrl.sensorVout)
228except Exception
as ex:
232input(
'Press Enter to quit...')