2

For my classroom, I have a PN532 NFC card reader/writer hooked up via UART to a Raspberry Pi 2, and I'm using Type 2 NXP NTAG213 NFC cards to store information specifically to the text record. While weak in Python, I used the example under subheader 8.3 in the NFCPy Documentation to write to the card and used "How to redirect 'print' output to a file using python?" in order to complete the output process to a text file. For a while, the reading, writing, and outputting to my text file worked:

import nfc
import nfc.ndef
import nfc.tag
import os, sys
import subprocess
import glob
from os import path
import datetime

f = open('BankTransactions.txt', 'a')
sys.stdout = f

path = '/home/pi/BankTransactions.txt'

def connected(tag): print(tag); return False

clf = nfc.ContactlessFrontend('tty:AMA0:pn532')

clf.connect(rdwr={'on-connect': connected})

tag = clf.connect(rdwr={'on-connect': connected})
record_1 = tag.ndef.message[0]
signature = nfc.tag.tty2_nxp.NTAG213
today = datetime.date.today()

print(record_1.pretty())

if tag.ndef is not None:
    print(tag.ndef.message.pretty())
    if tag.ndef.is_writeable:
        text_record = nfc.ndef.TextRecord("Jessica has 19 GP on card")
        tag.ndef.message = nfc.ndef.Message(text_record)
        print >> f, "Edited by Roman", today, record_1, signature, '\n'
        f.close()

Now, however, when I use the same card for testing, it will not append the data within the text file. The data is still being written to the card, as I can read the information on the card with a simple read program.

Community
  • 1
  • 1

0 Answers0