"""
This example shows basic FNet DIO controller initialization and usage.
(c) iSYSTEM Labs, 2022
"""
import isystem.connect as ic
winidea_id = ''
try:
connMgr = ic.ConnectionMgr()
connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
SessionCtrl = ic.CSessionCtrl(connMgr)
FNetCtrl = ic.CFNetCtrl(connMgr)
DIOCtrl = FNetCtrl.DIO('ADIO.DIO1')
optDIOCfg = DIOCtrl.cfg()
optDIOCfg.reset()
optDIOCfg.set_bank(nBank = 0, bOutput = False, dThreshold = 3.3)
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()
SessionCtrl.begin_prepare()
FTrig = 5
FTrigStop = 6
nPattern = 3
optDIOOp = DIOCtrl.op()
DIOCtrl.op_qualifier_enable(FTrig)
DIOCtrl.op_qualifier_enable_on_start(False)
optDIOOp.set_record(ic.ERecord_ALL)
optComparator = optDIOOp.opt_comparator(0)
optComparator.set_channel_ignore_all()
optComparator.set_channel_state(nMyInputChannel, bHi = True)
optComparator.set_FTrig(FTrig)
optDIOOp.set_action(nAction = 1, nFTrig = FTrig, nChannel = nMyOutputChannel, bHi = True)
optPattern = optDIOOp.opt_pattern(nPattern)
vPatternChannels = ic.IntVector([nMyOutputChannel, nMyOtherOutputChannel])
optPattern.set_channels(vPatternChannels)
optPattern.set_operation(ic.EOperation_CONTINUOUS)
optPattern.set_pattern("10,3ms;01,5ms")
optPattern.set_start(FTrig, False)
optPattern.set_stop(FTrigStop, False)
FNetCtrl.op_apply()
ChannelState = DIOCtrl.ctrl_get_channel(nMyInputChannel)
DIOCtrl.ctrl_set_channel(nMyOutputChannel, ChannelState)
DIOCtrl.ctrl_start_pattern(nPattern)
DIOCtrl.ctrl_stop_pattern(nPattern)
except Exception as ex:
print(ex)