winIDEA SDK
Loading...
Searching...
No Matches
daq_simple.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
# (c) TASKING Germany GmbH, 2023
#
# This script demonstrates the usage of data acquisition, which
# provides fast periodic access to data on target. Because values are
# buffered on an debugger, this approach provides much smaller
# sampling periods than normal access with read() or evaluate()
# methods.
#
# Two locations are monitored on a running application. The acquired
# data is printed to console.
#
# See also data_recorder_with_daq.py
import isystem.connect as ic
import sys
NM_BYTES = 4
MEM_AREA = 0
HEX_ADDR = 0x400001a8
SAMPLING_RATE_1 = ic.CDAQController.daqSample1s
# DAQ config 2
VAR_NAME = "main_loop_counter"
SAMPLING_RATE_2 = ic.CDAQController.daqSampleMax
if __name__ == '__main__':
winidea_id = ''
cmgr = ic.ConnectionMgr()
cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
debug_facade = ic.CDebugFacade(cmgr)
sess_ctrl: ic.CSessionCtrl = ic.CSessionCtrl(cmgr)
sess_ctrl.begin_program()
debug_facade.deleteAll()
debug_facade.runUntilFunction('main')
debug_facade.waitUntilStopped()
debug_facade.run()
# create a DAQ controller object
daqCtrl = ic.CDAQController(cmgr)
# check if DAQ system is available
daqInfo = daqCtrl.info()
if daqInfo.getMaxItems() == 0:
print('No DAQ items exist!')
sys.exit()
print('MaxItems = ', daqInfo.getMaxItems())
daqVariables = ic.DAQConfigVector()
# DAQ config 1
daqVariables.append(ic.CDAQConfigItem(NM_BYTES, MEM_AREA, HEX_ADDR, SAMPLING_RATE_1))
# DAQ config 2
daqVariables.append(ic.CDAQConfigItem(VAR_NAME, SAMPLING_RATE_2))
daqCtrl.configure(daqVariables)
# note the time of the DAQ system
daqTimeStart = daqCtrl.status().getTime()
# enable DAQ on the entire SoC
daqCtrl.enableGlobal(True)
counter = 0
while True:
daqStatus = daqCtrl.status()
# if any sample is available, display the status and print the samples
if daqStatus.getNumSamplesAvailable() > 0:
print('Max DAQ acquisition time = ', str(daqStatus.getLastLoopTime()))
if daqStatus.getOverflow():
print('SAMPLING OVERFLOW!')
# read available samples into daqSamples
daqSamples = ic.DAQSampleVector()
daqCtrl.read(daqSamples)
print('Number of samples = ', str(daqSamples.size()))
for daqSample in daqSamples:
# print data as a hexadecimal integer. Format time in seconds
print(' index =', str(daqSample.getIndex()),
' data =', hex(daqCtrl.getDataValue(daqSample).getLong()),
' time =', str((daqSample.getTime() - daqTimeStart)))
counter += 1
if counter > 100:
break