gpt4 book ai didi

python - 在 Raspi 2 上使用 mxgxw/MFRC522-python 库和 MFRC522 读取器编写 ntag213 (Mifare Ultralight C)

转载 作者:太空宇宙 更新时间:2023-11-03 16:39:48 26 4
gpt4 key购买 nike

对于一个学校项目,我们正在尝试在 ntag213(Mifare Ultralight C 180Bytes)上写入,但我们无法在其上写入。除此之外,该库在读取 Ultralight C/ntag213 方面运行良好。

相同的设置、库和硬件在 Mifare 1K Tags 1024kB 上运行良好。

是否有人已经在 PYTHON 中使用 MFRC522 阅读器和 Mifare Ultralight C 标签 (ntag213) 对此库进行了此操作?

链接:
https://github.com/mxgxw/MFRC522-python http://cache.nxp.com/documents/data_sheet/NTAG213_215_216.pdf?pspll=1

def MFRC522_Write(self, blockAddr, writeData):
buff = []
buff.append(self.PICC_WRITE)
buff.append(blockAddr)
crc = self.CalulateCRC(buff)
buff.append(crc[0])
buff.append(crc[1])
(status, backData, backLen) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE, buff)

#because of a timeout in function ToCard, backdata after this is empty!!!!!!!!!

if not(status == self.MI_OK) or not(backLen == 4) or not((backData[0] & 0x0F) == 0x0A):
status = self.MI_ERR

print str(backLen)+" backdata &0x0F == 0x0A "+str(backData[0]&0x0F)
if status == self.MI_OK:
i = 0
buf = []
while i < 16:
buf.append(writeData[i])
i = i + 1
crc = self.CalulateCRC(buf)
buf.append(crc[0])
buf.append(crc[1])
(status, backData, backLen) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE,buf)
if not(status == self.MI_OK) or not(backLen == 4) or not((backData[0] & 0x0F) == 0x0A):
print "Error while writing"
if status == self.MI_OK:
print "Data written"

因此我们正在研究 ToCard 函数来搜索错误:

def MFRC522_ToCard(self,command,sendData):
backData = []
backLen = 0
status = self.MI_ERR
irqEn = 0x00
waitIRq = 0x00
lastBits = None
n = 0
i = 0

if command == self.PCD_AUTHENT:
irqEn = 0x12
waitIRq = 0x10
if command == self.PCD_TRANSCEIVE:
irqEn = 0x77
waitIRq = 0x30

self.Write_MFRC522(self.CommIEnReg, irqEn|0x80)
self.ClearBitMask(self.CommIrqReg, 0x80)
self.SetBitMask(self.FIFOLevelReg, 0x80)

self.Write_MFRC522(self.CommandReg, self.PCD_IDLE);

while(i<len(sendData)):
self.Write_MFRC522(self.FIFODataReg, sendData[i])
i = i+1

self.Write_MFRC522(self.CommandReg, command)

if command == self.PCD_TRANSCEIVE:
self.SetBitMask(self.BitFramingReg, 0x80)
#!!!!!!!!!!!!!!!!!!!!!!!!!!!
# as we saw in the data sheet we figured out that until here everything looks correctly.
# despite of this fact self.Read_MFRC522(self.CommIrqReg) never gets an ACK
#!!!!!!!!!!!!!!!!!!!!!!!!!!!
i = 2000
while True:
n = self.Read_MFRC522(self.CommIrqReg)
i = i - 1
if ~((i!=0) and ~(n&0x01) and ~(n&waitIRq)):
break

self.ClearBitMask(self.BitFramingReg, 0x80)

if i != 0:
if (self.Read_MFRC522(self.ErrorReg) & 0x1B)==0x00:
status = self.MI_OK

if n & irqEn & 0x01:
status = self.MI_NOTAGERR

if command == self.PCD_TRANSCEIVE:
n = self.Read_MFRC522(self.FIFOLevelReg)
lastBits = self.Read_MFRC522(self.ControlReg) & 0x07
if lastBits != 0:
backLen = (n-1)*8 + lastBits
else:
backLen = n*8

if n == 0:
n = 1
if n > self.MAX_LEN:
n = self.MAX_LEN

i = 0
while i<n:
backData.append(self.Read_MFRC522(self.FIFODataReg))
i = i + 1;
else:
status = self.MI_ERR

return (status,backData,backLen)

最佳答案

我正在尝试做同样的事情,这可能与超轻卡不需要授权这一事实有关。至于你突出显示的代码位置,我suggest重写它

        while True:
n = self.dev_read(0x04)
if n == 0:
continue # Too fast
if n & irq_wait:
break # Got it!
if n & 0x01:
error = True
break # The timer decrements the timer value in register TCounterValReg to zero

关于python - 在 Raspi 2 上使用 mxgxw/MFRC522-python 库和 MFRC522 读取器编写 ntag213 (Mifare Ultralight C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36915264/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com