Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从连接到Raspberry Pi(UART模式)的PN532模块读取Python中的NDEF消息时出现问题_Python_Nfc_Pi_Ndef_Pn532 - Fatal编程技术网

从连接到Raspberry Pi(UART模式)的PN532模块读取Python中的NDEF消息时出现问题

从连接到Raspberry Pi(UART模式)的PN532模块读取Python中的NDEF消息时出现问题,python,nfc,pi,ndef,pn532,Python,Nfc,Pi,Ndef,Pn532,我有一个PN532通过UART连接到树莓Pi 3B。在Python脚本(V3.7.4)中,我激活了读卡器,并读取了数据表单中的一个标记。如果有NDEF消息,我将读取标记的数据并在字典中返回NDEF记录。所有这些都基于nfcpy和ndeflib库 问题是,检查NDEF消息的标记似乎无法正常工作。当使用Android应用程序NFC Tools Pro模拟标签时,可以读取NDEF消息。使用各种其他应用程序,无法读取NDEF消息。当我用NFC tools Pro编程一个真正的标签或卡片时,也找不到NDE

我有一个PN532通过UART连接到树莓Pi 3B。在Python脚本(V3.7.4)中,我激活了读卡器,并读取了数据表单中的一个标记。如果有NDEF消息,我将读取标记的数据并在字典中返回NDEF记录。所有这些都基于nfcpy和ndeflib库

问题是,检查NDEF消息的标记似乎无法正常工作。当使用Android应用程序NFC Tools Pro模拟标签时,可以读取NDEF消息。使用各种其他应用程序,无法读取NDEF消息。当我用NFC tools Pro编程一个真正的标签或卡片时,也找不到NDEF消息。通过USB NFC阅读器使用其他应用程序或标签,或通过手机扫描标签,可以找到并读取NDEF数据

因此,出于某种原因,if
tag.ndef:
的结果并不总是返回true,即使它应该返回true

from time import sleep

import nfc
import ndef
from nfc.clf import RemoteTarget

def parseNDEF():
    with nfc.ContactlessFrontend("tty:S0:pn532") as clf:
        while True:
            target = clf.sense(RemoteTarget("106A"), RemoteTarget("106B"), 
            RemoteTarget("212F"))
            print("Traget: "+str(target))

            if target is None:
                print("No target found ...")
                sleep(0.5)
                continue

            serial = target.sdd_res.hex()
            print("Found a target with serial " + serial + "!")

            tag = nfc.tag.activate(clf, target)
            print("tag data:\n" + str(tag.dump))

            nfcrecs = {}
            if tag.ndef:
                print("Tag is NDEF formatted!")
                print("It has " + str(len(tag.ndef.records)) + " records.")

                i=1;
                for record in tag.ndef.records:
                    print("Record: "+str(record))
                    nfcrecs["rec"+str(i)] = record.text
                    i+=1;

            else:
                print("No NDEF formatted tag.")

            if (len(nfcrecs)>0):
                return nfcrecs
这是使用Pi上的PN532从Android应用程序NFC tools Pro读取数据的结果:

我用与应用程序发送的相同数据编程了一个芯片。编程也通过NFC tools Pro完成。这是使用NFC tools Pro读取芯片的结果:

这是当我在Pi上用PN532读取上述编程芯片时的结果:

知道这里出了什么问题吗

提前感谢您的帮助