__init__.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:nfcpy 作者: nfcpy 项目源码 文件源码
def exchange(self, send_data, timeout):
        """Exchange data with an activated target (*send_data* is a command
        frame) or as an activated target (*send_data* is a response
        frame). Returns a target response frame (if data is send to an
        activated target) or a next command frame (if data is send
        from an activated target). Returns None if the communication
        link broke during exchange (if data is sent as a target). The
        timeout is the number of seconds to wait for data to return,
        if the timeout expires an nfc.clf.TimeoutException is
        raised. Other nfc.clf.CommunicationError exceptions may be raised if
        an error is detected during communication.

        """
        with self.lock:
            if self.device is None:
                raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))

            log.debug(">>> %s timeout=%s", print_data(send_data), str(timeout))

            if isinstance(self.target, RemoteTarget):
                exchange = self.device.send_cmd_recv_rsp
            elif isinstance(self.target, LocalTarget):
                exchange = self.device.send_rsp_recv_cmd
            else:
                log.error("no target for data exchange")
                return None

            send_time = time.time()
            rcvd_data = exchange(self.target, send_data, timeout)
            recv_time = time.time() - send_time

            log.debug("<<< %s %.3fs", print_data(rcvd_data), recv_time)
            return rcvd_data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号