def halscope_list_update(self): watchlist = [] for r in range(self.watched_list.rowCount()): if self.watched_list.item(r, 0).checkState(): watchlist.append([ self.watched_list.item(r, 4).text(), self.watched_list.item(r, 5).text(), self.watched_list.item(r, 1).text(), self.watched_list.item(r, 6).text() ]) if not watchlist: return self.trig_combo.clear() model = self.trig_combo.model() for i, key in enumerate(watchlist): #Set (Channel, NChannel*10+ChannelType, Pin offset) osc.send_packet(self.control, osc.OSC_CHANNEL, i * 10 + int(key[3]), int(key[0], 16)) item = QStandardItem(key[2]) item.setData(int(key[3]), role=Qt.UserRole + 1) item.setData(int(key[0], 16), role=Qt.UserRole + 2) model.appendRow(item) self.trig_combo.setCurrentIndex(-1) #Clear data old data osc.send_packet(self.control, osc.OSC_CHANNEL, (i + 1) * 10, 0) self.plot_update_data()
def on_oscrun_clicked(self): try: t = self.trig_edit.text() osc.send_packet(self.control, osc.OSC_RUN, self.trigger_mode, float(t) if t else 0) except Exception as e: printInfo(_("Failed to send run cmd: {}", e))
def trigger_changed(self, i): name = self.trig_combo.itemData(i, role=Qt.DisplayRole) if name: stype = self.trig_combo.itemData(i, role=Qt.UserRole + 1) addr = self.trig_combo.itemData(i, role=Qt.UserRole + 2) osc.send_packet(self.control, osc.OSC_TRIG, stype, addr) if len(self.plots) > i + 1 and i >= 0: self.plots[i + 1].addItem(self.hLine) self.plots[i + 1].addItem(self.tLine)
def load_data(self): self.tree.clear() try: data_pin = osc.send_packet(self.control, osc.OSC_LIST, osc.HAL_PIN, 0) data_pin = data_pin.split('\n') if "CONTROL" in data_pin[0]: self.control = int(data_pin[0].split(' ')[1], 16) data_pin = data_pin[1:] data_pin = filter( lambda a: len(a) == 5, [[c for c in s.split(' ') + [str(osc.HAL_PIN)] if len(c) > 0] for s in data_pin]) data_param = osc.send_packet(self.control, osc.OSC_LIST, osc.HAL_PARAMETER, 0) data_param = data_param.split('\n') if "CONTROL" in data_param[0]: self.control = int(data_param[0].split(' ')[1], 16) data_param = data_param[1:] data_param = filter(lambda a: len(a) == 5, [[ c for c in s.split(' ') + [str(osc.HAL_PARAMETER)] if len(c) > 0 ] for s in data_param]) data = list(data_pin) + list(data_param) except Exception as e: printInfo(_("Failed to get hal pin list: {}", e)) return if not data: data = [ [ ' ', ' ', ' ', _("HAL Pin viewer works only with\n loaded hal component 'ascope'." ), ' ' ], ] self.get_tree(data, self.tree)
def get_tree(self, pins, parent): cat_list = [] for pin in pins: if '.' in pin[3]: cat = pin[3].split('.')[0] if cat in cat_list: continue cat_list.append(cat) child = QTreeWidgetItem(parent) child.setText(0, "{}".format(cat)) self.get_tree( map( lambda s: s[:3] + [s[3][len(cat) + 1:]] + s[4:], filter( lambda s: s[3].startswith(cat + ".") and '.' in s[ 3], pins)), child) else: child = QTreeWidgetItem(parent) child.setText(0, pin[3]) child.setText(1, osc.get_type_text(pin[1])) child.setText(2, osc.get_dir_text(pin[2])) child.setText(3, pin[0]) child.setText(4, pin[4])
def update_watched_list(self): if not self.watched_list.visibleRegion().isEmpty(): for r in range(self.watched_list.rowCount()): addr = self.watched_list.item(r, 4) pdir = self.watched_list.item(r, 5) htype = self.watched_list.item(r, 6) if addr and pdir and htype: data = osc.send_packet(self.control, osc.OSC_STATE, int(htype.text()), int(addr.text(), 16)) if data: data = data[:-1].replace(' ', '') value = self.watched_list.item(r, 3) if value: value.setText(data) else: self.watched_list.setItem(r, 3, QTableWidgetItem(data))
def plot_update_data(self): if not self.trig_edit.visibleRegion().isEmpty(): #Check (Check,0,0) data = osc.send_packet(self.control, osc.OSC_CHECK, 0, 0) if not data: return answer = int(data[:-1]) if answer == osc.SAMPLE_COMPLETE: self.osc_status.setText(_("Complete")) data = osc.send_packet(self.control, osc.OSC_GET, 0, 0) if self.shot_mode: self.on_oscstop_clicked() else: self.on_oscrun_clicked() elif answer == osc.SAMPLE_RUN: self.osc_status.setText(_("Reading")) return elif answer == osc.SAMPLE_IDLE: self.osc_status.setText(_("Idle")) return elif answer in (osc.SAMPLE_CHANGE, osc.SAMPLE_HIGH, osc.SAMPLE_LOW): self.osc_status.setText(_("Waiting")) return else: return if not data: return self.clear_plot() color = [ 'blue', 'green', 'red', 'orange', 'violet', 'brown', 'gray', 'white' ] lineStyle = [ Qt.SolidLine, Qt.DashLine, Qt.DotLine, Qt.DashDotLine, Qt.DashDotDotLine, Qt.SolidLine, Qt.SolidLine ] watchedlist = [] for r in range(self.watched_list.rowCount()): if self.watched_list.item(r, 0).checkState(): name = self.watched_list.item(r, 1).text() watchedlist.append(name) self.data[name] = [[], []] data = data.split('\n') samples = 0 thread = 0 if "Samples" in data[0]: s = data[0].split(' ') samples = int(s[1]) thread = int(s[3]) data = data[1:] for i, d in enumerate(data): s = d.split(' ') if len(s) == 2: channel = s[0] value = s[1] else: continue l = len(self.data[watchedlist[int(channel)]][0]) self.data[watchedlist[int(channel)]][0].append(l) self.data[watchedlist[int(channel)]][1].append(float(value)) self.info_label.setText("S:{} T:{:.2f}ms".format( samples / len(watchedlist), (thread / 1000000) * self.div_edit.value())) index_x = [] label_x = [] for i, l in enumerate(self.data[watchedlist[0]][0]): index_x.append(i) label_x.append(l * thread / 1000000) label = list(zip(index_x, label_x)) ticks = [label[::100], label] self.axis_x.setTicks(ticks) osc_list = [(self.watched_list.item(r,7),self.watched_list.item(r,8)) \ for r in range(self.watched_list.rowCount()) \ if self.watched_list.item(r,0).checkState()] for i, key in enumerate(self.data): axis = pyqtgraph.AxisItem('right') axis.tickFont = QFont("Helvetica", pointSize=13, weight=1, italic=False) view = pyqtgraph.ViewBox() self.plots[0].layout.addItem(axis, 2, i + 3) self.plots[0].scene().addItem(view) axis.linkToView(view) if osc_list[i][0] and osc_list[i][1]: min = float(osc_list[i][0].text()) max = float(osc_list[i][1].text()) view.setRange(yRange=(min, max), padding=0) view.setXLink(self.plots[0]) self.plots.append(view) axis.setLabel(key, **{'color': color[i], 'font-size': '16pt'}) pen = pyqtgraph.mkPen(QColor(color[i]), width=2, style=lineStyle[i]) curve = pyqtgraph.PlotCurveItem(self.data[key][1], pen=pen) view.addItem(curve) trigger = self.trig_combo.currentIndex() if trigger >= 0 and trigger == i: self.plots[i + 1].addItem(self.hLine) self.plots[i + 1].addItem(self.tLine) self.updateViews()
def on_oscstop_clicked(self): osc.send_packet(self.control, osc.OSC_STOP, 0, 0)
def divider_value_changed(self): try: div = self.div_edit.value() - 1 osc.send_packet(self.control, osc.OSC_DIV, div, 0) except: pass