关于python nfcpy“找不到任何可用的nfc阅读器”

时间:2013-04-21 07:16:49

标签: nfc

我是初学者。安装了libUSB,Python和PyUSB包后,我的ACR122U连接到了计算机。然后我想实现如下代码:

import os
import sys
import time

sys.path.insert(1, os.path.split(sys.path[0])[0])

import nfc
import nfc.ndef

def main():
    clf = nfc.ContactlessFrontend()

    print "Please touch a tag to send a hello to the world"
    while True:
        tag = clf.poll()
        if tag and tag.ndef:
            break

    text_en = nfc.ndef.TextRecord(language="en", text="Hello World")
    text_de = nfc.ndef.TextRecord(language="de", text="Hallo Welt")
    text_fr = nfc.ndef.TextRecord(language="fr", text="Bonjour tout le monde")
    message = nfc.ndef.Message( [text_en, text_de, text_fr] )

    tag.ndef.message = str(message)

    print "Remove this tag"
    while tag.is_present:
        time.sleep(1)

    print "Now touch it again to receive a hello from the world"
    while True:
        tag = clf.poll()
        if tag and tag.ndef:
            break

    message = nfc.ndef.Message( tag.ndef.message )
    for record in message:
        if record.type == "urn:nfc:wkt:T":
            text = nfc.ndef.TextRecord( record )
            print text.language + ": " + text.text

if __name__ == '__main__':
    main()

当我到达

clf= nfc.ContactlessFrontend()"
然后出现了问题:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\tools\python\nfc\clf.py", line 58, in __init__
raise LookupError("couldn't find any usable nfc reader")
LookupError: couldn't find any usable nfc reader

我不知道如何解决它。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我做的就是“Petesh”在评论中说道:

python -d helloworld.py

在输出中有

Exception usb.USBError: 'error submitting URB: Operation not permitted'

用“sudo”运行相同的命令之后,它起作用了。