winIDEA SDK
fnet_ain.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 AIN controller initialization and usage.
7"""
8
9import isystem.connect as ic
10
11winidea_id = ''
12
13
14try:
15 # connect to last winIDEA
16 connMgr = ic.ConnectionMgr()
17 connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
18
19 # initialize FNet AIN Controller
20 SessionCtrl = ic.CSessionCtrl(connMgr)
21 FNetCtrl = ic.CFNetCtrl(connMgr)
22 AINCtrl = FNetCtrl.AIN('ADIO.AIN1')
23
24
25
26 optAINCfg = AINCtrl.cfg()
27 optAINCfg.reset()
28
29 nMyChannel = 0
30 # configure channel in one call
31 optAINCfg.set_channel(nChannel = nMyChannel, strName = 'MyAINChannel', bShow = True, dMultiply = 2.0)
32 # configure channel individually (JU) delay impl to later time
33# optChannelCfg = optAINCfg.opt_channel(nMyChannel)
34# optChannelCfg.set_name('MyAINChannel')
35# optChannelCfg.set_show(True)
36# optChannelCfg.set_multiply(3.14)
37
38 # set averager, if the given value is not directly available, winIDEA will use the next bigger one
39 # if value==0, averager is disabled <= AlexB modify also Data.FNet.FNode[0].Cfg.AIN[0].Cfg.UseAverager accodingly
40 optAINCfg.set_averager(8)
41
42 # don't use power measurement
43 optAINCfg.power_measurement_disable()
44 if False: # here's how to set it, 1 Ohm shunt
45 optAINCfg.power_measurement_enable(1.0)
46
47
48
49 # SessionCtrl.end() #end first for cfg to take effect
50 SessionCtrl.begin_prepare()
51
52
53
54 # use FNetTrigger 5 in the example
55 FTrigQ = 5
56 FTrigGen = 6
57
58 optAINOp = AINCtrl.op()
59 # qualifier - starts on FTrig, not enabled from start
60 AINCtrl.op_qualifier_enable(FTrigQ)
61 AINCtrl.op_qualifier_enable_on_start(False)
62
63 # qualifier - sampling interval every 10us
64 optAINOp.set_sampling_interval(0.00001)
65
66 # configure channel
67 optChannel = optAINOp.opt_channel(nMyChannel)
68 optChannel.set_record(True)
69 optChannel.set_comparator(nComparator = 0, nFTrig = FTrigGen, bHigherThan = False, dVoltage = 3.0)
70
71 # apply new operation settings and restart operation
72 FNetCtrl.op_apply()
73
74
76 voltage = AINCtrl.ctrl_get_channel(nMyChannel)
77except Exception as ex:
78 print(ex)