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