我是在韩国开发的开发人员。我创建了一个使用python pyscard和tkinter来更新或查询RF标签中的二进制块的程序。 该程序运行良好。但是,有时卡上的二进制块更改为0或255。 这种现象主要发生在快速取出存储卡或不稳定读取存储卡时。 RF阅读器将给出更新失败标志,但二进制块已被初始化为0或255。我想知道是否有防止这种情况的方法。有人有与您相似或相似的症状吗?
项目中使用的资源
RF阅读器:ACS-1256U
Python:3.6
OS:Raspberry Pi 3b + / Raspbian-拉伸
我们实现了一个简单的事务,以在失败时重新读取二进制块,但是二进制块读取操作失败,并且该事务无法实现。
class transmitobserver(CardObserver):
UID_BYTE = [0xFF, 0xCA, 0x00, 0x00, 0x04] # uid byte
LOAD_KEY_SELECT = [0xFF, 0x82, 0x00, 0x00, 0x06] # load key select
AUTH_SELECT = [0xFF, 0x86, 0x00, 0x00, 0x05] # auth select
AUTH_DF = [0x01, 0x00, 0x00, 0x60, 0x00] # auth df
READ_BINARY_SELECT = [0xFF, 0xB0, 0x00, 0x01, 0x10] # read binary block select
UPDATE_BINARY_SELECT = [0xFF, 0xD6, 0x00, 0x01, 0x10] # update binary block select
def __init__(self):
self.cards = []
def update(self, observable, actions):
key = "00000000"
arg1 = int(key[0:2], 16)
arg2 = int(key[2:4], 16)
arg3 = int(key[4:6], 16)
arg4 = int(key[6:8], 16)
arg5 = int(key[8:10], 16)
arg6 = int(key[10:12], 16)
LOAD_KEY_DF = [arg1, arg2, arg3, arg4, arg5, arg6] #load key set
(addedcards, removedcards) = actions
for card in addedcards:
if card not in self.cards:
self.cards += [card]
try:
r = readers()
if str(card.reader) == str(r[0]):
card.connection = card.createConnection()
card.connection.connect()
serial_number, sw1, sw2 = card.connection.transmit(self.UID_BYTE)
if serial_number and len(serial_number) > 2:
response, is_load_key, sw2 = card.connection.transmit(self.LOAD_KEY_SELECT + LOAD_KEY_DF) # LOAD KEY
# LOAD KEY success
if is_load_key == 144:
response, is_authentication, sw2 = card.connection.transmit(self.AUTH_SELECT + self.AUTH_DF) # AUTHENTICATION
# AUTHENTICATION success
if is_authentication == 144:
binary_block, sw1, sw2 = card.connection.transmit(self.READ_BINARY_SELECT) # read Number 1 binary block
if binary_block and len(binary_block) > 2:
set_req_byte = [0x00, 0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, 0xAA, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
# update binary block !!!!!@@@@@ prob code @@@@@@!!!!!
response, set1, set2 = card.connection.transmit(self.UPDATE_BINARY_SELECT + set_req_byte)
if set1 == 144:
# success update binary block
# read binary block
response, sw1, sw2 = card.connection.transmit(self.READ_BINARY_SELECT)
card.connection.disconnect()
else:
# failed update binary block
# read binary block
# then binary block has 0 or 255
response, sw1, sw2 = card.connection.transmit(self.READ_BINARY_SELECT)
print(response) # response has [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] or [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, ]
card.connection.disconnect()
else:
card.connection.disconnect()
else:
card.connection.disconnect()
else:
card.connection.disconnect()
else:
pass
except Exception as e:
print(e) #not except
for card in removedcards:
if card in self.cards:
self.cards.remove(card)
读卡时二进制块变为0或255。