1AdityaX / mfrc522-python

The mfrc522-python library is used to interact with RFID readers that use the MFRC522 chip interfaced with a Raspberry Pi.
https://pypi.org/project/mfrc522-python/
GNU General Public License v3.0
13 stars 4 forks source link

don't block for 700 seconds #7

Closed K-os closed 3 months ago

K-os commented 3 months ago

As mentioned in issue #4 , there is a time.sleep(0.35) in the loop waiting for a tag response. When no tag is present, it blocks the program for 700 seconds. This makes it unusable, to detect when a tag is placed on the reader, especially since, it stays blocked after a tag has appeared.

I think the sleep stems from a misunderstanding of the comments in the Arduino_MFRC522v2 source code: There is a comment in MFRC522v2.cpp:411, that says the whole loop of 2000 iterations takes 35.7 ms (on some Arduino hardware): // 35.7ms and nothing happened. Communication with the MFRC522 might be down.

This implementation did sleep for 350ms on each iteration, 2000 times = 700s. I changed, it to sleep 4 times 10ms, which I guess is close enough to the intended total of 35ms.

1AdityaX commented 3 months ago

did you check your code if it works on mfrc522?? check out line 313 in MFRC522.py It breaks from the loop if it detects a card

K-os commented 3 months ago

Oh, sorry. I just realized, that my "fix" is not necessary any more since the line 313 was fixed in PR #3.

I installed the library from PyPI using PIP, where I got version 0.0.7 with the condition in line 313 is still broken. I patched it locally to reduce the sleep, which also solved the problem for me. When submitting my PR, I just applied my patch to the master branch without realizing it wasn't needed there any more.

So this PR can be closed, but it would be good to update the published version in PyPI.