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)
|
||||
|
||||
Reference in New Issue
Block a user