# Read the length of the SYSTEM file (should be 0x0012) wait("read system file length") len = tag.readBinary(0x00, 0x02) print("len:" + str(len)) # Read the memory size field in the SYSTEM file (shoudl be 0x1FFF eeprom size) wait("read eeprom size from system file") memsize = tag.readBinary(0x000F, 0x02) print("memsize:" + str(memsize)) # Deselect the tag and release the token (RF can now use it) wait("deselect") tag.deselect() try: wait("init I2C") i2c.initDefaults() # Loop around repeatedly running the test # This makes it easy to see things on the logic analyser while True: test() finally: # Clean up I2C before exit wait("cleaning up") i2c.finished() # END
def test_AN4433seq(): import ci2c as i2c class DummyI2C(): def initDefaults(self): pass def write(self, addr, msg): pass #print("write") def read(self, addr, len): pass #print("read") def finished(self): pass #i2c = DummyI2C() i2c.initDefaults() tag = NFCTag(i2c) # READ MEMORY SIZE REGISTER FROM SYSTEM FILE # kill off any RF session, and open an I2C session, claiming the token. wait("select I2C") tag.killRFSelectI2C() # select NFC application wait("select NFC application") tag.selectNFCT4Application(pcb=0x02) # Select the CC file wait("select CC file") tag.selectFile(tag.CC, pcb=0x03) # read CC file length wait("read CC file len") data = tag.readBinary(0x0000, 0x02, pcb=0x02) print(tohex(data)) # read CC file wait("read CC file") data = tag.readBinary(0x0000, 0x0F, pcb=0x03) print(data) print(tohex(data)) # select NDEF file wait("select NDEF file") tag.selectFile(tag.NDEF, pcb=0x02) # read NDEF message length wait("read NDEF message len") data = tag.readBinary(0x0000, 0x02, pcb=0x03) print(tohex(data)) ndef_len = (data[1] * 256) + data[2] print("NDEF len:" + str(ndef_len)) # read NDEF file wait("read NDEF message") data = tag.readBinary(0x0002, ndef_len, pcb=0x02) print(tohex(data)) ndef = data[6:-4] s = "" for i in range(len(ndef)): s += chr(ndef[i]) print("ndef:" + s) # Deselect the tag and release the token (RF can now use it) wait("deselect") tag.deselect() i2c.finished()
#=============================================================================== # SETUP try: import ci2c # python2 except ImportError: from . import ci2c # python3 import time CMD_SELECT_MIFARE = 0x01 CMD_GET_FIRMWARE = 0xF0 WR_RD_DELAY = 0.05 ci2c.initDefaults() #=============================================================================== # UTILITIES def typename(type): if (type == 0x01): return "mifare 1k, 4byte UID" elif (type == 0x02): return "mifare 1k, 7byte UID" elif (type == 0x03): return "mifare UltraLight, 7 byte UID" elif (type == 0x04): return "mifare 4k, 4 byte UID" elif (type == 0x05):
def test_AN4433seq(): import ci2c as i2c class DummyI2C(): def initDefaults(self): pass def write(self, addr, msg): pass#print("write") def read(self, addr, len): pass#print("read") def finished(self): pass #i2c = DummyI2C() i2c.initDefaults() tag = NFCTag(i2c) # READ MEMORY SIZE REGISTER FROM SYSTEM FILE # kill off any RF session, and open an I2C session, claiming the token. wait("select I2C") tag.killRFSelectI2C() # select NFC application wait("select NFC application") tag.selectNFCT4Application(pcb=0x02) # Select the CC file wait("select CC file") tag.selectFile(tag.CC, pcb=0x03) # read CC file length wait("read CC file len") data = tag.readBinary(0x0000, 0x02, pcb=0x02) print(tohex(data)) # read CC file wait("read CC file") data = tag.readBinary(0x0000, 0x0F, pcb=0x03) print(data) print(tohex(data)) # select NDEF file wait("select NDEF file") tag.selectFile(tag.NDEF, pcb=0x02) # read NDEF message length wait("read NDEF message len") data = tag.readBinary(0x0000, 0x02, pcb=0x03) print(tohex(data)) ndef_len = (data[1]*256) + data[2] print("NDEF len:" + str(ndef_len)) # read NDEF file wait("read NDEF message") data = tag.readBinary(0x0002, ndef_len, pcb=0x02) print(tohex(data)) ndef = data[6:-4] s = "" for i in range(len(ndef)): s += chr(ndef[i]) print("ndef:" + s) # Deselect the tag and release the token (RF can now use it) wait("deselect") tag.deselect() i2c.finished()