winIDEA SDK
Loading...
Searching...
No Matches
chart_sample.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, 2026
#
# This script opens a window with chart and reads and draws values of target
# variable 'main_loop_counter' in real-time for 5 seconds.
import matplotlib
matplotlib.use('TkAgg')
import sys
import pylab as p
import time
import isystem.connect as ic
from isystem.connect import IConnectDebug as ICDebug
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()
ax = p.subplot(111)
canvas = ax.figure.canvas
if len(sys.argv) < 2:
varName = 'main_loop_counter'
print('No target variable name specified in cmd line, using default: ' + varName)
else:
varName = sys.argv[1]
print('Drawing chart for target variable: ' + varName)
# create the initial line
x = range(0, 500)
lineData = [0]*len(x)
line, = p.plot(x, lineData, animated=True, lw=2)
# define ranges on X and Y axis
p.axis([0, 500, -2000, 2000])
def run(*args):
background = canvas.copy_from_bbox(ax.bbox)
run.flag = True
startTime = time.time()
while run.flag:
# restore the clean slate background
canvas.restore_region(background)
# update the data
del lineData[0]
# make sure real-time access is enabled in winIDEA, see description above.
main_loop_counter = debugCtrl.evaluate(ICDebug.fRealTime, varName)
lineData.append(main_loop_counter.getInt())
line.set_ydata(lineData)
# just draw the animated artist
ax.draw_artist(line)
# just redraw the axes rectangle
canvas.blit(ax.bbox)
if (time.time() - startTime) > 5: # wait for 5 seconds
print('Recording finished!')
run.flag = False
p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
p.grid() # to ensure proper background restore
manager = p.get_current_fig_manager()
manager.window.after(100, run)
p.show()