"""
This example shows FNet Counter 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)
CounterCtrl = FNetCtrl.counter('Root.COUNTER1')
SessionCtrl.end()
SessionCtrl.begin_prepare()
FTrigQ = 5
FTrigGen = 6
optCounterOp = CounterCtrl.op()
CounterCtrl.op_qualifier_enable(FTrigQ)
CounterCtrl.op_qualifier_enable_on_start(False)
optChannel = optCounterOp.opt_channel(nChannel = 1)
optChannel.set_count_on(bCount = True, nPeriod_us = 10, nFEvent = 4)
optChannel.set_on_increment(nFTrig = 0)
optChannel.set_active(bStart = True, nFTrigRestart = 5, nFTrigSuspend = 6, nFTrigResume = 7)
optChannel.set_limit(bLimit = True, nLimit = 1000, nFTrig = 8, bRestart = False)
optChannel.set_record(bOnChange = True)
FNetCtrl.op_apply()
nCount = CounterCtrl.ctrl_get_FTrig_count(FTrigQ)
CounterCtrl.ctrl_reset_FTrig_count(nFTrig = 1)
CounterCtrl.ctrl_reset (nChannel = 1)
CounterCtrl.ctrl_suspend(nChannel = 1)
CounterCtrl.ctrl_resume (nChannel = 1)
Status = CounterCtrl.ctrl_get_status(nChannel = 1)
print(f"count: {Status.m_nCount}, active: {Status.m_bActive}")
except Exception as ex:
print(ex)