def _read_block(self, block):
"""Reads a block from a Mifare Card after authentication
Returns the data read or raises an exception
"""
if nfc.nfc_device_set_property_bool(self.__device, nfc.NP_EASY_FRAMING, True) < 0:
raise Exception("Error setting Easy Framing property")
abttx = (ctypes.c_uint8 * 2)()
abttx[0] = self.MC_READ
abttx[1] = block
abtrx = (ctypes.c_uint8 * 250)()
res = nfc.nfc_initiator_transceive_bytes(self.__device, ctypes.pointer(abttx), len(abttx),
ctypes.pointer(abtrx), len(abtrx), 0)
if res < 0:
raise IOError("Error reading data")
return "".join([chr(abtrx[i]) for i in range(res)])
评论列表
文章目录