1

I have an USB RFID reader (EF4100 125kHz) connected to Raspberry Pi 4 Model B. The RFID reader is act like a keyboard and it read the first 10 digit. When I debugging the code with Thonny. At the "buffer = f.read(8)" row reading the card ID code and write the 10 digit code in the shell window, but not step to the next program row. Every time I touch the card to the reader, it reads the card code as many times and write it in the shell window but does not continue in the program. What could be the problem?

Here is my code:

NUMBERS = {30: '1', 31: '2', 32: '3', 33: '4', 34: '5', 35: '6', 36: '7', 37: '8', 38: '9', 39: '0'}
ENDFLAG = 40


def read_rfid():
    try:
        with open('/dev/hidraw0', 'rb') as f:
            print("Tedd oda a kartyat")
            READING = True
            ID=""
            while READING:
                buffer = f.read(8)
                print("Reading")
                for c in buffer:
                    if c == ENDFLAG:
                        READING = False
                    elif c > 0:
                        ID = ID + NUMBERS[c]
                    rfid_number = ID.hex().upper()
                    print(f"Kartya szama: {rfid_number}")
    except Exception as e:
        print(f"Hiba {e}")
        
if __name__ == "__main__":
    read_rfid()

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.