Search code examples
pythonruntime-errortypeerrorrfid

TypeError and RuntimeError after working fine first run


I am using this Mercury API https://github.com/gotthardp/python-mercuryapi to read RFID tags.

When running the simple example code below, the code produces errors after 1 successful execution:

#!/usr/bin/env python3
from __future__ import print_function
import time
import mercury
reader = mercury.Reader("tmr:///dev/ttyUSB0", baudrate=115200)

print(reader.get_model())
print(reader.get_supported_regions())

reader.set_region("EU3")
reader.set_read_plan([1], "GEN2", read_power=1900)
print(reader.read())

reader.start_reading(lambda tag: print(tag.epc, tag.antenna, tag.read_count, tag.rssi))
time.sleep(1)
reader.stop_reading()

At the first run the code executes fine producing this reading of the RFID tags.

M6e Nano
[u'NA2', u'NA3', u'IN', u'JP', u'PRC', u'EU3', u'KR2', u'AU', u'NZ', u'open']
['E20040057307013122103116']
E20040057307013122103116 1 1 -36
E20040057307013122103116 1 1 -36
E20040057307013122103116 1 1 -36
E20040057307013122103116 1 1 -36

Running it again results in this:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    reader = mercury.Reader("tmr:///dev/ttyUSB0", baudrate=115200)
TypeError: No such file or directory

Running again some times results in this:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    reader = mercury.Reader("tmr:///dev/ttyUSB0", baudrate=115200)
TypeError: Permission denied

Running it then from sudo gives and RuntimeError:

M6e Nano
[u'NA2', u'NA3', u'IN', u'JP', u'PRC', u'EU3', u'KR2', u'AU', u'NZ', u'open']
Traceback (most recent call last):
  File "test.py", line 12, in <module>
    print(reader.read())
RuntimeError: Timeout

Any ideas on how to solve these issues?

Update had the reader turned of for some time and the same behaviour happens again. Works the first time then goes into TypeError. Can it be the path "tmr:///dev/ttyUSB0" changing after first use?

Update tried running it on a Raspberry Pi 3 and I get the same problem. RuntimeError: Timeout


Solution

  • The problem was that the RFID reader did not receive enough power. Instead of 3.3V I provided it with 5V which solved the issue.