summaryrefslogtreecommitdiff
path: root/devices/serial_device.py
diff options
context:
space:
mode:
Diffstat (limited to 'devices/serial_device.py')
-rw-r--r--devices/serial_device.py37
1 files changed, 28 insertions, 9 deletions
diff --git a/devices/serial_device.py b/devices/serial_device.py
index fb131aa..61c3a64 100644
--- a/devices/serial_device.py
+++ b/devices/serial_device.py
@@ -52,6 +52,27 @@ _LABEL_FOR: Dict[str, str] = {v: k for k, v in _FORMAT_LABELS.items()}
_GENERIC_FORMATS = {"key:val", "csv", "json"}
_PROTOCOL_FORMATS = {"scpi", "modbus_rtu", "mark10", "cml"}
+# parse_format → auto-name label — fallback only, used when the OS can't
+# describe the port (simulation mode, or the device isn't enumerable)
+_AUTO_NAME_LABEL: Dict[str, str] = {
+ "mark10": "Mark-10 USB Device",
+ "scpi": "SCPI Serial Device",
+ "modbus_rtu": "Modbus Serial Device",
+ "cml": "CML Serial Device",
+}
+
+
+def _auto_name(parse_format: str, port: str, simulate: bool = False) -> str:
+ """Prefer the OS-reported device description (same string Windows Device
+ Manager / Linux udev shows for this port) over a generic protocol label,
+ so the auto-assigned name matches what the operator sees outside the app."""
+ if not simulate:
+ desc = ArduinoLayer.describe_port(port)
+ if desc:
+ return desc if port in desc else f"{desc} ({port})"
+ label = _AUTO_NAME_LABEL.get(parse_format, "USB Serial Device")
+ return f"{label} ({port})"
+
# Index into the config-widget stacked panel
_STACK_IDX = {
"key:val": 0,
@@ -78,7 +99,7 @@ class SerialDevice(BaseDevice):
parse_format: str = "key:val",
simulate: bool = True,
# ── Generic stream options ──────────────────────────────────────
- num_channels: int = 4,
+ num_channels: int = 1,
channel_names: List[str] = None,
units: List[str] = None,
# ── SCPI ───────────────────────────────────────────────────────
@@ -116,7 +137,7 @@ class SerialDevice(BaseDevice):
channels = self._build_channel_configs()
info = DeviceInfo(
device_id=device_id,
- name="Serial / UART",
+ name=_auto_name(parse_format, port, simulate),
device_type=self.DEVICE_TYPE,
description=self._description(),
icon=self.ICON,
@@ -459,14 +480,12 @@ class SerialConfigWidget(QWidget):
self._fmt_cb.currentIndexChanged.connect(self._on_fmt_changed)
conn_form.addRow("Protocol / Format:", self._fmt_cb)
- self._sim_cb = QComboBox()
- self._sim_cb.addItems(["Simulate", "Real Hardware"])
- self._sim_cb.setCurrentIndex(0 if self.device.simulate else 1)
+ self._sim_cb = QCheckBox("Simulation Mode (no hardware)")
+ self._sim_cb.setChecked(self.device.simulate)
from core.app_settings import is_developer_mode
- mode_lbl = QLabel("Mode:")
dev_mode = is_developer_mode()
- mode_lbl.setVisible(dev_mode); self._sim_cb.setVisible(dev_mode)
- conn_form.addRow(mode_lbl, self._sim_cb)
+ self._sim_cb.setVisible(dev_mode)
+ conn_form.addRow(self._sim_cb)
root.addWidget(conn_grp)
@@ -535,7 +554,7 @@ class SerialConfigWidget(QWidget):
port=self._port_edit.text().strip() or "COM3",
baud=int(self._baud_cb.currentText()),
fmt=fmt,
- simulate=(self._sim_cb.currentIndex() == 0),
+ simulate=self._sim_cb.isChecked(),
)
if fmt in _GENERIC_FORMATS:
kwargs.update(self._generic_panel.collect())