2013-04-21 117 views
1

我是一名初學者。安裝libUSB,Python和PyUSB包後,將我的ACR122U連接到電腦上。然後我想實現如下代碼:關於python nfcpy「找不到任何可用的nfc閱讀器」

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 

我不知道如何解決我t。有人能幫助我嗎?

+1

你嘗試設置你的python日誌級別進行調試和再次運行嗎?有很多模塊發出的日誌消息可能有助於確定問題所在 – Petesh 2013-04-21 10:23:23

回答

0

我有

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

與「命令」 runnung相同的命令後也爲「Petesh」在他的評論中說,通過運行

python -d helloworld.py 

在輸出,它的工作。