Python树莓派GPIO和Wiegand问题。

问题描述 投票:1回答:1

我对Python非常陌生,在过去的几周里我一直在学习。这是我设法想出的东西。我很高兴,代码大部分时间都能正常工作。 我使用2个GPIO引脚从阅读器读取wiegand格式到我的Raspberry Pi 2。 然而,它并不总是正确扫描。偶尔扫描会挂在存储位上,我不得不第二次拨动阅读器让它完成。有时它会正确完成。有时它完成的卡号是完全错误的。通常第三次拨动读卡器会得到一组新的正确信息。我在PIGPIO的C版和Python版上搞来搞去,试图了解我做了什么不同的事情。我不明白为什么使用那段代码似乎总是从读取器返回一组正确的值。我还没有足够的知识来完全理解PIGPIO代码中发生的事情,所以我不确定如何在我自己的代码中创建这种一致性,因为我从阅读器中捕获信息。 是否有什么东西会立即跳出来,表明我从阅读器读取信息的逻辑有问题? 请记住,我是超级新手,所以我需要一点点的手把手地教我。我有3个不同的HID格式的fobscards,我一直在使用它们来测试。问题发生在利用相同的fob一次又一次,如果我循环使用他们一个又一个。有时,它会扫描10多次,其他时间会立即失败,2或3次扫描不工作。

from time import sleep
import os
import RPi.GPIO as GPIO
import pifacecad as p
GPIO.setmode(GPIO.BOARD)
#GPIO setup
data0=38
data1=40
GPIO.setup(data0,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(data1,GPIO.IN,pull_up_down=GPIO.PUD_UP)
#Setting up display
cad = p.PiFaceCAD()
cad.lcd.backlight_on()
cad.lcd.clear()
cad.lcd.cursor_off()
cad.lcd.blink_off()
cad.lcd.write("Ready")
#Variables
i=0
dataBits=[]
bitCount=1
fcc="0"
card="0"
Zero="0"
One="1"
hexFilter=[]
hexCard=[]
hexFCC=[]
justRead=0
j=0
k=0
#Main code
while (1):
    #Reading code
    while (bitCount<27):   
        if GPIO.input(data0)==0:
            dataBits.append(Zero)
            print dataBits
            print "Bitcount %d" % bitCount
            bitCount = bitCount+1
            justRead=1
        if GPIO.input(data1)==0:
            dataBits.append(One)
            print dataBits
            print "Bitcount %d" % bitCount
            bitCount = bitCount+1
            justRead=1   
        if justRead ==1:
            if bitCount>26:
    #Transforming our information into usable bits  
    #Rest of the code just handles the information and prints to a screen. 
    #The issue existed before I wrote the rest of the code

我正在使用一个带电阻的分压电路将5V降到3V,我的数据线和Pi都是一起接地的。

Wiegand HangWiegand错了

编辑:这里解决了

https:/raspberrypi.stackexchange.comquestions42118wegand-gpio-read-not-working-all-the-time-work-most-times-but-hangs-on-some-r。

python-2.7 raspbian raspberry-pi2 gpio
1个回答
0
投票

上次我研究这个问题,是在几年前(2018年左右),结果发现python的速度不够快,无法直接稳定地读取weigand。 那次我最后在RFID阅读器上放了一个arduino,让arduino上的C代码读取weigand,并把数值以ASCII格式通过USBserial放出来。

从我读到的资料来看,用C语言从raspberry pi读取weigand应该是可行的。我来到这个页面是因为我想看看是否有人做了一个pythonC库来读取weigand。 还没找到。

EDIT: 嗯,pigpio看起来好像可以做这个工作。

https:/raspberrypi.stackexchange.comquestions56706raspberry -pi-as-wiegand-device-output-wiegand-to-receiver...

http:/abyz.me.ukrpipigpioexamples.html#pdif2_tx_WD。

© www.soinside.com 2019 - 2024. All rights reserved.