From b127461be6ff04b5a8f2ef2ef795199fcc09a5df Mon Sep 17 00:00:00 2001 From: wangfq Date: Fri, 31 Jul 2026 08:26:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20DLD154Tool=20Modbus=20=E5=A4=8D?= =?UTF-8?q?=E4=BD=8D=20MCU=20=E6=8C=89=E9=92=AE=20(HR=200x0012=3D0x2C2C,?= =?UTF-8?q?=20=E5=AF=B9=E9=BD=90=20700BS=200x2C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DLD154Tool/main.py | 12 ++++++++++++ DLD154Tool/protocol_modbus.py | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/DLD154Tool/main.py b/DLD154Tool/main.py index ccf0d56..1468f48 100644 --- a/DLD154Tool/main.py +++ b/DLD154Tool/main.py @@ -31,6 +31,7 @@ from protocol_700bs import ( from protocol_modbus import ( build_read_input_regs, build_read_holding_regs, build_read_discrete_inputs, build_write_single_reg, build_write_multiple_regs, build_report_slave_id, + build_reset_mcu, parse_response, is_active_report, FullDataBlock, ) @@ -380,6 +381,11 @@ class TabModbus(QWidget): btn_write.clicked.connect(self._write_single) hl.addWidget(btn_write) + btn_reset = QPushButton("复位 MCU (0x0012=0x2C2C)") + btn_reset.setStyleSheet("color: red; font-weight: bold;") + btn_reset.clicked.connect(self._send_reset) + hl.addWidget(btn_reset) + layout.addWidget(gb_write) # ── 主动上报控制 ── @@ -458,6 +464,12 @@ class TabModbus(QWidget): self.send_request.emit(build_write_single_reg(self._addr(), reg, val)) self.log_signal.emit(f"[Modbus] FC 0x06 write reg=0x{reg:04X} val=0x{val:04X}") + def _send_reset(self): + if QMessageBox.question(self, "确认", "发送复位 MCU 命令 (HR 0x0012=0x2C2C)?", + QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes: + self.send_request.emit(build_reset_mcu(self._addr())) + self.log_signal.emit("[Modbus] 发送复位 MCU 命令 (HR 0x0012=0x2C2C)") + def _toggle_auto_report(self, checked: bool): self._auto_report_enabled = checked val = 1 if checked else 0 diff --git a/DLD154Tool/protocol_modbus.py b/DLD154Tool/protocol_modbus.py index c50a580..8e74a79 100644 --- a/DLD154Tool/protocol_modbus.py +++ b/DLD154Tool/protocol_modbus.py @@ -111,6 +111,11 @@ def build_report_slave_id(addr: int) -> bytes: return build_request(addr, 0x11, b'') +def build_reset_mcu(addr: int) -> bytes: + """FC 0x06 — 写 HR 0x0012=0x2C2C 复位 MCU""" + return build_write_single_reg(addr, 0x0012, 0x2C2C) + + # ══════════════════════════════════════════════════ # 响应解析 # ══════════════════════════════════════════════════