winIDEA SDK
fnet_dio.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 DIO controller initialization and usage.
7
8(c) iSYSTEM Labs, 2022
9"""
10import isystem.connect as ic
11
12winidea_id = ''
13
14
15try:
16 # connect to last winIDEA
17 connMgr = ic.ConnectionMgr()
18 connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
19
20 # initialize FNet DIO Controller
21 SessionCtrl = ic.CSessionCtrl(connMgr)
22 FNetCtrl = ic.CFNetCtrl(connMgr)
23 DIOCtrl = FNetCtrl.DIO('ADIO.DIO1')
24
25
26
27 optDIOCfg = DIOCtrl.cfg()
28 optDIOCfg.reset()
29
30 # configure bank 0 as 3.3V inputs
31 optDIOCfg.set_bank(nBank = 0, bOutput = False, dThreshold = 3.3)
32 # configure bank 3 as 3.3V outputs
33 optDIOCfg.set_bank(nBank = 3, bOutput = True, dThreshold = 3.3)
34
35 nMyInputChannel = 0
36 nMyOutputChannel = 25
37 nMyOtherOutputChannel = 27
38 optDIOCfg.set_channel(nChannel = nMyInputChannel, strName = 'MyInputChannel', bShow = True, bInitialHi = False)
39 optDIOCfg.set_channel(nChannel = nMyOtherOutputChannel, strName = 'MyOtherOutputChannel', bShow = True, bInitialHi = False)
40
41
42
43 SessionCtrl.end() #end first for cfg to take effect
44 SessionCtrl.begin_prepare()
45
46
47
48 # use FNetTrigger 5 in the example
49 FTrig = 5
50 FTrigStop = 6
51 nPattern = 3
52
53 optDIOOp = DIOCtrl.op()
54 # qualifier - starts on FTrig, not enabled from start
55 DIOCtrl.op_qualifier_enable(FTrig)
56 DIOCtrl.op_qualifier_enable_on_start(False)
57
58 # which channels to record - ALL, including outputs
59 optDIOOp.set_record(ic.ERecord_ALL)
60
61 # configure comparator 0
62 optComparator = optDIOOp.opt_comparator(0)
63 # set all channels to ignore
64 optComparator.set_channel_ignore_all()
65 # comparator to consider input Channel when state is high
66 optComparator.set_channel_state(nMyInputChannel, bHi = True)
67 # generate this trigger
68 optComparator.set_FTrig(FTrig)
69
70 # configure action 1, when FTrig occurs, set output Channel to high
71 optDIOOp.set_action(nAction = 1, nFTrig = FTrig, nChannel = nMyOutputChannel, bHi = True)
72
73 # configure pattern 3
74 optPattern = optDIOOp.opt_pattern(nPattern)
75 # pattern will use two channels
76 vPatternChannels = ic.IntVector([nMyOutputChannel, nMyOtherOutputChannel])
77 optPattern.set_channels(vPatternChannels)
78 # when started, it will run until explicitly stopped
79 optPattern.set_operation(ic.EOperation_CONTINUOUS)
80 # pattern waveform is 3ms of state MyOutputChannel = 1, MyOtherOutputChannel = 0, then 5ms MyOutputChannel = 0, MyOtherOutputChannel = 1
81 optPattern.set_pattern("10,3ms;01,5ms")
82 # pattern starts on FTrig=5, it's not active from start of session
83 optPattern.set_start(FTrig, False)
84 # pattern stops on FTrigStop
85 optPattern.set_stop(FTrigStop, False)
86
87 # apply new operation settings and restart operation
88 FNetCtrl.op_apply()
89
90
92 ChannelState = DIOCtrl.ctrl_get_channel(nMyInputChannel)
93 DIOCtrl.ctrl_set_channel(nMyOutputChannel, ChannelState)
94
95 # manually start pattern
96 DIOCtrl.ctrl_start_pattern(nPattern)
97 # manually stop pattern
98 DIOCtrl.ctrl_stop_pattern(nPattern)
99except Exception as ex:
100 print(ex)