写NG流程:添加光纤传感器线程和双压传感器线程

This commit is contained in:
2026-01-08 18:09:22 +08:00
parent 2de3857d1c
commit 8821b30689
5 changed files with 437 additions and 23 deletions

View File

@ -14,7 +14,7 @@ import threading
import logging
# 网络继电器的 IP 和端口
HOST = '192.168.1.18'
HOST = '192.168.5.18'
PORT = 50000
# 控件命名映射
@ -312,12 +312,12 @@ def init_sensor_monitor():
)
# press_sensor_thread.start()
# 启动红外传感器监听线程
infrared_sensor_thread = threading.Thread(
# 启动光纤传感器监听线程
fiber_sensor_thread = threading.Thread(
target=relay.fiber_sensor_monitor,
daemon=True
)
# infrared_sensor_thread.start()
fiber_sensor_thread.start()
return relay
@ -329,17 +329,14 @@ def control_solenoid():
"""
控制电磁阀,并检测光纤传感器触发状态
"""
# 创建控制器实例
controller = RelayController()
global fiber_triggered
global fiber_triggered, global_relay
try:
# 重置光纤传感器触发事件
fiber_triggered.clear()
# 同时打开
controller.open(solenoid_valve1=True, solenoid_valve2=True)
global_relay.open(solenoid_valve1=True, solenoid_valve2=True)
logging.info("电磁阀1、2已打开")
# 等待线条掉落最多等待1秒
timeout = 2.0
@ -355,7 +352,7 @@ def control_solenoid():
logging.info("出问题!!!,红外传感器未检测到线条")
time.sleep(0.2) # 等待线条掉落
controller.close(solenoid_valve1=True, solenoid_valve2=True)
global_relay.close(solenoid_valve1=True, solenoid_valve2=True)
logging.info("电磁阀1、2已关闭")
except Exception as e:
logging.info(f"操作电磁阀失败:{str(e)}")