winIDEA SDK
fnet_mdio.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5"""
6This example shows basic FNet mDIO controller initialization and usage.
7
8(c) iSYSTEM Labs, 2023
9"""
10import isystem.connect as ic
11
12# connect to last winIDEA
13
14winidea_id = ''
15
16
17connMgr = ic.ConnectionMgr()
18connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
19
20sessionCtrl = ic.CSessionCtrl(connMgr)
21
22# initialize FNet DIO Controller
23FNetCtrl = ic.CFNetCtrl(connMgr)
24mDIOCtrl = FNetCtrl.mDIO('ADIO.DIO1')
25
26# configuration
27Cfg = mDIOCtrl.cfg()
28Cfg.set_voltage(dVoltage=3.3)
29Cfg.set_channel_out(nChannel=0, strName='mych0', bShow=True, bInitialHi=True)
30Cfg.set_channel_in (nChannel=1, strName='mych1', bShow=True)
31
32print(f"channel 0 name is: {Cfg.get_channel_name(nChannel=0)}")
33
34# apply configuration
35sessionCtrl.begin_prepare()
36
37# operation
38mDIOCtrl.op_set_qualifier(bEnableFromStart = False, nFTrigEnable=2, nFTrigDisable=3)
39Op = mDIOCtrl.op()
40Op.set_record(ic.ERecord_ALL) #TODO define enum
41
42# comparator index 1
43OpCh = Op.opt_comparator(nChannel = 0)
44# set mDIO pin states
45OpCh.set_FTrig(nFTrig=5)
46OpCh.set_channel_state(nChannel = 0, bHi = False)
47OpCh.set_channel_ignore(nChannel = 1)
48
49# test action on mDIO pins on trigger event
50Op.set_action(nAction = 0, nFTrig = 5, nChannel = 0, bHi = False)
51
52# pattern config
53OpPat = Op.opt_pattern(nPattern = 0)
54OpPat.set_channels(vChannels = {0,2,1})
55OpPat.set_action(nFTrigStart = 1, bStartActive = False, nFTrigStop = 2, bStopImmediately = True)
56OpPat.set_continuous(bContinuous = False)
57OpPat.set_pattern('001,140; xx0,10; 1xx,50ms; 111,100us')
58
59# apply modified Op settings - takes effect at this call
60FNetCtrl.applyOperation()
61
62# control
63mDIOCtrl.ctrl_set_channel(nChannel = 0, bHi = True)
64bHi = mDIOCtrl.ctrl_get_channel(nChannel = 0)
65
66# pattern control not implemented yet
67# mDIOCtrl.ctrl_start_pattern(nPattern = 0)
68# mDIOCtrl.ctrl_stop_pattern(nPattern = 0, bStopImmediately = True)