stage_one
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
import socket
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime
|
||||
import binascii
|
||||
from typing import Optional, Callable, Dict, Any, Set
|
||||
from collections import Counter
|
||||
|
||||
from PySide6.QtCore import QObject
|
||||
from .crc16 import crc16
|
||||
from .command_hex import command_hex
|
||||
|
||||
@ -12,7 +15,8 @@ class rfid_service:
|
||||
"""
|
||||
RFID读写器服务
|
||||
"""
|
||||
def __init__(self, host='192.168.1.190', port=6000):
|
||||
# callback_signal=Signal(int,str)
|
||||
def __init__(self, host='192.168.250.67', port=6000):
|
||||
"""
|
||||
初始化RFID控制器
|
||||
|
||||
@ -34,9 +38,9 @@ class rfid_service:
|
||||
# 需要过滤掉的数据(字符串)
|
||||
self._filter_value = None
|
||||
|
||||
self.check_time_seconds = 60.0 # 采集数据时间(秒)
|
||||
self.check_time_seconds = 5.0 # 采集数据时间(秒)
|
||||
# 超时设置
|
||||
self._connect_timeout = 5.0 # 连接超时时间(秒)
|
||||
self._connect_timeout = 1.0 # 连接超时时间(秒)
|
||||
self.client_socket = None
|
||||
self.connected = False
|
||||
#链接失败次数
|
||||
@ -349,7 +353,7 @@ class rfid_service:
|
||||
#endregion
|
||||
|
||||
|
||||
def start_receiver(self, callback: Optional[Callable[[str], None]] = None)->bool:
|
||||
def start_receiver(self, callback: Optional[Callable[[int,str], None]] = None)->bool:
|
||||
"""
|
||||
开始接收RFID推送的数据
|
||||
|
||||
@ -439,14 +443,21 @@ class rfid_service:
|
||||
|
||||
if data:
|
||||
loc_str = command_hex.parse_user_data_hex(data)
|
||||
print(f"收到RFID推送数据: {binascii.hexlify(data).decode()}")
|
||||
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")
|
||||
|
||||
if loc_str:
|
||||
# 将数据添加到缓冲区
|
||||
with self._data_lock:
|
||||
if self._filter_value == loc_str:
|
||||
continue
|
||||
self._data_buffer.append(loc_str)
|
||||
|
||||
time.sleep(1)
|
||||
self._pause_receive = True
|
||||
self._process_collected_data()
|
||||
|
||||
@ -471,12 +482,15 @@ class rfid_service:
|
||||
most_common_string, count = counter.most_common(1)[0]
|
||||
print(f"出现次数最多的字符串是: '{most_common_string}', 出现次数: {count}")
|
||||
|
||||
# 使用出现次数最多的字符串作为结果传递给回调
|
||||
self._callback(most_common_string)
|
||||
# 使用出现次数最多的字符串作为结果传递给回调函数
|
||||
# self.callback_signal.emit(1,most_common_string)
|
||||
self._callback(1,most_common_string)
|
||||
else:
|
||||
# 空缓冲区情况
|
||||
print("数据缓冲区为空")
|
||||
self._callback(None)
|
||||
# 使用None作为结果传递给回调函数
|
||||
# self.callback_signal.emit(0,'')
|
||||
self._callback(0,'')
|
||||
|
||||
print(f"收集了{len(self._data_buffer)}条RFID数据,过滤后数据为{most_common_string}")
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user