2016-11-25 3 views
1

Je suis en train d'écrire des données à une étiquette ICODE NXP SLIX SL2S2002 (ISO 15693) en utilisant la commande BLOCS MULTIPLES WRITE à travers l'objet NfcV:Ecriture de plusieurs blocs de commande basculées NfcV

private void writeTagData(Tag tag) throws Exception { 
    int offset = 0; 
    int blocks = 19; 

    String _writedata = "1hello34567850000071234561815064150220161603201016022018112233445552031033"; 
    byte[] data = _writedata.getBytes(StandardCharsets.UTF_8); 
    data = Arrays.copyOfRange(data, 0, 4 * blocks); 

    byte[] id = tag.getId(); 
    boolean techFound = false; 
    for (String tech : tag.getTechList()) { 
     if (tech.equals(NfcV.class.getName())) { 
      techFound = true; 
      NfcV nfcvTag = NfcV.get(tag); 
      try { 
       nfcvTag.connect(); 
      } catch (IOException e) { 
       Toast.makeText(this, "IO Exception", Toast.LENGTH_LONG).show(); 
       return; 
      } 
      try { 
       byte[] cmd = new byte[] { 
         (byte)0x20, 
         (byte)0x24, 
         (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, 
         (byte)(offset & 0x0ff), 
         (byte)((blocks - 1) & 0x0ff) 
       }; 
       System.arraycopy(id, 0, cmd, 2, 8); 

       byte[] cmd_plus_data = new byte[88]; 
       System.arraycopy(cmd, 0, cmd_plus_data, 0, cmd.length); 
       System.arraycopy(data, 0, cmd_plus_data, 12, data.length); 

       byte[] response = nfcvTag.transceive(cmd_plus_data); 
       String strResponse = Common.toHexString(response); 
      } catch (IOException e) { 
       Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); 
       return; 
      } 

      try { 
       nfcvTag.close(); 
      } catch (IOException e) { 
       Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); 
       return; 
      } 
     } 
    } 
} 

La réponse de la La méthode transceive(...) est 010f (indiquant "Erreur inconnue"). Auparavant, j'étais capable de lire des données en utilisant la commande READ MULTIPLE BLOCKS de la même balise avec succès.

I a essayé de faire appel getMaxTransceiveLength() sur l'objet NfcV et la valeur est 253.

+0

À quel produit d'étiquette spécifique voulez-vous écrire? Étant donné que vous avez indiqué une valeur d'étiquette UID de 'e004015057da807b' dans un post précédent, je suppose que c'est un NXP ICODE SLIX SL2S2xx2, non? –

+0

NXP ICODE SLIX SL2S2002 – ibrahim

Répondre

2

ISO/IEC 15693 définit les blocs de commandes d'écriture MULTIPLES commande en option. C'est à la puce de l'étiquette (ou en fait à son fabricant) d'implémenter cette commande.

Dans votre cas, le NXP ICODE SLIX SL2S2xx2 (comme tous les tags (les plus courants?) ICODE SLI/SLIX) ne prend pas en charge la commande WRITE MULTIPLE BLOCKS. Par conséquent, la balise renvoie le code d'erreur 0x0F. La fiche technique ICODE SLIX SL2S2xx2 définit que ce code d'erreur est renvoyé au cas où une commande n'est pas prise en charge. Au lieu de cela, le SL2S2xx2 prend en charge la commande WRITE SINGLE BLOCK (0x21). Vous pouvez utiliser cette commande dans une boucle pour écrire toutes vos données:

byte[] cmd = new byte[] { 
     /* FLAGS */ (byte)0x20, 
     /* COMMAND */ (byte)0x21, 
     /* UID  */ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, 
     /* OFFSET */ (byte)0x00, 
     /* DATA */ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 
}; 
System.arraycopy(id, 0, cmd, 2, 8); 

for (int i = 0; i < blocks; ++i) { 
    cmd[10] = (byte)((offset + i) & 0x0ff); 
    System.arraycopy(data, 4 * i, cmd, 11, 4); 

    byte[] response = nfcvTag.transceive(cmd); 
}