gpt4 book ai didi

Python - 循环读取RFID

转载 作者:太空宇宙 更新时间:2023-11-03 21:47:56 24 4
gpt4 key购买 nike

我正在尝试编写一个Python代码来读取我的RFID卡,如果他得不到任何响应则继续。

但是当他等待读者重播时我被卡住了是否有任何python命令说:

while reader.available()? 

这是我的代码(正在等待放置 RF 标签)

#!/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 上没有卡 - 它就会卡住......为什么?

最佳答案

print (status == None) 将返回 true。

print (status == 'None') 将返回 false。

因此使用:如果(状态==无)

关于Python - 循环读取RFID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52343386/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com