【发布时间】:2023-03-16 23:18:01
【问题描述】:
我正在尝试将 NDEF 数据写入 NFC 标签(Mifare S50 芯片),以便它可以与我的 iPhone 配合使用,我正在使用 Raspberry Pi 4 和通过 GPIO 连接的 RC522 NFC 模块并使用 SPI。
我尝试了几种方法,最后得到了上面的代码,它似乎没有向标签写入任何内容,而且我的手机确实无法读取它,我想我可能在某个地方搞砸了。
代码如下:
#!/usr/bin/env python
import RPi.GPIO as GPIO
import ndef
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
try:
message = [ndef.TextRecord("Hello"), ndef.TextRecord("World")]
print("Approach a tag to the reader")
reader.write(b''.join(ndef.message_encoder(message)))
print("Written")
finally:
GPIO.cleanup()
这是控制台输出:
Traceback (most recent call last):
File "Write.py", line 12, in <module>
reader.write(b''.join(ndef.message_encoder(message)))
File "/usr/local/lib/python3.7/dist-packages/mfrc522/SimpleMFRC522.py", line 62, in write
id, text_in = self.write_no_block(text)
File "/usr/local/lib/python3.7/dist-packages/mfrc522/SimpleMFRC522.py", line 78, in write_no_block
data.extend(bytearray(text.ljust(len(self.BLOCK_ADDRS) * 16).encode('ascii')))
AttributeError: 'bytes' object has no attribute 'encode'
【问题讨论】:
标签: python raspberry-pi nfc ndef