diff options
| author | Christian Kolset <christian.kolset@gmail.com> | 2026-04-21 13:43:52 -0600 |
|---|---|---|
| committer | Christian Kolset <christian.kolset@gmail.com> | 2026-04-21 13:57:46 -0600 |
| commit | 2a634dca0c7962b90004f75c4cdac6225201bb5e (patch) | |
| tree | 3e1f0cd4ff165e77d17ebec5278c9bed885bb1da /devices/analog_input.py | |
| parent | b1a61fd29e2282110bc4f4bc4616c55ed9d88dbb (diff) | |
V13
This version contains the profile feature. Allowins users to save the
channels, signals and plots for specific labs.
Diffstat (limited to 'devices/analog_input.py')
| -rw-r--r-- | devices/analog_input.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/devices/analog_input.py b/devices/analog_input.py index 6183f43..508804f 100644 --- a/devices/analog_input.py +++ b/devices/analog_input.py @@ -141,7 +141,22 @@ class AnalogInputDevice(BaseDevice): return self._layer.read() def write_channel(self, channel_id: str, value: Any) -> bool: - return False + """ + Route output commands through the Arduino layer. + + channel_id examples: + "D7" → digital write W:D7:1 or W:D7:0 + "D9" → PWM write P:D9:<duty> (if value is 0-255) + "HEAT" → named param C:HEAT:1.0 + """ + if self.backend != "arduino" or not hasattr(self._layer, "digital_write"): + return False + ch = channel_id.strip() + # Digital pin (D7, D13, etc.) + if ch.upper().startswith("D") and ch[1:].isdigit(): + return self._layer.digital_write(ch, int(bool(value))) + # Named parameter / setpoint + return self._layer.set_parameter(ch, value) def get_config_widget(self) -> QWidget: return AnalogInputConfigWidget(self) @@ -295,7 +310,7 @@ class AnalogInputConfigWidget(QWidget): self._diag_box = QTextEdit() self._diag_box.setObjectName("codeEditor") self._diag_box.setReadOnly(True) - self._diag_box.setMaximumHeight(90) + self._diag_box.setMaximumHeight(160) self._diag_box.setPlaceholderText("Connection log will appear here…") diag_lay.addWidget(self._diag_box) @@ -332,6 +347,13 @@ class AnalogInputConfigWidget(QWidget): lines.append(f"Port: {self.device._ard_port}") lines.append(f"Baud: {self.device._ard_baud}") lines.append(f"pyserial: {'available' if ArduinoLayer.is_pyserial_available() else 'NOT INSTALLED'}") + # Show last raw lines received from Arduino + if hasattr(self.device._layer, "raw_lines"): + raw = self.device._layer.raw_lines + if raw: + lines.append("\nLast lines from Arduino:") + for r in raw: + lines.append(f" {r}") if self.device._last_error: lines.append(f"\nError:\n{self.device._last_error}") self._diag_box.setPlainText("\n".join(lines)) |
