def __write_block(self, block, data):
"""Writes a block of data to a Mifare Card after authentication
Raises an exception on error
"""
if nfc.nfc_device_set_property_bool(self.__device, nfc.NP_EASY_FRAMING, True) < 0:
raise Exception("Error setting Easy Framing property")
if len(data) > 16:
raise ValueError("Data value to be written cannot be more than 16 characters.")
abttx = (ctypes.c_uint8 * 18)()
abttx[0] = self.MC_WRITE
abttx[1] = block
abtrx = (ctypes.c_uint8 * 250)()
for i in range(16):
abttx[i + 2] = ord((data + "\x00" * (16 - len(data)))[i])
return nfc.nfc_initiator_transceive_bytes(self.__device, ctypes.pointer(abttx), len(abttx),
ctypes.pointer(abtrx), len(abtrx), 0)
评论列表
文章目录