如何解决针对 .txt 文件读取 RFID_Presented 作为字符串
我正在尝试制作 RFID 门锁。目标是扫描将检查 .txt 文件的 RFID 卡。如果卡串在文件中则接受,如果卡被接受则播放视频,然后发送解锁信号。
发生的事情是,无论是否加载,每张卡都被接受。我不确定为什么会发生这种情况...如果有人可以帮忙,我附上我的代码!!!
这是我的代码:
#!/usr/bin/env python3
from evdev import InputDevice
from select import select
import RPi.GPIO as GPIO
import time
from time import sleep
import subprocess
from subprocess import run
import datetime
import os
import sys
import re
import pygame
from pygame.locals import *
def main():
pygame.init()
windowSurface = pygame.display.set_mode ((1024,600),pygame.NOFRAME)
img = pygame.image.load("/home/pi/Accepted/New Phone Wallpaper copy.jpg")
pygame.mouse.set_cursor((8,8),(0,0),0))
windowSurface.blit(img,0))
pygame.display.flip()
pygame.event.clear()
def check_if_string_in_file(file_name,string_to_search):
"""Check if any line in the file contains given string"""
with open("/home/pi/Accepted/Loaded_Cards.txt",'r') as read_obj:
for line in read_obj:
if string_to_search in line:
return True
return False
rfid_presented = ""
e = rfid_presented;
keys = "X^1234567890asdfghjklXXXXXycbnmXXXXXXXXXXXXXXXXXXXXXXX"
dev = InputDevice('/dev/input/event0')
while True:
r,w,x = select([dev],[],[])
for event in dev.read():
if event.type==1 and event.value==1:
if event.code==28:
if check_if_string_in_file('/home/pi/Accepted/Loaded_Cards.txt',e):
videoPath = "myMovieFile.mp4"
omx = run(["omxplayer",'--win','1,1,1024,600',videoPath])
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(26,GPIO.OUT,initial=GPIO.LOW)
GPIO.output(26,GPIO.HIGH)
time.sleep(3)
GPIO.output(26,GPIO.LOW)
else:
rfid_presented = ""
else:
rfid_presented += keys[event.code]
main()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。