winIDEA SDK
Loading...
Searching...
No Matches
fnet_dio.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
#
# (c) TASKING Germany GmbH, 2023
"""
This example shows basic FNet DIO controller initialization and usage.
(c) iSYSTEM Labs, 2022
"""
import isystem.connect as ic
winidea_id = ''
try:
# connect to last winIDEA
connMgr = ic.ConnectionMgr()
connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
# initialize FNet DIO Controller
SessionCtrl = ic.CSessionCtrl(connMgr)
FNetCtrl = ic.CFNetCtrl(connMgr)
DIOCtrl = FNetCtrl.DIO('ADIO.DIO1')
optDIOCfg = DIOCtrl.cfg()
optDIOCfg.reset()
# configure bank 0 as 3.3V inputs
optDIOCfg.set_bank(nBank = 0, bOutput = False, dThreshold = 3.3)
# configure bank 3 as 3.3V outputs
optDIOCfg.set_bank(nBank = 3, bOutput = True, dThreshold = 3.3)
nMyInputChannel = 0
nMyOutputChannel = 25
nMyOtherOutputChannel = 27
optDIOCfg.set_channel(nChannel = nMyInputChannel, strName = 'MyInputChannel', bShow = True, bInitialHi = False)
optDIOCfg.set_channel(nChannel = nMyOtherOutputChannel, strName = 'MyOtherOutputChannel', bShow = True, bInitialHi = False)
SessionCtrl.end() #end first for cfg to take effect
SessionCtrl.begin_prepare()
# use FNetTrigger 5 in the example
FTrig = 5
FTrigStop = 6
nPattern = 3
optDIOOp = DIOCtrl.op()
# qualifier - starts on FTrig, not enabled from start
DIOCtrl.op_qualifier_enable(FTrig)
DIOCtrl.op_qualifier_enable_on_start(False)
# which channels to record - ALL, including outputs
optDIOOp.set_record(ic.ERecord_ALL)
# configure comparator 0
optComparator = optDIOOp.opt_comparator(0)
# set all channels to ignore
optComparator.set_channel_ignore_all()
# comparator to consider input Channel when state is high
optComparator.set_channel_state(nMyInputChannel, bHi = True)
# generate this trigger
optComparator.set_FTrig(FTrig)
# configure action 1, when FTrig occurs, set output Channel to high
optDIOOp.set_action(nAction = 1, nFTrig = FTrig, nChannel = nMyOutputChannel, bHi = True)
# configure pattern 3
optPattern = optDIOOp.opt_pattern(nPattern)
# pattern will use two channels
vPatternChannels = ic.IntVector([nMyOutputChannel, nMyOtherOutputChannel])
optPattern.set_channels(vPatternChannels)
# when started, it will run until explicitly stopped
optPattern.set_operation(ic.EOperation_CONTINUOUS)
# pattern waveform is 3ms of state MyOutputChannel = 1, MyOtherOutputChannel = 0, then 5ms MyOutputChannel = 0, MyOtherOutputChannel = 1
optPattern.set_pattern("10,3ms;01,5ms")
# pattern starts on FTrig=5, it's not active from start of session
optPattern.set_start(FTrig, False)
# pattern stops on FTrigStop
optPattern.set_stop(FTrigStop, False)
# apply new operation settings and restart operation
FNetCtrl.op_apply()
ChannelState = DIOCtrl.ctrl_get_channel(nMyInputChannel)
DIOCtrl.ctrl_set_channel(nMyOutputChannel, ChannelState)
# manually start pattern
DIOCtrl.ctrl_start_pattern(nPattern)
# manually stop pattern
DIOCtrl.ctrl_stop_pattern(nPattern)
except Exception as ex:
print(ex)