MarvinMcFly
Posts: 3
Joined: Sat Nov 11, 2017 7:34 am
Location: Germany

RFID Tag value import problems

Tue Nov 28, 2017 5:09 pm

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"?

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: RFID Tag value import problems

Tue Nov 28, 2017 5:27 pm

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)
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: RFID Tag value import problems

Tue Nov 28, 2017 8:28 pm

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 :)

Return to “Python”