这是我已经使用的 Raspberry Pi 上的 RFID wiegand 阅读器的代码片段。
def main():
set_procname("Wiegand Reader")
global bits
global timeout
GPIO.add_event_detect(D0, GPIO.FALLING, callback=one)
GPIO.add_event_detect(D1, GPIO.FALLING, callback=zero)
GPIO.add_event_detect(S1, GPIO.FALLING, callback=unlockDoor)
while 1:
if bits:
timeout = timeout -1
time.sleep(0.001)
if len(bits) > 1 and timeout == 0:
#print "Binary:", int(str(bits),2)
c1 = int(str(bits),2)
result = ((~c1) >> 1) & 0x0FFFFFF;
checkAccess(result, doorID)
else:
time.sleep(0.001)
if __name__ == '__main__':
main()
在普通的 USB RFID 阅读器上,我得到 0000119994,这就是卡上打印的内容。但是使用此代码,它显示为 119994。我尝试了多张卡。它总是将零放在前面。
我什至尝试了一张里面有零的卡片。0000120368,它显示 120368 我以为它正在删除前 4 个字符,但后来我尝试了一个前面只有 3 个零的密钥卡。0004876298,它读取 4876298。只删除前面的零。