winIDEA SDK
Loading...
Searching...
No Matches
ADIO_usecases_example.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
#
# This Python example demonstrates the automated usage of ADIO Add-on
# module in different use cases, as described in winIDEA Help:
# Close-up SPI recording, AOUT, AIN, SPI and Pattern Generator,
# Pattern Generator, and HIL Monitor Plugin.
#
# (c) TASKING Germany GmbH, 2023
import isystem.connect as ic
import os
# creates a connection configuration struct which instructs connects to the last used winIDEA
def CreateCConnectionConfig():
cfg = ic.CConnectionConfig()
# cfg.cmdLineParams("/LOG:6")
# cfg.instanceId("sdk_example")
# cfg.udpDiscoveryPort(5345) # see 'isystem.connect' options dialog for range
# cfg.useIPCDiscovery(True)
# cfg.visibility(ic.IConnect.lfShowHidden) # use winIDEA in headless mode
# cfg.waitTime(ic.IConnect.lfWait100ms)
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__":
# create a connection manager and connect to most recently used winIDEA workspace
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') # in Analayzer - Profiler enable Fnet
ideCtrl.setOption(urll, True)
fnetCtrl = ic.CFNetCtrl(cmgr)
# initialize FNet DIO Controller
dioCtrl = fnetCtrl.DIO('ADIO.DIO1')
# get DIO configuration controller
optDIOCfg = dioCtrl.cfg()
# configure DIO channels
# set bank 0 as 3.3V outputs, set bank 1 as 3.3V inputs.
optDIOCfg.set_bank(nBank = 0, bOutput = True, dThreshold = 3.3) #output
optDIOCfg.set_bank(nBank = 1, bOutput = False, dThreshold = 3.3) #input
# set Channel visibility and names
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)
# hide unused channels
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)
# enable DIO recording in Analyzer
dioCtrl.op_qualifier_enable_on_start(True)
aoutCtrl = fnetCtrl.AOUT('ADIO.AOUT1')
# get AOUT configuration controller
optAOUTCfg = aoutCtrl.cfg()
# set channel 0 initial state, set show flag
optAOUTCfg.set_channel(nChannel = 0, strName = 'Sensor_Vout', bShow = True, dInitial = 1.65)
# hide unused channel
optAOUTCfg.set_channel(nChannel = 1, strName = '-', bShow = False, dInitial = 0)
# enable recording on start
aoutCtrl.op_qualifier_enable_on_start(True)
# Example:
try:
contextCtrl = contextHandler()
runScript = True
# dbgCtrl.download() # downloads application to target, not needed if application already loaded
# loaderCtrl.downloadWithoutCode()
dbgCtrl.reset()
#DIO****************************************************************
# configure pattern slot
optDIOOp = dioCtrl.op()
nPattern = 0
optPattern = optDIOOp.opt_pattern(nPattern)
# pattern will use one channel
vPatternChannels = ic.IntVector([0])
optPattern.set_channels(vPatternChannels)
# when started, it will run until explicitly stopped
optPattern.set_operation(ic.EOperation_CONTINUOUS)
# pattern waveform according to default values
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)
# Record Inputs and outputs
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...')