我有一张NTAG213
NFC贴纸。我想知道怎样才能使这个贴纸成为只读的。如果以后我切换到NTAG215
,如何使该标记为只读。实际制作不同类型的只读标签所涉及的过程是什么。当我说只读时,我的意思是NFC的记录永远不能被修改,但是设备仍然可以在没有身份验证的情况下读取记录
我阅读了https://answers.launchpad.net/nfcpy/+question/242606,并试图实现它的解决方案
import nfc
from time import sleep
from nfc.clf import RemoteTarget
import ndef
clf = nfc.ContactlessFrontend('usb')
while True:
target = clf.sense(RemoteTarget('106A'), RemoteTarget('106B'), RemoteTarget('212F'))
if target is None:
sleep(1)
continue
serial = target.sdd_res.hex()
tag = nfc.tag.activate(clf, target)
if not tag.ndef:
print("No NDEF records found!")
continue
for record in tag.ndef.records:
print("Found record: " + str(record))
record = ndef.UriRecord("https://www.example.com")
tag.ndef.records = [record]
# Code is fine until it gets to these tag indexes
tag[15] = tag[15] | 0x0F
tag[10] = 0xFF
tag[11] = 0xFF
我得到一个错误:
File "test.py", line 26, in <module>
tag[15] = tag[15] | 0x0F
TypeError: 'NTAG213' object does not support indexing
看看Python库,它有一个简单的方法,可以使用锁字节或通过密码使其成为只读
https://nfcpy.readthedocs.io/en/stable-0.10/modules/tag.html#nfc.tag.tt2_nxp.NTAG21x
只需在
tag
对象上调用protect
方法,使用或不使用密码即可(不使用密码将使用锁字节,并且是永久只读的)因此,该库已在其中编程正确的内存地址和位,以翻转各种卡,包括所有NTAG21x卡
相关问题 更多 >
编程相关推荐