You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.0 KiB

from helper.SerialPort import *
from collections import Counter
import time
import threading
import binascii
# 移植来自RMS3.0的超高频SimpleRFIDReader方法中的超高频UHF部分
class OutSideUHFReader:
def __init__(self, com="/dev/ttyUSB0"):
self.seria = None
self.rfidData=''
self.taskKillFlag=True
self.noCount=0
self.bqz=''
try:
self.seria = SerialPort(com, 115200,0.1)
print('小型FID初始化成功')
except Exception as ex:
print('小型FID初始化失败' + str(ex))
# 读取
def read(self):
self.seria.Write(bytes.fromhex("A0 04 FF 89 01 D3"))
while True:
data = self.seria.Read()
if data == None:
continue
else:
break
val = str(binascii.b2a_hex(data).decode())
# print('valvalval:',val)
if len(val) == 66:
# 不同的超高频的标签的UID位置可能不一样注意
bq = val[14:38]
self.bqz=bq
self.noCount=0
else:
self.noCount+=1
if(self.noCount>=3):
self.bqz = ""
# print(bqz)
return self.bqz
def getData(self):
return self.rfidData
def readDataThread(self):
while not(self.taskKillFlag):
try:
dataStr=self.read()
if(dataStr):
self.rfidData=dataStr
else:
self.rfidData=''
time.sleep(0.1)
except Exception as e:
print(str(e))
# 启动服务
def start(self):
self.rfidData=''
self.taskKillFlag=False
if self.seria.ser:
p = threading.Thread(target=self.readDataThread)
p.start()
else:
print("打开串口设备失败!")
# 停止服务
def stop(self):
self.taskKillFlag=True
self.rfidData=''
rfid_reader = OutSideUHFReader()
rfid_reader.start()