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): """