def __init__(self, wib_server='127.0.0.1', cli=False): super().__init__() self.cli = cli self.wib = WIB(wib_server) self.setAutoFillBackground(True) p = self.palette() p.setColor(self.backgroundRole(), QtGui.QColor(*colors[0])) self.setPalette(p) self._main = QtWidgets.QWidget() self.setCentralWidget(self._main) layout = QtWidgets.QVBoxLayout(self._main) self.wib_pane = WIBPane(self) self.femb_panes = [FEMBPane(self, idx) for idx in range(4)] layout.addWidget(self.wib_pane) fembs = QtWidgets.QWidget(self._main) fembs_layout = QtWidgets.QGridLayout(fembs) for idx, f in enumerate(self.femb_panes): fembs_layout.addWidget(f, idx // 2, idx % 2) layout.addWidget(fembs) if self.cli: self.get_sensors() else: QtCore.QTimer.singleShot(500, self.get_sensors)
def __init__(self, wib_server='127.0.0.1', config='femb0.json', grid=False): super().__init__() self.wib = WIB(wib_server) self.config = config self._main = QtWidgets.QWidget() self._main.setFocusPolicy(QtCore.Qt.StrongFocus) self.setCentralWidget(self._main) layout = QtWidgets.QVBoxLayout(self._main) self.grid = QtWidgets.QGridLayout() if grid: self.views = [Hist2DView(), FFTView(), MeanView(), RMSView()] for i, v in enumerate(self.views): self.grid.addWidget(v, i % 2, i // 2) else: self.views = [Hist2DView(), MeanRMSView(), FFTView()] for i, v in enumerate(self.views): self.grid.addWidget(v, 0, i) layout.addLayout(self.grid) nav_layout = QtWidgets.QHBoxLayout() button = QtWidgets.QPushButton('Configure') nav_layout.addWidget(button) button.setToolTip('Configure WIB and front end') button.clicked.connect(self.configure_wib) button = QtWidgets.QPushButton('Acquire') nav_layout.addWidget(button) button.setToolTip('Read WIB Spy Buffer') button.clicked.connect(self.acquire_data) button = QtWidgets.QPushButton('Continuous') nav_layout.addWidget(button) button.setToolTip('Repeat acquisitions until stopped') button.clicked.connect(self.toggle_continuous) self.continuious_button = button self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.acquire_data) layout.addLayout(nav_layout) self.plot()
class WIBMon(QtWidgets.QMainWindow): def __init__(self, wib_server='127.0.0.1', cli=False): super().__init__() self.cli = cli self.wib = WIB(wib_server) self.setAutoFillBackground(True) p = self.palette() p.setColor(self.backgroundRole(), QtGui.QColor(*colors[0])) self.setPalette(p) self._main = QtWidgets.QWidget() self.setCentralWidget(self._main) layout = QtWidgets.QVBoxLayout(self._main) self.wib_pane = WIBPane(self) self.femb_panes = [FEMBPane(self, idx) for idx in range(4)] layout.addWidget(self.wib_pane) fembs = QtWidgets.QWidget(self._main) fembs_layout = QtWidgets.QGridLayout(fembs) for idx, f in enumerate(self.femb_panes): fembs_layout.addWidget(f, idx // 2, idx % 2) layout.addWidget(fembs) if self.cli: self.get_sensors() else: QtCore.QTimer.singleShot(500, self.get_sensors) @QtCore.pyqtSlot() def get_sensors(self): print('Querying sensors...') req = wibpb.GetSensors() rep = wibpb.GetSensors.Sensors() self.wib.send_command(req, rep) self.wib_pane.load_data(rep) for f in self.femb_panes: f.load_data(rep) if not self.cli: QtCore.QTimer.singleShot(1000, self.get_sensors)
) parser.add_argument( '--stage', '-s', choices=['full', 'pre', 'post'], default='full', help= 'Run full power ON sequence or pre/post ADC synchronization stages [default: full]' ) parser.add_argument('FEMB_0', choices=['on', 'off'], help='Power FEMB_0') parser.add_argument('FEMB_1', choices=['on', 'off'], help='Power FEMB_1') parser.add_argument('FEMB_2', choices=['on', 'off'], help='Power FEMB_2') parser.add_argument('FEMB_3', choices=['on', 'off'], help='Power FEMB_3') args = parser.parse_args() wib = WIB(args.wib_server) req = wibpb.PowerWIB() req.femb0 = args.FEMB_0 == 'on' req.femb1 = args.FEMB_1 == 'on' req.femb2 = args.FEMB_2 == 'on' req.femb3 = args.FEMB_3 == 'on' req.cold = args.cold if args.stage == 'full': req.stage = 0 elif args.stage == 'pre': req.stage = 1 elif args.stage == 'post': req.stage = 2 rep = wibpb.Status() print('Sending PowerWIB command...') wib.send_command(req, rep)
class FEMBDiagnostics(QtWidgets.QMainWindow): def __init__(self, wib_server='127.0.0.1', femb=0, cold=False, grid=False, save_to=None, config=None, test=False): super().__init__() self.wib = WIB(wib_server) self.config = config self.femb = femb self.cold = cold self.test = test self.save_to = save_to self._main = QtWidgets.QWidget() self._main.setFocusPolicy(QtCore.Qt.StrongFocus) self.setCentralWidget(self._main) layout = QtWidgets.QVBoxLayout(self._main) self.grid = QtWidgets.QGridLayout() if grid: self.views = [ Hist2DView(femb=femb), FFTView(femb=femb), MeanView(femb=femb), RMSView(femb=femb) ] for i, v in enumerate(self.views): self.grid.addWidget(v, i % 2, i // 2) else: self.views = [ Hist2DView(femb=femb), MeanRMSView(femb=femb), FFTView(femb=femb) ] for i, v in enumerate(self.views): self.grid.addWidget(v, 0, i) layout.addLayout(self.grid) nav_layout = QtWidgets.QHBoxLayout() button = QtWidgets.QPushButton('Configure') nav_layout.addWidget(button) button.setToolTip('Configure WIB and front end') button.clicked.connect(self.configure_wib) button = QtWidgets.QPushButton('Acquire') nav_layout.addWidget(button) button.setToolTip('Read WIB Spy Buffer') button.clicked.connect(self.acquire_data) button = QtWidgets.QPushButton('Continuous') nav_layout.addWidget(button) button.setToolTip('Repeat acquisitions until stopped') button.clicked.connect(self.toggle_continuous) self.continuious_button = button self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.acquire_data) layout.addLayout(nav_layout) self.plot(None) @QtCore.pyqtSlot() def toggle_continuous(self): if self.continuious_button.text() == 'Continuous': self.continuious_button.setText('Stop') print('Starting continuous acquisition') self.timer.start(500) else: self.continuious_button.setText('Continuous') self.timer.stop() @QtCore.pyqtSlot() def acquire_data(self): data = self.wib.acquire_data(buf0=self.femb < 2, buf1=self.femb >= 2) if data is None: return self.timestamps, self.samples = data for view in self.views: view.load_data(self.timestamps, self.samples) self.plot(self.save_to) def plot(self, save_to): for view in self.views: view.plot_data(save_to=save_to) @QtCore.pyqtSlot() def configure_wib(self): if self.config is not None: print('Loading specified config: %s' % self.config) self.wib.configure(self.config) else: print('Generating %s config with FEMB %i enabled' % ('cold' if self.cold else 'warm', self.femb)) req = self.wib.defaults() req.cold = self.cold req.adc_test_pattern = self.test req.fembs[self.femb].enabled = True rep = wibpb.Status() print('Configuring WIB') self.wib.send_command(req, rep) if not rep.success: print(rep.extra.decode('ascii')) print('Successful:', rep.success)
def __init__(self, wib_server='127.0.0.1', config='default.json', rows=1, cols=1, layout=None): super().__init__() plot_layout = layout self.wib = WIB(wib_server) self.config = config self.samples = None self.timestamps = None self._main = QtWidgets.QWidget() self._main.setFocusPolicy(QtCore.Qt.StrongFocus) self.setCentralWidget(self._main) layout = QtWidgets.QVBoxLayout(self._main) button_layout = QtWidgets.QHBoxLayout() button = QtWidgets.QPushButton('Reshape') button_layout.addWidget(button) button.setToolTip('Change the plot grid shape') button.clicked.connect(self.reshape_prompt) button = QtWidgets.QPushButton('Load Layout') button_layout.addWidget(button) button.setToolTip('Save plot layout and selected signals') button.clicked.connect(self.load_layout) button = QtWidgets.QPushButton('Save Layout') button_layout.addWidget(button) button.setToolTip('Load plot layout and selected signals') button.clicked.connect(self.save_layout) layout.addLayout(button_layout) self.grid = QtWidgets.QGridLayout() self.views = [] self.reshape(rows, cols) layout.addLayout(self.grid) nav_layout = QtWidgets.QHBoxLayout() button = QtWidgets.QPushButton('Configure') nav_layout.addWidget(button) button.setToolTip('Configure WIB and front end') button.clicked.connect(self.configure_wib) button = QtWidgets.QPushButton('Acquire') nav_layout.addWidget(button) button.setToolTip('Read WIB Spy Buffer') button.clicked.connect(self.acquire_data) button = QtWidgets.QPushButton('Continuous') nav_layout.addWidget(button) button.setToolTip('Repeat acquisitions until stopped') button.clicked.connect(self.toggle_continuious) self.continuious_button = button self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.acquire_data) layout.addLayout(nav_layout) if plot_layout: self.load_layout(plot_layout) self.plot_selected()
class WIBScope(QtWidgets.QMainWindow): def __init__(self, wib_server='127.0.0.1', config='default.json', rows=1, cols=1, layout=None): super().__init__() plot_layout = layout self.wib = WIB(wib_server) self.config = config self.samples = None self.timestamps = None self._main = QtWidgets.QWidget() self._main.setFocusPolicy(QtCore.Qt.StrongFocus) self.setCentralWidget(self._main) layout = QtWidgets.QVBoxLayout(self._main) button_layout = QtWidgets.QHBoxLayout() button = QtWidgets.QPushButton('Reshape') button_layout.addWidget(button) button.setToolTip('Change the plot grid shape') button.clicked.connect(self.reshape_prompt) button = QtWidgets.QPushButton('Load Layout') button_layout.addWidget(button) button.setToolTip('Save plot layout and selected signals') button.clicked.connect(self.load_layout) button = QtWidgets.QPushButton('Save Layout') button_layout.addWidget(button) button.setToolTip('Load plot layout and selected signals') button.clicked.connect(self.save_layout) layout.addLayout(button_layout) self.grid = QtWidgets.QGridLayout() self.views = [] self.reshape(rows, cols) layout.addLayout(self.grid) nav_layout = QtWidgets.QHBoxLayout() button = QtWidgets.QPushButton('Configure') nav_layout.addWidget(button) button.setToolTip('Configure WIB and front end') button.clicked.connect(self.configure_wib) button = QtWidgets.QPushButton('Acquire') nav_layout.addWidget(button) button.setToolTip('Read WIB Spy Buffer') button.clicked.connect(self.acquire_data) button = QtWidgets.QPushButton('Continuous') nav_layout.addWidget(button) button.setToolTip('Repeat acquisitions until stopped') button.clicked.connect(self.toggle_continuious) self.continuious_button = button self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.acquire_data) layout.addLayout(nav_layout) if plot_layout: self.load_layout(plot_layout) self.plot_selected() @QtCore.pyqtSlot() def reshape_prompt(self): dialog = QtWidgets.QDialog() layout = QtWidgets.QFormLayout() layout.addRow(QtWidgets.QLabel("Choose Plot Grid Shape")) rowbox, colbox = QtWidgets.QLineEdit(str( self.rows)), QtWidgets.QLineEdit(str(self.cols)) layout.addRow(QtWidgets.QLabel("Rows"), rowbox) layout.addRow(QtWidgets.QLabel("Cols"), colbox) buttons = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, dialog) buttons.accepted.connect(dialog.accept) buttons.rejected.connect(dialog.reject) layout.addWidget(buttons) dialog.setLayout(layout) if dialog.exec_() == QtWidgets.QDialog.Accepted: try: r = int(rowbox.text()) c = int(colbox.text()) self.reshape(r, c) except: print('Invalid input to reshape dialog') def reshape(self, rows, cols): self.rows = rows self.cols = cols for i in reversed(range(self.grid.count())): self.grid.itemAt(i).widget().setParent(None) for r in range(self.rows): for c in range(self.cols): i = c + self.cols * r if i < len(self.views): view = self.views[i] else: view = SignalView(data_source=self) self.views.append(view) self.grid.addWidget(view, r, c) for widget in self.views[self.rows * self.cols:]: widget.deleteLater() #how necessary is this, i wonder self.views = self.views[:self.rows * self.cols] self.plot_selected() @QtCore.pyqtSlot() def load_layout(self, fname=None): if fname is None: fname, _ = QtWidgets.QFileDialog.getOpenFileName( self, 'Open settings', '.', 'WIB Scope Plot Layouts (*.ply);;All files (*.*)') if fname: try: with open(fname, 'rb') as f: settings = pickle.load(f) rows = settings['rows'] cols = settings['cols'] views = [ SignalView(data_source=self) for i in range(rows * cols) ] for view, state in zip(views, settings['views']): view.set_state(state) self.views = views self.reshape(rows, cols) except: print('Could not load settings') @QtCore.pyqtSlot() def save_layout(self): fname, _ = QtWidgets.QFileDialog.getSaveFileName( self, 'Save settings', '.', 'WIB Scope Plot Layouts (*.ply);;All files (*.*)') if fname: if not fname.endswith('.ply'): fname = fname + '.ply' settings = {'rows': self.rows, 'cols': self.cols} settings['views'] = [v.get_state() for v in self.views] with open(fname, 'wb') as f: pickle.dump(settings, f) @QtCore.pyqtSlot() def toggle_continuious(self): if self.continuious_button.text() == 'Continuous': self.continuious_button.setText('Stop') print('Starting continuous acquisition') self.timer.start(500) else: self.continuious_button.setText('Continuous') self.timer.stop() @QtCore.pyqtSlot() def acquire_data(self): self.timestamps, self.samples = self.wib.acquire_data( ignore_failure=True) for view in self.views: view.load_data() self.plot_selected() @QtCore.pyqtSlot() def plot_selected(self): for view in self.views: view.plot_signals() @QtCore.pyqtSlot() def configure_wib(self): self.wib.configure(self.config)
bind_parser(help_parser, help) def handle_args(args): try: args = commands.parse_args(args) args.func(args) except CommandException as ex: if ex.parser is not None: ex.parser.print_usage() print(ex.message) if __name__ == "__main__": args = parser.parse_args() wib = WIB(args.wib_server) if args.command is None: import readline hist_file = os.path.expanduser('~/.wib_client_hist') if os.path.exists(hist_file): readline.read_history_file(hist_file) else: open(hist_file, 'w').close() hist_start = readline.get_current_history_length() while True: try: line = input('[%s] >> ' % args.wib_server).strip() handle_args(shlex.split(line)) except KeyboardInterrupt: print() continue
def acquire(args): take_data(WIB(args.wib_server), args.femb_data, num_acquisitions=args.nacq, cold=args.cold, ignore_failure=args.ignore_failure)
class FEMB0Diagnostics(QtWidgets.QMainWindow): def __init__(self, wib_server='127.0.0.1', config='femb0.json', grid=False): super().__init__() self.wib = WIB(wib_server) self.config = config self._main = QtWidgets.QWidget() self._main.setFocusPolicy(QtCore.Qt.StrongFocus) self.setCentralWidget(self._main) layout = QtWidgets.QVBoxLayout(self._main) self.grid = QtWidgets.QGridLayout() if grid: self.views = [Hist2DView(), FFTView(), MeanView(), RMSView()] for i, v in enumerate(self.views): self.grid.addWidget(v, i % 2, i // 2) else: self.views = [Hist2DView(), MeanRMSView(), FFTView()] for i, v in enumerate(self.views): self.grid.addWidget(v, 0, i) layout.addLayout(self.grid) nav_layout = QtWidgets.QHBoxLayout() button = QtWidgets.QPushButton('Configure') nav_layout.addWidget(button) button.setToolTip('Configure WIB and front end') button.clicked.connect(self.configure_wib) button = QtWidgets.QPushButton('Acquire') nav_layout.addWidget(button) button.setToolTip('Read WIB Spy Buffer') button.clicked.connect(self.acquire_data) button = QtWidgets.QPushButton('Continuous') nav_layout.addWidget(button) button.setToolTip('Repeat acquisitions until stopped') button.clicked.connect(self.toggle_continuous) self.continuious_button = button self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.acquire_data) layout.addLayout(nav_layout) self.plot() @QtCore.pyqtSlot() def toggle_continuous(self): if self.continuious_button.text() == 'Continuous': self.continuious_button.setText('Stop') print('Starting continuous acquisition') self.timer.start(500) else: self.continuious_button.setText('Continuous') self.timer.stop() @QtCore.pyqtSlot() def acquire_data(self): data = self.wib.acquire_data(buf1=False) if data is None: return self.timestamps, self.samples = data for view in self.views: view.load_data(self.timestamps, self.samples) self.plot() @QtCore.pyqtSlot() def plot(self): for view in self.views: view.plot_data() @QtCore.pyqtSlot() def configure_wib(self): self.wib.configure(self.config)
#!/usr/bin/env python3 import os import sys import time import argparse from wib import WIB import wib_pb2 as wibpb if __name__ == "__main__": parser = argparse.ArgumentParser( description='Send a configuration json document to a WIB') parser.add_argument('--wib_server', '-w', default='127.0.0.1', help='IP of wib_server to connect to [127.0.0.1]') parser.add_argument('--config', '-C', default=None, help='WIB configuration to load [defaults]') args = parser.parse_args() wib = WIB(args.wib_server) wib.configure(args.config)