import isystem.connect as ic
import os
def CreateCConnectionConfig():
cfg = ic.CConnectionConfig()
return cfg
class contextHandler:
def __init__(self):
self.isRunning = False
self.isRecording = True
self.currentMode = "Mode_Manual"
self.inputDuty = 0.5
self.inputPeriod = 10000
self.sensorVout = 1.65
def clear():
return os.system('cls')
if __name__ == "__main__":
cmgr = ic.ConnectionMgr()
cmgr.connect(CreateCConnectionConfig())
dbgCtrl = ic.CDebugFacade(cmgr)
traceCtrl = ic.CAnalyzerDocController(cmgr,
ic.CAnalyzerDocController.ANALYZER,
'ADIO_TEST.trd', 'w')
ideCtrl = ic.CIDEController(cmgr)
wsCtrl = ic.CWorkspaceController(cmgr)
urll = traceCtrl.getDocumentOptionURL('Trigger.Items[0].EnableFNet')
ideCtrl.setOption(urll, True)
fnetCtrl = ic.CFNetCtrl(cmgr)
dioCtrl = fnetCtrl.DIO('ADIO.DIO1')
optDIOCfg = dioCtrl.cfg()
optDIOCfg.set_bank(nBank = 0, bOutput = True, dThreshold = 3.3)
optDIOCfg.set_bank(nBank = 1, bOutput = False, dThreshold = 3.3)
optDIOCfg.set_channel(nChannel = 0, strName = 'PWM_IN_MODE', bShow = True, bInitialHi = False)
optDIOCfg.set_channel(nChannel = 8, strName = 'PWM_OUT_BACKLIGHT', bShow = True, bInitialHi = False)
optDIOCfg.set_channel(nChannel = 16, strName = 'SCLK', bShow = True, bInitialHi = False)
optDIOCfg.set_channel(nChannel = 17, strName = 'MISO', bShow = True, bInitialHi = False)
optDIOCfg.set_channel(nChannel = 18, strName = 'MOSI', bShow = True, bInitialHi = False)
optDIOCfg.set_channel(nChannel = 23, strName = 'nCS', bShow = True, bInitialHi = False)
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]
for i in list:
optDIOCfg.set_channel(nChannel = i, strName = '-', bShow = False, bInitialHi = False)
dioCtrl.op_qualifier_enable_on_start(True)
aoutCtrl = fnetCtrl.AOUT('ADIO.AOUT1')
optAOUTCfg = aoutCtrl.cfg()
optAOUTCfg.set_channel(nChannel = 0, strName = 'Sensor_Vout', bShow = True, dInitial = 1.65)
optAOUTCfg.set_channel(nChannel = 1, strName = '-', bShow = False, dInitial = 0)
aoutCtrl.op_qualifier_enable_on_start(True)
try:
contextCtrl = contextHandler()
runScript = True
dbgCtrl.reset()
optDIOOp = dioCtrl.op()
nPattern = 0
optPattern = optDIOOp.opt_pattern(nPattern)
vPatternChannels = ic.IntVector([0])
optPattern.set_channels(vPatternChannels)
optPattern.set_operation(ic.EOperation_CONTINUOUS)
optPattern.set_pattern('1,{activeDuty}us;0,{inactiveDuty}us'.format(
activeDuty=int(contextCtrl.inputPeriod * contextCtrl.inputDuty),
inactiveDuty=int(contextCtrl.inputPeriod * (1 - contextCtrl.inputDuty))))
optPattern.set_start(0, True)
optDIOOp.set_record(ic.ERecord_ALL)
fnetCtrl.op_apply()
while runScript:
clear()
print(f"Current control mode is: \t {contextCtrl.currentMode}")
print(f"Current input signal duty:\t {contextCtrl.inputDuty}")
print(f"Current sensor output voltage:\t {aoutCtrl.ctrl_read_channel(0)}")
print(f"Choose an option:")
print(f" 1. Set control mode: automatic"
"(200Hz, backlight intensity controlled by the sensor)")
print(f" 2. Set control mode: manual"
"(100Hz, backlight intensity controlled by the input signal)")
print(f" 3. Change input signal duty ratio (range 0.01 - 0.99)")
print(f" 4. Change sensor output voltage (range 0.0 - 3.3 V)")
print(f" 5. Run application and start recording")
print(f" 6. Stop application and recording")
print(f" 7. End session")
choice = input('Choice: ')
if choice == '1':
clear()
contextCtrl.currentMode = "Mode_Automatic"
contextCtrl.inputPeriod = 5000
optPattern.set_pattern('1,{activeDuty}us;0,{inactiveDuty}us'.format(
activeDuty=int(contextCtrl.inputPeriod * contextCtrl.inputDuty),
inactiveDuty=int(contextCtrl.inputPeriod*(1-contextCtrl.inputDuty))))
optPattern.set_operation(ic.EOperation_CONTINUOUS)
optPattern.set_start(0, True)
fnetCtrl.op_apply()
elif choice == '2':
clear()
contextCtrl.currentMode = "Mode_Manual"
contextCtrl.inputPeriod = 10000
optPattern.set_pattern('1,{activeDuty}us;0,{inactiveDuty}us'.format(
activeDuty=int(contextCtrl.inputPeriod * contextCtrl.inputDuty),
inactiveDuty=int(contextCtrl.inputPeriod*(1-contextCtrl.inputDuty))))
optPattern.set_operation(ic.EOperation_CONTINUOUS)
optPattern.set_start(0, True)
fnetCtrl.op_apply()
elif choice == '3':
clear()
duty = float(input('Enter duty ratio (0-1): '))
if duty == 0:
contextCtrl.inputDuty = 0.01
elif duty == 1:
contextCtrl.inputDuty = 0.99
else:
contextCtrl.inputDuty = duty
optPattern.set_pattern('1,{activeDuty}us;0,{inactiveDuty}us'.format(
activeDuty=int(contextCtrl.inputPeriod * contextCtrl.inputDuty),
inactiveDuty=int(contextCtrl.inputPeriod*(1-contextCtrl.inputDuty))))
optPattern.set_operation(ic.EOperation_CONTINUOUS)
optPattern.set_start(0, True)
fnetCtrl.op_apply()
elif choice == '4':
clear()
contextCtrl.sensorVout = float(input('Enter input voltage (0.0 - 3.3) [V]: '))
aoutCtrl.ctrl_set_channel(0, contextCtrl.sensorVout)
elif choice == '5':
traceCtrl.start()
dbgCtrl.run()
elif choice == '6':
traceCtrl.stop()
dbgCtrl.stop()
else:
traceCtrl.stop()
dbgCtrl.stop()
cmgr.disconnect()
runScript = False
except Exception as ex:
print(ex)
input('Press Enter to quit...')