#hardware
#setup
brew install libusb
pip3 install nfcpy
#script
公式のものを改変
nfcwriter.py
import nfc
import sys
def on_connect(tag):
global data
if tag.ndef is not None:
for record in tag.ndef.records:
print(record)
if tag.ndef.is_writeable:
from ndef import TextRecord
tag.ndef.records = [TextRecord(data)]
print("write complete")
def main():
with nfc.ContactlessFrontend("usb") as clf:
rdwr = {
'on-connect': on_connect
}
clf.connect(rdwr=rdwr)
if __name__ == '__main__':
global data
if len(sys.argv) > 1:
data=sys.argv[1]
print("Put NFC-Tag")
main()
else:
print("Need Record-Text")
#実行
python3 nfcwriter.py helloworld