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