From 1a11add438e6dd9369722f1347083c2f5bf0978a Mon Sep 17 00:00:00 2001 From: XIVN1987 Date: Tue, 2 Jun 2020 12:04:41 +0800 Subject: [PATCH] add multi wave support --- README.md | 6 ++++++ RTTView.py | 56 ++++++++++++++++++++++++++++++++++++----------------- setting.ini | 2 +- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index df7aa3f..b2c0529 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,11 @@ to run software, you need python 3.6, pyqt5 and pyqtchart wave show: ![](https://github.com/XIVN1987/JRTTView/blob/master/截屏.gif) +data format for wave show: ++ 1 wave: 11, 22, 33, ++ 2 wave: 11 22, 33 44, 55 66, ++ 3 wave: 11 22 33, 44 55 66, 77 88 99, ++ 4 wave: 11 22 33 44, 55 66 77 88, 99 11 22 33, + input: ![](https://github.com/XIVN1987/JRTTView/blob/master/截屏.jpg) diff --git a/RTTView.py b/RTTView.py index 1ea0073..602c964 100644 --- a/RTTView.py +++ b/RTTView.py @@ -11,6 +11,8 @@ from PyQt5.QtChart import QChart, QChartView, QLineSeries, QLegend +N_CURVES = 4 + class RingBuffer(ctypes.Structure): _fields_ = [ ('sName', ctypes.c_uint), # ctypes.POINTER(ctypes.c_char),64位Python中 ctypes.POINTER 是64位的,与目标芯片不符 @@ -55,6 +57,8 @@ def __init__(self, parent=None): self.tmrRTT.setInterval(10) self.tmrRTT.timeout.connect(self.on_tmrRTT_timeout) self.tmrRTT.start() + + self.tmrRTT_Cnt = 0 def initSetting(self): if not os.path.exists('setting.ini'): @@ -72,21 +76,16 @@ def initSetting(self): self.linDLL.setText(self.conf.get('J-Link', 'dllpath')) def initQwtPlot(self): - self.PlotData = [0]*1000 + self.PlotData = [[0]*1000 for i in range(N_CURVES)] + self.PlotPoint = [[QtCore.QPointF(j, 0) for j in range(1000)] for i in range(N_CURVES)] self.PlotChart = QChart() - self.PlotChart.legend().hide() self.ChartView = QChartView(self.PlotChart) self.ChartView.setVisible(False) self.vLayout.insertWidget(0, self.ChartView) - self.PlotCurve = QLineSeries() - self.PlotCurve.setColor(Qt.red) - self.PlotChart.addSeries(self.PlotCurve) - - self.PlotChart.createDefaultAxes() - self.PlotChart.axisX().setLabelFormat('%d') + self.PlotCurve = [QLineSeries() for i in range(N_CURVES)] @pyqtSlot() def on_btnOpen_clicked(self): @@ -180,19 +179,40 @@ def on_tmrRTT_timeout(self): else: if self.rcvbuff.rfind(b',') == -1: return - d = [int(x) for x in self.rcvbuff[0:self.rcvbuff.rfind(b',')].split(b',')] - for x in d: - self.PlotData.pop(0) - self.PlotData.append(x) - - points = [QtCore.QPoint(i, v) for i, v in enumerate(self.PlotData)] - - self.PlotCurve.replace(points) - self.PlotChart.axisX().setMax(len(self.PlotData)) - self.PlotChart.axisY().setRange(min(self.PlotData), max(self.PlotData)) + d = self.rcvbuff[0:self.rcvbuff.rfind(b',')].split(b',') # [b'12', b'34'] or [b'12 34', b'56 78'] + d = [[float(x) for x in X.strip().split()] for X in d] # [[12], [34]] or [[12, 34], [56, 78]] + for arr in d: + for i, x in enumerate(arr): + if i == N_CURVES: break + + self.PlotData[i].pop(0) + self.PlotData[i].append(x) + self.PlotPoint[i].pop(0) + self.PlotPoint[i].append(QtCore.QPointF(999, x)) self.rcvbuff = self.rcvbuff[self.rcvbuff.rfind(b',')+1:] + self.tmrRTT_Cnt += 1 + if self.tmrRTT_Cnt % 4 == 0: + if len(d[-1]) != len(self.PlotChart.series()): + for series in self.PlotChart.series(): + self.PlotChart.removeSeries(series) + for i in range(min(len(d[-1]), N_CURVES)): + self.PlotCurve[i].setName(f'Curve {i+1}') + self.PlotChart.addSeries(self.PlotCurve[i]) + self.PlotChart.createDefaultAxes() + + for i in range(len(self.PlotChart.series())): + for j, point in enumerate(self.PlotPoint[i]): + point.setX(j) + + self.PlotCurve[i].replace(self.PlotPoint[i]) + + miny = min([min(d) for d in self.PlotData]) + maxy = max([max(d) for d in self.PlotData]) + self.PlotChart.axisY().setRange(miny, maxy) + self.PlotChart.axisX().setRange(0000, 1000) + except Exception as e: self.rcvbuff = b'' print(str(e)) # 波形显示模式下 txtMain 不可见,因此错误信息不能显示在其上 diff --git a/setting.ini b/setting.ini index 2dc2e28..ac15b67 100644 --- a/setting.ini +++ b/setting.ini @@ -1,5 +1,5 @@ [J-Link] -dllpath = C:/Program/Segger/JLink_V502g/bin_x64/JLink_x64.dll +dllpath = D:/Program/Segger/JLink_V502k/bin_x64/JLink_x64.dll [Memory] startaddr = 0x20000000