2015-02-09 20 views
6

Sto cercando di leggere un tag ISO15693 RFID con la tecnologia NFC libreria Android:Android NFC leggere ISO15693 tag RFID

Ecco maggiori informazioni sul Tag: http://img42.com/gw07d+

L'ID tag viene letto correttamente, ma i dati nel tag non lo è.

onCreate Metodo:

// initialize NFC 
    nfcAdapter = NfcAdapter.getDefaultAdapter(this); 
    nfcPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, this.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); 

onNewIntent metodo:

if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction()) || NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) { 

     currentTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); 
     byte[] id = currentTag.getId(); 
     Tag_data_TextDisplay.setText("TagId:" + Common.getHexString(id)); 

     for (String tech : currentTag.getTechList()) { 

      if (tech.equals(NfcV.class.getName())) { 
       NfcV nfcvTag = NfcV.get(currentTag); 

       try { 
        nfcvTag.connect(); 
        txtType.setText("Hello NFC!"); 
       } catch (IOException e) { 
        Toast.makeText(getApplicationContext(), "Could not open a connection!", Toast.LENGTH_SHORT).show(); 
        return; 
       } 

       try { 
        byte[] cmd = new byte[]{ 
          (byte) 0x00, // Flags 
          (byte) 0x23, // Command: Read multiple blocks 
          (byte) 0x00, // First block (offset) 
          (byte) 0x04 // Number of blocks 
        }; 
        byte[] userdata = nfcvTag.transceive(cmd); 

        userdata = Arrays.copyOfRange(userdata, 0, 32); 
        txtWrite.setText("DATA:" + Common.getHexString(userdata)); 

       } catch (IOException e) { 
        Toast.makeText(getApplicationContext(), "An error occurred while reading!", Toast.LENGTH_SHORT).show(); 
        return; 
       } 
      } 
     } 
    } 

userdata è contiene un singolo byte con il valore 0x02 ({ 0x02 }) subito dopo il metodo ricetrasmettitore finito.

+0

e cosa dovrebbe leggere? –

+0

@RandykaYudhistira Dove ho letto il tag http://img42.com/mHBPa+ – yoshgoodman

+0

Sarebbe utile se potesse mostrarci il risultato effettivo di 'nfcvTag.transceive (cmd);' (senza riempimento a 32 byte). Inoltre, potresti assicurarti che il tuo array di byte in conversione esadecimale riempia ogni byte a due cifre esadecimali (altrimenti sarà difficile interpretarne il valore). –

risposta

2

Quindi si riceve un valore di { 0x02 } dal metodo transceive. Come trovato in this thread questo può accadere quando si usano comandi non indirizzati. Pertanto, è necessario inviare sempre i comandi indirizzati tramite NfcV (poiché questo sembra essere supportato su tutti i chipset NFC su dispositivi Android). Nel tuo caso, potresti usare qualcosa come questo per generare un comando READ MULTIPLE BLOCKS:

int offset = 0; // offset of first block to read 
int blocks = 1; // number of blocks to read 
byte[] cmd = new byte[]{ 
     (byte)0x60,     // flags: addressed (= UID field present) 
     (byte)0x23,     // command: READ MULTIPLE BLOCKS 
     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, // placeholder for tag UID 
     (byte)(offset & 0x0ff),  // first block number 
     (byte)((blocks - 1) & 0x0ff) // number of blocks (-1 as 0x00 means one block) 
}; 
System.arraycopy(id, 0, cmd, 2, 8); 
byte[] response = nfcvTag.transceive(cmd); 
+0

Grazie, questo funziona – yoshgoodman

+0

Cosa fa 'System.arraycopy (id, 0, cmd, 2, 8); 'fare? – yoshgoodman

+0

Come spiegato nella documentazione Java: "* Copie [8] elementi dall'array [' id'], a partire dall'offset [0], nell'array ['cmd'], a partire dall'offset [2]. *" –