winIDEA SDK
Loading...
Searching...
No Matches
daq_simple.py
1# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
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
19
20if __name__ == '__main__':
21 winidea_id = ''
22
23
24 cmgr = ic.ConnectionMgr()
25 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
26
27 debugCtrl = ic.CDebugFacade(cmgr)
28 debugCtrl.download()
29 debugCtrl.deleteAll()
30 debugCtrl.runUntilFunction('main')
31 debugCtrl.waitUntilStopped()
32 debugCtrl.run()
33
34 # create a DAQ controller object
35 daqCtrl = ic.CDAQController(cmgr)
36
37 # check if DAQ system is available
38 daqInfo = daqCtrl.info()
39
40 if daqInfo.getMaxItems() == 0:
41 print('No DAQ items exist!')
42 sys.exit()
43
44 print('MaxItems = ', daqInfo.getMaxItems())
45
46 daqVariables = ic.DAQConfigVector()
47
48 # monitor every 100ms, four bytes at address 0x400001a8, memory area 0
49 daqVariables.append(ic.CDAQConfigItem(4, 0, 0x400001a8, ic.CDAQController.daqSample1s))
50
51 # monitor variable main_loop_counter at maximum sampling rate
52 daqVariables.append(ic.CDAQConfigItem('main_loop_counter'))
53
54 daqCtrl.configure(daqVariables)
55
56 # note the time of the DAQ system
57 daqTimeStart = daqCtrl.status().getTime()
58
59 # enable DAQ on the entire SoC
60 daqCtrl.enableGlobal(True)
61
62 counter = 0
63 while True:
64 daqStatus = daqCtrl.status()
65 # if any sample is available, display the status and print the samples
66 if daqStatus.getNumSamplesAvailable() > 0:
67 print('Max DAQ acquisition time = ', str(daqStatus.getLastLoopTime()))
68 if daqStatus.getOverflow():
69 print('SAMPLING OVERFLOW!')
70
71 # read available samples into daqSamples
72 daqSamples = ic.DAQSampleVector()
73 daqCtrl.read(daqSamples)
74
75 print('Number of samples = ', str(daqSamples.size()))
76 for daqSample in daqSamples:
77 # print data as a hexadecimal integer. Format time in seconds
78 print(' index =', str(daqSample.getIndex()),
79 ' data =', hex(daqCtrl.getDataValue(daqSample).getLong()),
80 ' time =', str((daqSample.getTime() - daqTimeStart)))
81
82 counter += 1
83
84 if counter > 100:
85 break