atitan/MFRC522_Ruby

Potential un-handled error when reading card (nil bytes)

Closed this issue · 4 comments

Sometimes I got following error when reading a card

mfrc522-1.0.4/lib/mfrc522.rb:259:in `^': nil can't be coerced into Fixnum (TypeError)

Maybe there should be a error handler to handle this issue?

Sure, the buffer is not verified for valid content before doing XOR.

I've made a patch fbc0d27 to handle this situation.
Take a look and tell me what you think.

I have no devices at hand now. Thus I cannot test whether the code is correct or not.
I am wandering that the code in the new patch is trying to fetch all data before it exits the loop.
Will that operation hang the execution? Maybe you need to handle the timeout.
Namely, report an error when the card is no longer readable.

The patch didn't change the loop behavior. It only verifies the buffer when UID is thought to be completed, and clears the buffer if something went wrong.

For each cascade level, loops are hardcoded to be up to 32 according to ISO spec. Clearing the buffer during a loop does not reset the counter, so the timeout mechanism will not be bypassed.