acr122.py 文件源码

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

项目:bitpay-brick 作者: javgh 项目源码 文件源码
def command(self, cmd_code, cmd_data=None, timeout=100):
        """Send a chip command and return the chip response."""
        cmd_name = self.CMD.get(cmd_code, "PN53x 0x{0:02X}".format(cmd_code))
        log.debug("{0} called with timeout {1} ms".format(cmd_name, timeout))

        if cmd_data is None: cmd_data = ""
        frame = bytearray([0xD4, cmd_code]) + bytearray(cmd_data)
        frame = bytearray([0xFF, 0x00, 0x00, 0x00, len(frame)]) + frame
        frame = bytearray([0x6B, len(frame)] + 8 * [0x00]) + frame

        self.transport.write(frame)
        frame = self.transport.read(timeout)

        if len(frame) < 14:
            strerror = os.strerror(errno.EIO) + " - Received frame too short"
            raise IOError(errno.EIO, strerror)
        if frame[0] != 0x83:
            strerror = os.strerror(errno.EIO) + " - Unexpected start of frame"
            raise IOError(errno.EIO, strerror)
        if frame[-2] == 0x63:
            strerror = os.strerror(errno.EIO) + " - No response from PN53X"
            raise IOError(errno.EIO, strerror)

        return frame[12:-2]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号