winIDEA SDK
daq_simple.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5"""
6This script demonstrates the usage of data acquisition, which
7provides fast periodic access to data on target. Because values are
8buffered on an emulator, this approach provides much smaller
9sampling periods than normal access with read() or evaluate()
10methods.
11
12Two locations are monitored on a running application. The acquired
13data is printed to console.
14
15See also dataRecorderWithDAQ.py
16"""
17
18
19import isystem.connect as ic
20from isystem.connect import IConnectDebug
21import sys
22
23winidea_id = ''
24
25
26cmgr = ic.ConnectionMgr()
27cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
28
29debugCtrl = ic.CDebugFacade(cmgr)
30debugCtrl.download()
31debugCtrl.deleteAll()
32debugCtrl.runUntilFunction('main')
33debugCtrl.waitUntilStopped()
34debugCtrl.run()
35
36# create a DAQ controller object
37daqCtrl = ic.CDAQController(cmgr)
38
39# check if DAQ system is available
40daqInfo = daqCtrl.info()
41
42if daqInfo.getMaxItems() == 0:
43 print('No DAQ items exist!')
44 sys.exit()
45
46print('MaxItems = ', daqInfo.getMaxItems())
47
48daqVariables = ic.DAQConfigVector()
49
50# monitor every 100ms, four bytes at address 0x400001a8, memory area 0
51daqVariables.append(ic.CDAQConfigItem(4, 0, 0x400001a8, ic.CDAQController.daqSample1s))
52
53# monitor variable main_loop_counter at maximum sampling rate
54daqVariables.append(ic.CDAQConfigItem('main_loop_counter'))
55
56daqCtrl.configure(daqVariables)
57
58# note the time of the DAQ system
59daqTimeStart = daqCtrl.status().getTime()
60
61# enable DAQ on the entire SoC
62daqCtrl.enableGlobal(True)
63
64counter = 0
65while True:
66 daqStatus = daqCtrl.status()
67 # if any sample is available, display the status and print the samples
68 if daqStatus.getNumSamplesAvailable() > 0:
69 print('Max DAQ acquisition time = ', str(daqStatus.getLastLoopTime()))
70 if daqStatus.getOverflow():
71 print('SAMPLING OVERFLOW!')
72
73 # read available samples into daqSamples
74 daqSamples = ic.DAQSampleVector()
75 daqCtrl.read(daqSamples)
76
77 print('Number of samples = ', str(daqSamples.size()))
78 for daqSample in daqSamples:
79 # print data as a hexadecimal integer. Format time in seconds
80 print(' index =', str(daqSample.getIndex()),
81 ' data =', hex(daqCtrl.getDataValue(daqSample).getLong()),
82 ' time =', str((daqSample.getTime() - daqTimeStart)))
83
84 counter += 1
85
86 if counter > 100:
87 break