winIDEA SDK
chart_sample.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2# (c) TASKING Germany GmbH, 2023
3#
4# This script opens a window with chart and reads and draws values of target
5# variable 'iCounter' in real-time for 5 seconds.
6# Real-time access must be enabled in winIDEA:
7# Debug | Debug Options | Memory Access | check 'Allow real-time ...',
8# uncheck 'Allow monitor ...'
9# Debug | Debug Options | Update | check 'Update when running', in
10# group 'Update Target' check only 'Watches'
11#
12# This script requires 'matplotlib' to be installed.
13
14
15import matplotlib
16matplotlib.use('TkAgg')
17
18import sys
19import pylab as p
20import time
21
22import isystem.connect as ic
23from isystem.connect import IConnectDebug as ICDebug
24
25winidea_id = ''
26
27cmgr = ic.ConnectionMgr()
28cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
29
30debugCtrl = ic.CDebugFacade(cmgr)
31debugCtrl.download()
32debugCtrl.deleteAll()
33debugCtrl.runUntilFunction('main')
34debugCtrl.waitUntilStopped()
35debugCtrl.run()
36
37
38ax = p.subplot(111)
39canvas = ax.figure.canvas
40
41if len(sys.argv) < 2:
42 varName = 'main_loop_counter'
43 print('No target variable name specified in cmd line, using default: ' + varName)
44else:
45 varName = sys.argv[1]
46 print('Drawing chart for target variable: ' + varName)
47
48# create the initial line
49x = range(0, 500)
50lineData = [0]*len(x)
51line, = p.plot(x, lineData, animated=True, lw=2)
52
53# define ranges on X and Y axis
54p.axis([0, 500, -2000, 2000])
55
56
57def run(*args):
58 background = canvas.copy_from_bbox(ax.bbox)
59 run.flag = True
60 startTime = time.time()
61
62 while run.flag:
63 # restore the clean slate background
64 canvas.restore_region(background)
65
66 # update the data
67 del lineData[0]
68 # make sure real-time access is enabled in winIDEA, see description above.
69 main_loop_counter = debugCtrl.evaluate(ICDebug.fRealTime, varName)
70 lineData.append(main_loop_counter.getInt())
71 line.set_ydata(lineData)
72
73 # just draw the animated artist
74 ax.draw_artist(line)
75 # just redraw the axes rectangle
76 canvas.blit(ax.bbox)
77
78 if (time.time() - startTime) > 5: # wait for 5 seconds
79 print('Recording finished!')
80 run.flag = False
81
82
83p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
84p.grid() # to ensure proper background restore
85manager = p.get_current_fig_manager()
86manager.window.after(100, run)
87
88p.show()