【发布时间】:2019-02-19 22:34:36
【问题描述】:
我正在尝试编写一个 python 代码来读取我的 RFID 卡,如果他不会得到任何响应,则继续。
但是当他等待读者的重播时我被卡住了 是否有任何 python 命令这样说:
while reader.available()?
这是我的代码(正在等待放置射频标签)
#!/usr/bin/env python
import RPi.GPIO as GPIO
import SimpleMFRC522
import time
reader = SimpleMFRC522.SimpleMFRC522 ()
OldText = ''
while True:
# GPIO.cleanup()
time.sleep(1)
try:
status,TagType = reader.read_no_block()
print(status)
if status == 'None':
print ("No Card Found")
elif status != 'None':
id,text = reader.read()
if text != OldText:
print(text)
OldText=text
else:
print ("Same card")
finally:
GPIO.cleanup()
time.sleep(5)
这是修复代码 - 但是在外壳上我没有得到“找不到卡” - 为什么? 这是我现在得到的输出:
675036844849
new test 13.9.18
None
Same card
MFRC522-python/ReadOnce.py:28: RuntimeWarning: No channels have been set up yet - nothing to clean up! Try cleaning up at the end of your program instead!
GPIO.cleanup()
None
Same card
None
Same card
None
Same card
None
White_Card
None
Same card
None
Same card
None
如果 RFID 上没有卡 - 它会卡住.... 为什么?
【问题讨论】:
-
你能再帮忙吗?我想我需要了解这部分 def read(self): id, text = self.read_no_block() while not id: id, text = self.read_no_block() return id, text - 但我需要从中得到什么?
-
没有一个关键字。检查此链接以了解其用法 - educative.io/edpresso/what-is-the-none-keyword-in-python