Open tlongeri opened 6 years ago
Just wanted to open a new feature request for rdr.wait_for_tag(timeout=10)
.
So GitHub "similar issues" works 😃
Hi @ondryaso, @jo-me ,
wait_for_tag now returns after timeout seconds but unfortunatelly there is no way to know whether it returned normally or because the time out. In case there is a timeout when i call self._reader.request() I would get an error.
Would be possible to use a Timeout Exception so you can handle the timeout in the caller method. Something like this:
try:
self._reader.wait_for_tag(timeout=1)
except TimeoutError:
return None
error, tag_type = self._reader.request()
if error:
raise RfidReadException("Error reading rfid tag")
def wait_for_tag(self, timeout=None):
if self.pin_irq is None:
raise NotImplementedError('Waiting not implemented if IRQ is not used')
# enable IRQ on detect
self.init()
self.irq.clear()
self.dev_write(0x04, 0x00)
self.dev_write(0x02, 0xA0)
# wait for it
start_time = time.time()
waiting = True
while waiting:
if timeout and (time.time() - start_time) >= timeout:
raise TimeoutError
self.init()
self.dev_write(0x04, 0x00)
self.dev_write(0x02, 0xA0)
self.dev_write(0x09, 0x26)
self.dev_write(0x01, 0x0C)
self.dev_write(0x0D, 0x87)
waiting = not self.irq.wait(0.1)
self.irq.clear()
self.init()
Should i raise a new issue or could this be reopened ?
It would be nice to have a timeout argument on the
wait_for_tag
function. I'm using it to listen for tags on a looping thread that checks on a 'global' exit flag at each loop, but sincewait_for_tag
can never exit I have no nice way of killing it so I was forced to make my own modified version.It should be a simple change, like this:
It's just a little detail that would improve usability.