6This script plots several variables in one chart. The chart is
7automatically scaled so that all the data is visible.
8To use this script as a module, import it to your scripts and
9call function startRecorder() with the list of variable you want to
12This script requires additional python modules: matplotlib ver 1.1,
17import isystem.connect
as ic
20import matplotlib.pyplot
as plt
21import matplotlib.animation
as animation
29 This function initializes the target. Customize it according to
33 debugCtrl = ic.CDebugFacade(cmgr)
36 debugCtrl.runUntilFunction("main")
37 debugCtrl.waitUntilStopped()
43def _read_data(watches):
45 This function reads variables from the target. It
is called
46 periodically
from updateChart()
52 for expression
in watches:
54 value = g_debugCtrl.evaluate(ic.IConnectDebug.fRealTime, expression)
58 row.append(value.getInt())
60 current_time = time.time() - g_startTime
61 return current_time, row
64def updateChart(num, watches, xRange, isScale):
66 This function is periodically called by the animation loop.
71 t, y = _read_data(watches)
74 xdata = np.hstack((xdata, t))
75 ydata = np.row_stack((ydata, y))
78 xmin, xmax = ax.get_xlim()
79 ymin, ymax = ax.get_ylim()
84 ax.set_xlim(xmin, 2*xmax)
87 ax.set_xlim(t - xRange, t)
90 delta_y_max = np.max(ydata)
91 delta_y_min = np.min(ydata)
93 delta_y = (delta_y_max - delta_y_min) / 10
94 if delta_y_max > ymax:
95 ax.set_ylim(ymin, delta_y_max + delta_y)
98 if delta_y_max < ymin:
99 ax.set_ylim(delta_y_min - delta_y, ymax)
103 ax.figure.canvas.draw()
106 for i
in range(len(g_lines)):
107 g_lines[i].set_data(xdata, ydata[:, i])
112def startRecorder(isInitTarget, watches, samplingInterval, xRange, isScale):
114 This is the main function of this module.
117 isInitTarget -
if true, function initTarget()
is called, otherwise
118 the target must be initialized
and running
120 watches - list of variables to plot,
for example [
'g_int',
'g_char']
122 samplingInterval - time
in milliseconds between reading of samples
124 xRange - initiali range on x-axis
126 isScale
if true, data
is scale along x axis so that everything
is visible,
127 otherwise x-axis
is shifted.
129 global g_lines, ax, xdata, ydata, \
130 g_debugCtrl, g_startTime
132 cmgr = ic.ConnectionMgr()
133 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
136 g_debugCtrl = initTarget(cmgr)
138 g_debugCtrl = ic.CDebugFacade(cmgr)
140 g_startTime = time.time()
142 ydata = np.zeros((0, len(watches)))
144 figure = plt.figure()
145 ax = figure.add_subplot(111)
147 g_lines = ax.plot([0], [[0]*len(watches)], lw=1)
149 ax.set_xlim(0, xRange)
152 ani = animation.FuncAnimation(figure, updateChart, 40, blit=
False,
153 interval=samplingInterval,
154 fargs=[watches, xRange, isScale])
158if __name__ ==
'__main__':
159 startRecorder(
True, [
'g_complexStruct.i_cplx',
'g_char'], 10, 10,
False)