问题描述
我使用带有Raspberry Pi4的MFRC522读取器来读取RFID标签。 MFRC522阅读器连接到Raspberry上的GPIO引脚。下面是Python3.7中的脚本。
#!/usr/bin/python3.7 python3.7
# -*- coding: utf-8 -*-
import re,sys,signal,time
import RPi.GPIO as GPIO
import MFRC522 # comment out for testing on notebook
# define variables
global refTime,tag
# assign values
refTime = time.time()
tag = None
# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()
print("begin scanning loop...")
# read port
while int(time.time()-refTime) < 30:
# Scan for cards
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()
# If we have the UID,continue
if status == MIFAREReader.MI_OK:
print("> drug tag detected")
break
else:
print("> no tag detected")
continue
# a bit of delay
time.sleep(.5)
GPIO.cleanup() # Clear input buffer
time.sleep(0.1)
我想检查阅读器是否正常工作。为此,我使用了下面的代码。不幸的是,代码无法区分损坏的标签和损坏的阅读器。
#!/usr/bin/python3.7 python3.7
# -*- coding: utf-8 -*-
import re,spidev
import RPi.GPIO as GPIO
spi = None
try:
spi = spidev.SpiDev()
bus = 0
device = 0
spi.open(bus,device)
spi.max_speed_hz = 10000000
spi.mode = 0b00
spi.lsbfirst = False
except Exception as e:
print(e)
GPIO.cleanup()
if spi:
spi.close()
spi = None
print(spi)
如何在不涉及读卡,MOSI / MISO桥接器或其他的情况下,当场确认读取器已启动并运行?我检查了这些帖子,但没有找到答案:
- detect-removed-card-with-mfrc522
- two-mfrc522-readers
- heck-if-spi-is-enabled
- programcreek.com/python/example/105717/spidev.SpiDev
- check-whether-spi-working
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)