def listen(self, target, timeout):
"""Listen for *timeout* seconds to become initialized as a
*target*. The *target* must be one of :class:`nfc.clf.TTA`,
:class:`nfc.clf.TTB`, :class:`nfc.clf.TTF`, or
:class:`nfc.clf.DEP` (note that target type support depends on
the hardware capabilities). The return value is :const:`None`
if *timeout* elapsed without activation or a tuple (target,
command) where target is the activated target (which may
differ from the requested target, see below) and command is
the first command received from the initiator.
If an activated target is returned, the target type and
attributes may differ from the *target* requested. This is
especically true if activation as a :class:`nfc.clf.DEP`
target is requested but the contactless frontend does not have
a hardware implementation of the data exchange protocol and
returns a :class:`nfc.clf.TTA` or :class:`nfc.clf.TTF` target
instead.
.. note:: This is a direct interface to the
driver and not needed if :meth:`connect` is used.
"""
if self.dev is None:
raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))
with self.lock:
log.debug("listen for {0:.3f} sec as target {1}"
.format(timeout, target))
if type(target) is TTA:
return self.dev.listen_tta(target, timeout)
if type(target) is TTB:
return self.dev.listen_ttb(target, timeout)
if type(target) is TTF:
return self.dev.listen_ttf(target, timeout)
if type(target) is DEP:
return self.dev.listen_dep(target, timeout)
评论列表
文章目录