From 3f8a6bd5098343a6d015ad48865ccaeecd32c351 Mon Sep 17 00:00:00 2001 From: leon Date: Sun, 13 Sep 2026 08:36:32 +0800 Subject: [PATCH] =?UTF-8?q?hvs2=E4=B8=AD=E5=A2=9E=E5=8A=A0=E6=B0=AE?= =?UTF-8?q?=E6=B0=94=E9=98=80=E9=97=A8=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hvs_service2/main.py | 8 ++++++++ hvs_service2/tcp_io_module.py | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/hvs_service2/main.py b/hvs_service2/main.py index 2d141d3..0798201 100644 --- a/hvs_service2/main.py +++ b/hvs_service2/main.py @@ -23,6 +23,7 @@ def main(): light_state_update_time = 0.0 xray_off_time = 0.0 + last_valve_time = 0.0 while True: try: @@ -47,8 +48,15 @@ def main(): light_state_update_time = time.time() time.sleep(0.1) + + if time.time() - last_valve_time > 10.0: + io_module.control_valve(13, True) + time.sleep(1) + io_module.control_valve(13, False) + last_valve_time = time.time() except KeyboardInterrupt: print("程序收到中断信号,正在退出...") + io_module.control_valve(13, False) io_module.stop() hv_service.stop() mqtt_client.stop() diff --git a/hvs_service2/tcp_io_module.py b/hvs_service2/tcp_io_module.py index 60e2b5d..6c1a606 100644 --- a/hvs_service2/tcp_io_module.py +++ b/hvs_service2/tcp_io_module.py @@ -184,6 +184,13 @@ class TcpIoModule(): except Exception as e: print(f"写入线圈出错: {e}") self.is_connected = False + + def control_valve(self, index, value): + try: + self.client.write_coil(index, value) + except Exception as e: + print(f"写入线圈出错: {e}") + self.is_connected = False def get_register_value(self, register_address): """