diff --git a/oscilloscope/serialio.py b/oscilloscope/serialio.py index be60f1f..f7915e6 100644 --- a/oscilloscope/serialio.py +++ b/oscilloscope/serialio.py @@ -57,6 +57,7 @@ def __init__( super().__init__(emitterIsEnabled=emitterIsEnabled, *args, **kwargs) self.name = name self.port = kwargs.pop("port", None) + self.baudrate = kwargs.pop("baudrate", None) self.reconnectDelay = reconnectDelay self.maxAttempts = maxAttempts self.portsRefreshTime = portsRefreshTime @@ -148,6 +149,7 @@ def connect(self): if self.serial.port is None and self.port is not None: self.serial.port = self.port + self.serial.baudrate = self.baudrate self.serial.open() except Exception as e: diff --git a/run.py b/run.py index 915714c..0f50413 100644 --- a/run.py +++ b/run.py @@ -49,7 +49,7 @@ def __configureButtons(self): def __configureSerial(self): """Configures the serial device variables.""" self.baudrates.addItems(['1200', '2400', '4800', '9600', '14400', '19200', '28800', '31250', '57600', '115200']) - self.baudrates.setCurrentIndex(3) + self.baudrates.setCurrentIndex(9) self.serial = Serial(name="arduino", timeout=.5, emitAsDict=False) self.serial.on('connection', self.updateSerialConnectionStatus) self.serial.on('ports', self.updateListOfPorts) @@ -60,7 +60,7 @@ def __configureTimers(self): """Configures timers.""" self.samplerTimerCounter = SamplerTimeCounter() self.frequencyLabelTimer = TimerCount( - interval=1, + interval=1, callback = lambda: self.fsLabel.setText(f"{self.samplerTimerCounter.lastFrequency():.5f}") ) @@ -79,24 +79,26 @@ def updateBuffer(self, data: str): self.frequencyLabelTimer.update() self.samplerTimerCounter.update() - def updateGraph(self): - """Plots the signal over the corresponding GUI element.""" + def updateGraph(self): + """Plots the signal over the corresponding GUI element.""" data = self.buffer.getData() self.curve.setData(data) # When the buffer is full clear it if self.buffer.isFull(): self.buffer.clear() - + def updatePortDevice(self): """Updates a new value for the port device.""" device = self.devices.currentText() + baudrate = self.baudrates.currentText() self.connectBtn.setChecked(False) if not self.serial.isOpen(): self.serial.port = device + self.serial.baudrate = baudrate else: self.serial.disconnect(force=True) - + def start(self): """Starts the serial read loop.""" self.serial.start() @@ -110,5 +112,5 @@ def close(self, event): app = QApplication(sys.argv) w = Oscilloscope() w.show() - w.start() # + w.start() # sys.exit(app.exec_())