1228
This commit is contained in:
@ -6,25 +6,55 @@ import os
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
import time
|
||||
from hardware.RFID.rfid_service import rfid_service
|
||||
from busisness.blls import ArtifactBll
|
||||
from busisness.models import ArtifactInfoModel
|
||||
|
||||
|
||||
|
||||
def test_data_callback(status,raw_data):
|
||||
rfid=None
|
||||
rfid_before_mould=''
|
||||
artifact_bll=ArtifactBll()
|
||||
def test_data_callback(status,data):
|
||||
"""
|
||||
测试用的数据接收回调函数
|
||||
"""
|
||||
if status:
|
||||
print(f"[回调] 收到RFID数据: {raw_data}")
|
||||
else:
|
||||
print(f"[回调] 读取RFID数据为空或失败")
|
||||
global rfid_before_mould
|
||||
try:
|
||||
if status==1:
|
||||
#成功读取到RFID标签
|
||||
#检查标识是否符号要求
|
||||
if data:
|
||||
loc_array=data.strip(',').split(',')
|
||||
if len(loc_array)==4:
|
||||
if rfid_before_mould!=loc_array[0]:
|
||||
model={
|
||||
'MouldCode':loc_array[0],
|
||||
'BlockNumber':loc_array[1],
|
||||
'SizeSpecification':loc_array[2],
|
||||
'BetonVolume':loc_array[3]
|
||||
}
|
||||
artifact_bll.insert_artifact_bycode(model)
|
||||
rfid_before_mould=loc_array[0]
|
||||
print(f"RFID-生产模具车号:{loc_array[0]}")
|
||||
else:
|
||||
print(f"RFID-重复生产模具车号:{loc_array[0]}")
|
||||
|
||||
else:
|
||||
print("RFID标签格式错误")
|
||||
print(f"成功读取到RFID标签:{data}")
|
||||
else:
|
||||
self.rfid_flag_succ=False
|
||||
print("读取RFID标签失败")
|
||||
except Exception as e:
|
||||
print(f"RFID回调处理异常: {e}")
|
||||
|
||||
|
||||
def test_rfid_functions():
|
||||
"""
|
||||
测试RFIDHardware的主要功能
|
||||
"""
|
||||
global rfid
|
||||
# 初始化RFID控制器
|
||||
rfid = rfid_service(host='192.168.250.77', port=6000)
|
||||
rfid = rfid_service(host='192.168.250.67', port=6000)
|
||||
|
||||
# print("=== RFID硬件测试开始 ===")
|
||||
|
||||
@ -96,21 +126,38 @@ def test_rfid_functions():
|
||||
# rfid._data_buffer.append('THR B1-12,B1,6600 * 1500,1.900')
|
||||
# rfid._data_buffer.append('THR B1-12,B1,6600 * 1500,1.900')
|
||||
# rfid._process_collected_data()
|
||||
rfid.start_receiver(callback=test_data_callback)
|
||||
rfid.start_receiver(callback=test_data_callback)
|
||||
while True:
|
||||
rfid._pause_receive = False
|
||||
time.sleep(10)
|
||||
|
||||
|
||||
# print("接收线程已启动,等待接收数据...")
|
||||
# 等待5秒模拟接收过程1111111111111
|
||||
time.sleep(60*60)
|
||||
finally:
|
||||
# 确保停止接收线程
|
||||
# rfid.stop_receiver()
|
||||
rfid.stop_receiver()
|
||||
|
||||
print("\n=== RFID硬件测试结束 ===")
|
||||
# print("\n=== RFID硬件测试结束 ===")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
# model={
|
||||
# 'ArtifactID':0,
|
||||
# 'MouldCode':'SHR2B1-4',
|
||||
# 'BlockNumber':'B2',
|
||||
# 'SizeSpecification':'6600*1500',
|
||||
# 'BetonVolume':1.910
|
||||
# }
|
||||
# artifact_bll.insert_artifact_bycode(model)
|
||||
test_rfid_functions()
|
||||
except KeyboardInterrupt:
|
||||
if rfid is not None:
|
||||
rfid.stop_receiver()
|
||||
print("\n测试被用户中断")
|
||||
except Exception as e:
|
||||
if rfid is not None:
|
||||
rfid.stop_receiver()
|
||||
print(f"测试过程中发生错误: {e}")
|
||||
Reference in New Issue
Block a user