1228
This commit is contained in:
@ -384,7 +384,7 @@ class rfid_service:
|
||||
接收线程的主循环,用于接收RFID推送的数据
|
||||
"""
|
||||
while self._thread_signal:
|
||||
self._pause_receive=False
|
||||
# self._pause_receive=False
|
||||
if self._pause_receive:
|
||||
time.sleep(1)
|
||||
continue
|
||||
@ -409,11 +409,11 @@ class rfid_service:
|
||||
|
||||
received_data += chunk
|
||||
remaining_bytes -= len(chunk)
|
||||
print(f"[数据接收] 已接收 {len(received_data)}/{self._buffer_length} 字节")
|
||||
# print(f"[数据接收] 已接收 {len(received_data)}/{self._buffer_length} 字节")
|
||||
|
||||
# 只有接收到完整的数据才算成功
|
||||
if remaining_bytes == 0:
|
||||
print(f"[数据接收] 成功接收完整数据包 ({self._buffer_length} 字节)")
|
||||
# print(f"[数据接收] 成功接收完整数据包 ({self._buffer_length} 字节)")
|
||||
data = received_data # 保存完整的数据包
|
||||
self._error_count=0
|
||||
else:
|
||||
@ -443,13 +443,13 @@ class rfid_service:
|
||||
|
||||
if data:
|
||||
loc_str = command_hex.parse_user_data_hex(data)
|
||||
raw_data = binascii.hexlify(data).decode()
|
||||
print(f"收到RFID推送数据: {raw_data}")
|
||||
# raw_data = binascii.hexlify(data).decode()
|
||||
# print(f"收到RFID推送数据: {raw_data}")
|
||||
|
||||
# 保存到文件
|
||||
with open('rfid_data.log', 'a') as f:
|
||||
timestamp = datetime.now().strftime('%H:%M:%S.%f')[:-3]
|
||||
f.write(f"[{timestamp}] 解析数据: {loc_str}, 原始数据: {raw_data}\n")
|
||||
# with open('rfid_data.log', 'a') as f:
|
||||
# timestamp = datetime.now().strftime('%H:%M:%S.%f')[:-3]
|
||||
# f.write(f"[{timestamp}] 解析数据: {loc_str}, 原始数据: {raw_data}\n")
|
||||
|
||||
if loc_str:
|
||||
# 将数据添加到缓冲区
|
||||
@ -514,6 +514,7 @@ class rfid_service:
|
||||
"""
|
||||
停止接收RFID推送的数据
|
||||
"""
|
||||
print('RFID 线程停止')
|
||||
self._thread_signal = False
|
||||
if self._receive_thread:
|
||||
self._receive_thread.join(timeout=2.0)
|
||||
|
||||
@ -73,7 +73,7 @@ class RelayController:
|
||||
sock.connect((self.host, self.port))
|
||||
sock.send(byte_data)
|
||||
response = sock.recv(1024)
|
||||
print(f"收到继电器响应: {binascii.hexlify(response)}")
|
||||
# print(f"收到继电器响应: {binascii.hexlify(response)}")
|
||||
return response
|
||||
except Exception as e:
|
||||
print(f"继电器通信错误: {e}")
|
||||
@ -97,7 +97,7 @@ class RelayController:
|
||||
def control(self, device, action):
|
||||
"""控制继电器"""
|
||||
if device in self.relay_commands and action in self.relay_commands[device]:
|
||||
print(f"发送控制继电器命令 {device} {action}")
|
||||
# print(f"发送控制继电器命令 {device} {action}")
|
||||
self.send_command(self.relay_commands[device][action])
|
||||
else:
|
||||
print(f"无效设备或动作: {device}, {action}")
|
||||
@ -109,6 +109,13 @@ class RelayController:
|
||||
self.control(self.DOOR_UPPER_CLOSE, 'open')
|
||||
# 异步5秒后关闭
|
||||
threading.Thread(target=self._close_upper_s, daemon=True,name="close_upper_s").start()
|
||||
|
||||
def control_upper_close_after(self):
|
||||
"""控制上料斗关在几秒后"""
|
||||
# 关闭上料斗出砼门
|
||||
self.control(self.DOOR_UPPER_OPEN, 'close')
|
||||
# 异步5秒后关闭
|
||||
threading.Thread(target=self._close_upper_after_s, daemon=True,name="close_upper_after_s").start()
|
||||
|
||||
def control_upper_close_sync(self,duration=5):
|
||||
self.control(self.DOOR_UPPER_OPEN, 'close')
|
||||
@ -224,6 +231,24 @@ class RelayController:
|
||||
self.control(self.DOOR_UPPER_CLOSE, 'close')
|
||||
print("上料斗关闭完成")
|
||||
|
||||
def _close_upper_after_s(self):
|
||||
"""
|
||||
异步5秒后关闭上料斗20秒
|
||||
"""
|
||||
|
||||
# time.sleep(5)
|
||||
self.control_arch_upper_open_sync(5)
|
||||
self.control(self.DOOR_UPPER_CLOSE, 'open')
|
||||
time.sleep(1)
|
||||
self.control(self.DOOR_UPPER_CLOSE, 'close')
|
||||
self.control_arch_upper_open_sync(5)
|
||||
self.control_arch_upper_open_sync(5)
|
||||
self.control_arch_upper_open_async(8)
|
||||
self.control(self.DOOR_UPPER_CLOSE, 'open')
|
||||
time.sleep(20)
|
||||
self.control(self.DOOR_UPPER_CLOSE, 'close')
|
||||
print("上料斗关闭完成")
|
||||
|
||||
def _close_lower_5s(self):
|
||||
time.sleep(6)
|
||||
self.control(self.DOOR_LOWER_CLOSE, 'close')
|
||||
@ -238,19 +263,40 @@ class RelayController:
|
||||
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 control_arch_lower_open_sync(self,duration):
|
||||
"""控制下料斗振动"""
|
||||
self.control(self.BREAK_ARCH_LOWER, 'open')
|
||||
# 异步5秒后关闭
|
||||
time.sleep(duration)
|
||||
self.control(self.BREAK_ARCH_LOWER, 'close')
|
||||
|
||||
def control_arch_upper_open_sync(self,duration):
|
||||
"""控制下料斗振动"""
|
||||
self.control(self.BREAK_ARCH_UPPER, 'open')
|
||||
# 异步5秒后关闭
|
||||
time.sleep(duration)
|
||||
self.control(self.BREAK_ARCH_UPPER, 'close')
|
||||
|
||||
def _close_break_arch_lower(self):
|
||||
time.sleep(3)
|
||||
self.control(self.BREAK_ARCH_LOWER, 'close')
|
||||
|
||||
|
||||
def control_arch_upper_open(self):
|
||||
"""控制上料斗关"""
|
||||
def control_arch_upper_open_async(self,delay_seconds: float = 15):
|
||||
"""异步控制上料斗振动
|
||||
|
||||
Args:
|
||||
delay_seconds: 延迟关闭时间(秒),默认15秒
|
||||
"""
|
||||
# 关闭下料斗出砼门
|
||||
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)
|
||||
threading.Thread(target=lambda d: self._close_break_arch_upper(delay_seconds),args=(delay_seconds,), daemon=True, name="_close_break_arch_upper").start()
|
||||
|
||||
def _close_break_arch_upper(self, delay_seconds: float = 15):
|
||||
time.sleep(delay_seconds)
|
||||
print(f"上料斗振动关闭完成,延迟{delay_seconds}秒")
|
||||
self.control(self.BREAK_ARCH_UPPER, 'close')
|
||||
|
||||
|
||||
|
||||
@ -80,7 +80,7 @@ class TransmitterController:
|
||||
self.relay_controller.modbus_client.close()
|
||||
|
||||
# 直接读取 变送器返回的数据并解析
|
||||
def read_data_normal(self, transmitter_id):
|
||||
def read_data_sub(self, transmitter_id):
|
||||
|
||||
"""
|
||||
Args: transmitter_id 为1 表示上料斗, 为2 表示下料斗
|
||||
@ -90,7 +90,7 @@ class TransmitterController:
|
||||
BUFFER_SIZE= 1024
|
||||
IP = None
|
||||
PORT = None
|
||||
weight = 0
|
||||
weight = None
|
||||
if transmitter_id == 1:
|
||||
# 上料斗变送器的信息:
|
||||
IP = ini_manager.upper_transmitter_ip
|
||||
@ -102,7 +102,7 @@ class TransmitterController:
|
||||
|
||||
if not IP or not PORT:
|
||||
print(f"未配置变送器 {transmitter_id} 的IP或PORT")
|
||||
return 0
|
||||
return None
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
try:
|
||||
s.settimeout(TIMEOUT)
|
||||
@ -134,7 +134,7 @@ class TransmitterController:
|
||||
# 成功返回重量(int),失败返回None
|
||||
return weight
|
||||
|
||||
def read_data(self, transmitter_id):
|
||||
def read_data_sub_test(self, transmitter_id):
|
||||
|
||||
"""
|
||||
测试用:模拟读取变送器数据mock
|
||||
@ -266,4 +266,16 @@ class TransmitterController:
|
||||
except (IndexError, ValueError, UnicodeDecodeError) as e:
|
||||
# print(f"数据解析失败:{e},原始数据包:{packet_data}")
|
||||
return None
|
||||
|
||||
|
||||
def read_data(self,transmitter_id):
|
||||
"""获取重量函数:根据变送器ID获取当前重量,三次"""
|
||||
max_try_times=5
|
||||
try_times=0
|
||||
while try_times<max_try_times:
|
||||
weight=self.read_data_sub(transmitter_id)
|
||||
if weight is not None:
|
||||
return weight
|
||||
try_times+=1
|
||||
print(f'-----获取重量异常-------------- transmitter_id: {transmitter_id}')
|
||||
print(f'-----获取重量异常-------------- transmitter_id: {transmitter_id}')
|
||||
return None
|
||||
Reference in New Issue
Block a user