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 ddata_recorder_with_daq.py
import isystem.connect as ic
from isystem.connect import IConnectDebug
import sys
if __name__ == '__main__':
winidea_id = ''
cmgr = ic.ConnectionMgr()
cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
debugCtrl = ic.CDebugFacade(cmgr)
debugCtrl.download()
debugCtrl.deleteAll()
debugCtrl.runUntilFunction('main')
debugCtrl.waitUntilStopped()
debugCtrl.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()
# monitor every 100ms, four bytes at address 0x400001a8, memory area 0
daqVariables.append(ic.CDAQConfigItem(4, 0, 0x400001a8, ic.CDAQController.daqSample1s))
# monitor variable main_loop_counter at maximum sampling rate
daqVariables.append(ic.CDAQConfigItem('main_loop_counter'))
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