python 使用 serial库 通过pn532设备读取M1标签时,总是返回不了UID卡号,麻烦哪位帮我看看是哪里出错?
import serial
import binascii
com=input("输入串口号:")
while com=="":
com = input("输入串口号:")
pw=input("输入波特率:")#115200
while pw=="":
pw = input("输入波特率:") # 115200
ser = serial.Serial("com"+com, int(pw), timeout=0.5)
ser.bytesize = 8 # 字节大小
ser.parity = serial.PARITY_NONE # 无校验
ser.stopbits = 1 # 停止位
print("已连接端口:" + str(ser.name)+"\n")
def huan():
da1 = bytes.fromhex("55 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff 03 fd d4 14 01 17 00")
ser.write(da1)
ss = str(binascii.b2a_hex(ser.read(4)))[2:-1]
return ser
def getid(): # 获取卡号
ser = huan()
data = bytes.fromhex("00 00 FF 04 FC D4 4A 02 00 E0 00")
print("获取卡片信息")
ser.write(data)
redata_yid = str(binascii.b2a_hex(ser.read(4)))[2:-1]
if len(redata_yid) == 50:
# print("数据返回正确:" + redata_yid)
id = redata_yid[-12:-4]
print("卡号:" + id)
return id, ser
else:
#print("数据返回出错:" + redata_yid)
print("长度" + str(len(redata_yid)))
return "0", "0"
while True:
getid()
python 使用 serial库 通过pn532设备读取M1标签时,总是返回不了UID卡号,麻烦哪位帮我看看是哪里出错?