winIDEA SDK
array_chart.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 plots values of target
7arrays given as command line args.
8
9This script requires 'matplotlib' to be installed.
10"""
11
12import matplotlib
13import sys
14import pylab as pl
15import time
16import argparse
17import isystem.connect as ic
18
19
20winidea_id = ''
21
22matplotlib.use('TkAgg')
23
24
25def _initTarget():
26 cmgr = ic.ConnectionMgr()
27 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
28
29 debugCtrl = ic.CDebugFacade(cmgr)
30 debugCtrl.download()
31 debugCtrl.deleteAll()
32 debugCtrl.runUntilFunction('main')
33 debugCtrl.waitUntilStopped()
34 dataCtrl2 = ic.CDataController2(cmgr)
35
36 return debugCtrl, dataCtrl2
37
38
39def getDataFromTarget(debugCtrl, dataCtrl2, arrayNames):
40
41 targetData = []
42 for arrayName in arrayNames:
43 exprType = dataCtrl2.getExpressionType(0, arrayName)
44 exprInfo = exprType.Expression()
45 numElements = exprInfo.ArrayDimension()
46 dataCtrl2.release(exprType)
47 targetArray = []
48 for i in range(numElements):
49 val = debugCtrl.evaluate(ic.IConnectDebug.fMonitor, arrayName + f"[{i}]")
50 targetArray.append(val.getInt())
51
52 targetData.append(targetArray)
53
54 return targetData
55
56
57def plotArrays(arrayNames, targetData):
58 for idx, data in enumerate(targetData):
59 pl.plot(data, label=arrayNames[idx])
60
61 pl.legend()
62 pl.xlabel('t')
63 pl.ylabel('values')
64 pl.title("Target Data")
65
66 pl.grid(True)
67
68 pl.show()
69
70
71def _parseArgs():
72 parser = argparse.ArgumentParser(description="Specify names of arrays containing plot data.")
73
74 parser.add_argument('targetVar', metavar='targetVar', type=str, nargs='*',
75 default=['g_intArray1'],
76 help='list of arrays on target')
77
78 return parser.parse_args()
79
80
81def main():
82 args = _parseArgs()
83 print(args.targetVar)
84 debugCtrl, dataCtrl2 = _initTarget()
85 targetData = getDataFromTarget(debugCtrl, dataCtrl2, args.targetVar)
86 plotArrays(args.targetVar, targetData)
87
88
89if __name__ == "__main__":
90 main()