Page 1 of 1

RFID Tag value import problems

Posted: Tue Nov 28, 2017 5:09 pm
by MarvinMcFly
Hey folks,

I'm writing a little program using the RFID libary from Github(https://github.com/mxgxw/MFRC522-python). When I extract the data from the tag and convert it into an integer to work with it I get an Error like this

Code: Select all

ValueError: invalid literal for int(): 10
I know why I get this error. The reason is how the string realy looks like. With an "print()" it shows me a 10 but with "print(repr())"
'10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
I also know that \x00 stands for Null in HEX, and I also found a solution to solve the problem. My actual code snipped is

Code: Select all

DecimalValueCard= MIFAREReader.MFRC522_Read(BlockID)
Variable = ''.join(chr(i) for i in DecimalValueCard)
print(repr(Variable .strip('\x00')))
print(repr(Variable .strip("'")))
print(repr(Variable ))
Now to my question: Is there any better/other solution to get and clean string from the card without "\x00"?

Re: RFID Tag value import problems

Posted: Tue Nov 28, 2017 5:27 pm
by DougieLawson
I turn my RFID card IDs into an eight character hex string.

Code: Select all

    # Get the UID of the card
    (status,uid) = MIFAREReader.MFRC522_Anticoll()
    token_id = str(uid[0:4])

    if status == MIFAREReader.MI_OK:
        hexUid=""
        for val in uid[0:4]:
            hexUid = hexUid+"{:02x}".format(val)

Re: RFID Tag value import problems

Posted: Tue Nov 28, 2017 8:28 pm
by OutoftheBOTS
I was reading my data from the RFID tags as a byte array then I could just put together which bytes that I wanted as what I wanted :)