stage_one

This commit is contained in:
2025-12-12 18:00:14 +08:00
parent dc4ef9002e
commit b8b9679bc8
55 changed files with 6541 additions and 459 deletions

View File

@ -35,8 +35,8 @@ class RelayController:
self.RING: {'open': '00000000000601050000FF00', 'close': '000000000006010500000000'},
self.UPPER_TO_JBL: {'open': '00000000000601050001FF00', 'close': '000000000006010500010000'},
self.UPPER_TO_ZD: {'open': '00000000000601050002FF00', 'close': '000000000006010500020000'},
self.DOOR_LOWER_OPEN: {'open': '00000000000601050006FF00', 'close': '00000000000601050006FF00'},
self.DOOR_LOWER_CLOSE: {'open': '00000000000601050008FF00', 'close': '000000000006010500080000'},
self.DOOR_LOWER_OPEN: {'open': '00000000000601050006FF00', 'close': '000000000006010500060000'},
self.DOOR_LOWER_CLOSE: {'open': '00000000000601050008FF00', 'close':'000000000006010500080000'},
self.DOOR_UPPER_OPEN: {'open': '00000000000601050003FF00', 'close': '000000000006010500030000'},
self.DOOR_UPPER_CLOSE: {'open': '00000000000601050004FF00', 'close': '000000000006010500040000'},
self.BREAK_ARCH_UPPER: {'open': '0000000000060105000AFF00', 'close': '0000000000060105000A0000'},
@ -58,11 +58,14 @@ class RelayController:
self.BREAK_ARCH_UPPER: 3,
self.BREAK_ARCH_LOWER: 4
}
# 添加线程锁,保护对下料斗控制的并发访问
self.door_control_lock = threading.Lock()
def send_command(self, command_hex):
"""发送原始Socket命令"""
if app_set_config.debug_mode:
return None
# if app_set_config.debug_mode:
# return None
try:
byte_data = binascii.unhexlify(command_hex)
@ -102,32 +105,164 @@ class RelayController:
def control_upper_close(self):
"""控制上料斗关"""
# 关闭上料斗出砼门
self.control(self.DOOR_UPPER_OPEN, 'close')
self.control(self.DOOR_UPPER_CLOSE, 'open')
# 异步5秒后关闭
threading.Thread(target=self._close_upper_5s, daemon=True,name="close_upper_5s").start()
threading.Thread(target=self._close_upper_s, daemon=True,name="close_upper_s").start()
def control_upper_close_sync(self,duration=5):
self.control(self.DOOR_UPPER_OPEN, 'close')
self.control(self.DOOR_UPPER_CLOSE, 'open')
time.sleep(duration)
self.control(self.DOOR_UPPER_CLOSE, 'close')
def control_lower_close(self):
"""控制下料斗关"""
# 关闭下料斗出砼门
self.control(self.DOOR_LOWER_CLOSE, 'open')
thread_name = threading.current_thread().name
print(f"[{thread_name}] 尝试控制下料斗关闭")
with self.door_control_lock:
print(f"[{thread_name}] 获得下料斗控制锁,执行关闭操作")
# 关闭下料斗出砼门
self.control(self.DOOR_LOWER_OPEN, 'close')
self.control(self.DOOR_LOWER_CLOSE, 'open')
time.sleep(3)
self.control(self.DOOR_LOWER_CLOSE, 'close')
print(f"[{thread_name}] 下料斗关闭完成,释放控制锁")
# 异步5秒后关闭
threading.Thread(target=self._close_lower_5s, daemon=True,name="close_lower_5s").start()
# threading.Thread(target=self._close_lower_5s, daemon=True,name="close_lower_5s").start()
def control_upper_open_sync(self,duration):
self.control(self.DOOR_UPPER_CLOSE, 'close')
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(duration)
self.control(self.DOOR_UPPER_OPEN, 'close')
def control_upper_close_sync(self,duration):
thread_name = threading.current_thread().name
print(f"[{thread_name}] 尝试执行上料斗同步关闭,实际操作下料斗")
with self.door_control_lock:
print(f"[{thread_name}] 获得下料斗控制锁,执行同步关闭操作")
self.control(self.DOOR_UPPER_OPEN, 'close')
self.control(self.DOOR_UPPER_CLOSE, 'open')
time.sleep(duration)
self.control(self.DOOR_UPPER_CLOSE, 'close')
print(f"[{thread_name}] 同步关闭操作完成,释放控制锁")
def control_upper_open(self):
#关闭信号才能生效
self.control(self.DOOR_UPPER_CLOSE, 'close')
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.2)
self.control(self.DOOR_UPPER_OPEN, 'close')
time.sleep(1)
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.2)
self.control(self.DOOR_UPPER_OPEN, 'close')
time.sleep(1)
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.5)
self.control(self.DOOR_UPPER_OPEN, 'close')
time.sleep(0.1)
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.5)
self.control(self.DOOR_UPPER_OPEN, 'close')
time.sleep(0.1)
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.5)
self.control(self.DOOR_UPPER_OPEN, 'close')
time.sleep(0.1)
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.5)
self.control(self.DOOR_UPPER_OPEN, 'close')
time.sleep(0.1)
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.5)
self.control(self.DOOR_UPPER_OPEN, 'close')
#保持8秒
time.sleep(8)
#8秒后再开5秒
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.5)
self.control(self.DOOR_UPPER_OPEN, 'close')
time.sleep(0.1)
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.5)
self.control(self.DOOR_UPPER_OPEN, 'close')
time.sleep(0.1)
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.5)
self.control(self.DOOR_UPPER_OPEN, 'close')
time.sleep(0.1)
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.5)
self.control(self.DOOR_UPPER_OPEN, 'close')
time.sleep(0.1)
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.5)
self.control(self.DOOR_UPPER_OPEN, 'close')
time.sleep(0.1)
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.5)
self.control(self.DOOR_UPPER_OPEN, 'close')
time.sleep(0.1)
self.control(self.DOOR_UPPER_OPEN, 'open')
time.sleep(0.5)
self.control(self.DOOR_UPPER_OPEN, 'close')
def control_ring_open(self):
"""控制下料斗关"""
# 关闭下料斗出砼门
self.control(self.RING, 'open')
# 异步5秒后关闭
threading.Thread(target=self._close_ring, daemon=True,name="close_ring").start()
threading.Thread(target=self._close_ring, daemon=True,name="_close_ring").start()
def _close_upper_5s(self):
time.sleep(5)
def _close_upper_s(self):
time.sleep(16)
self.control(self.DOOR_UPPER_CLOSE, 'close')
print("上料斗关闭完成")
def _close_lower_5s(self):
time.sleep(5)
time.sleep(6)
self.control(self.DOOR_LOWER_CLOSE, 'close')
def _close_ring(self):
time.sleep(3)
self.control(self.RING, 'close')
def control_arch_lower_open(self):
"""控制下料斗关"""
# 关闭下料斗出砼门
self.control(self.BREAK_ARCH_LOWER, 'open')
# 异步5秒后关闭
threading.Thread(target=self._close_break_arch_lower, daemon=True,name="_close_break_arch_lower").start()
def _close_break_arch_lower(self):
time.sleep(3)
self.control(self.BREAK_ARCH_LOWER, 'close')
def control_arch_upper_open(self):
"""控制上料斗关"""
# 关闭下料斗出砼门
self.control(self.BREAK_ARCH_UPPER, 'open')
# 异步5秒后关闭
threading.Thread(target=self._close_break_arch_upper, daemon=True,name="_close_break_arch_upper").start()
def _close_break_arch_upper(self):
time.sleep(3)
self.control(self.BREAK_ARCH_UPPER, 'close')
def close_all(self):
"""关闭所有继电器"""
self.control(self.UPPER_TO_JBL, 'close')
self.control(self.UPPER_TO_ZD, 'close')
self.control(self.BREAK_ARCH_UPPER, 'close')
self.control(self.BREAK_ARCH_LOWER, 'close')
self.control(self.RING, 'close')
self.control(self.DOOR_LOWER_OPEN, 'close')
self.control(self.DOOR_LOWER_CLOSE, 'close')
self.control(self.DOOR_UPPER_OPEN, 'close')
self.control(self.DOOR_UPPER_CLOSE, 'close')