1. Download our Official Android App: Forums for Android!

Problems reading a NfcV Tag

Discussion in 'Android Development' started by Kellrkind, Oct 10, 2017.

  1. Kellrkind

    Kellrkind Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    3
    Joined:
    Oct 10, 2017

    Oct 10, 2017
    3
    2
    6
    Male
    Hello :)

    I'm new here and i hope you can help me with my problem writing an application for our guild.

    We want to optimize our membership administration on our trips we're doing during the karneval in Germany.
    I've completed nearly every feature but in the case 'NFC Tag Reading' I can't get any further.

    So maybe you can help me. Googled nearly everything but can't find a solution which helps me.
    The situation:

    The tag i need to read from is a NfcV Tag. It was implemented along with a professional reading 'computer'.
    When i want to read this tag with a usual NFC Reading App this is the result:

    Tag ID (hex): e0 04 03 50 00 57 c2 a3
    Tad ID (dec): -2304713467168832861
    ID (reversed): -66466544411911439136
    Technologies: NfcV, NdefFormatable

    I implemented several solutions but the best I've been able to read was this:
    a3 c2 57 00 50 03 04 e0

    It's the hex-ID backwords. The output i want to recieve is just '89'. As simple as it sounds but as difficult it is for me.
    Do you have any suggestions which should be the next step to get this information out of the tag. Maybe i'm on the wrong way with the hex-ID...

    Here's a the code for the reader:

    Code (Text):
    1.             nfcv.connect();
    2.             byte[] tagID = nfcv.getTag().getId();
    3.             String tagInhalt = getHex(tagID);
    4.             Log.d("Hex ID", tagInhalt);
    5.             String message = new String(tagInhalt);
    Found some ways to try reading the tag:
    From on programcreek a proposal but can't link it. Got problems with the VotarProtocol mVotarProtocol; Can't import it:
    Code (Text):
    1. public void onTagDiscovered(Tag tag) {
    2.     Log.i(TAG, "New tag discovered");
    3.     Log.i(TAG, "Tag: " + VotarProtocol.BuildTagId(tag.getId(),0));
    4.     VotarProtocol mVotarProtocol;
    5.     NfcV nfcvTag = NfcV.get(tag);
    6.     if (nfcvTag != null) {
    7.         mVotarProtocol = new VotarProtocol();
    8.         try {
    9.             // Connect to the remote NFC device
    10.             // set up read command buffer
    11.             nfcvTag.connect();
    12.  
    13.             mVotarProtocol.setSystemInfo(nfcvTag.transceive(getCommand(tag.getId(), true)));
    14.  
    15.             Log.i(TAG, "-----------------------");
    16.             Log.i(TAG, "Tag ID: " + mVotarProtocol.tagID());
    17.             Log.i(TAG, "-----------------------");
    18.             byte[] xdata = nfcvTag.transceive(getCommand(tag.getId(), false));
    19.             mVotarProtocol.setBallotData(xdata);
    20.  
    21.             //Log.i(TAG, VotarProtocol.ByteArrayToHexString(mVotarProtocol.rawdata));
    22.             //Log.i(TAG, "-----------------------");
    23.  
    24.             Log.i(TAG, mVotarProtocol.toString());
    25.             Log.i(TAG, "------xxxx--------------");
    26.  
    27.             //aca quiero que mande la cosa entera
    28.             mBallotCallback.get().onBallotReceived(mVotarProtocol);
    29.  
    30.  
    31.         } catch (IOException e) {
    32.             Log.e(TAG, "Error communicating with card: " + e.toString());
    33.             mBallotCallback.get().onBallotFailed(e.toString());
    34.         }
    35.     }
    36.  
    37. }
    Found an nfcbookscanner on github but can't link it.
    --> Problems with the private DDMTag danishTag; Can't import it from the source org.rfid.libdanrfid.DDMTag;

    Code (Text):
    1. private void readTagData(Tag tag) {
    2.         StringBuilder sb = new StringBuilder();
    3.         byte[] id = tag.getId();
    4.         //sb.append("Tag ID (hex): ").append(getHex(id)).append("\n");
    5.         //sb.append("Tag ID (hex): ").append(toHex(id)).append("\n");
    6.         //sb.append("Tag ID (dec): ").append(getDec(id)).append("\n");
    7.  
    8.         final TextView textView1 = (TextView) findViewById(R.id.textView12);
    9.         final TextView textView2 = (TextView) findViewById(R.id.textView22);
    10.         final TextView textView23 = (TextView) findViewById(R.id.textView23);
    11.         final TextView textView3 = (TextView) findViewById(R.id.textView32);
    12.         final TextView textView33 = (TextView) findViewById(R.id.textView33);
    13.  
    14.         boolean techFound = false;
    15.         for (String tech : tag.getTechList()) {
    16.            
    17.             // Biblioteksbrikkene er NfcV
    18.             if (tech.equals(NfcV.class.getName())) {
    19.                 techFound = true;
    20.  
    21.                 sb.append('\n');
    22.  
    23.                 // Get an instance of NfcV for the given tag:
    24.                 NfcV nfcvTag = NfcV.get(tag);
    25.  
    26.                 try {                  
    27.                     nfcvTag.connect();
    28.                 } catch (IOException e) {
    29.                     Toast.makeText(getApplicationContext(), "Klarte ikke åpne en tilkobling!", Toast.LENGTH_SHORT).show();                  
    30.                     return;
    31.                 }
    32.                
    33.                 try {
    34.  
    35.                     // Get system information (0x2B)
    36.                     byte[] cmd = new byte[] {
    37.                         (byte)0x00, // Flags
    38.                         (byte)0x2B // Command: Get system information
    39.                     };
    40.                     byte[] systeminfo = nfcvTag.transceive(cmd);
    41.  
    42.                     // Chop off the initial 0x00 byte:
    43.                     systeminfo = Arrays.copyOfRange(systeminfo, 1, 15);
    44.  
    45.                     // Read first 8 blocks containing the 32 byte of userdata defined in the Danish model
    46.                     cmd = new byte[] {
    47.                         (byte)0x00, // Flags
    48.                         (byte)0x23, // Command: Read multiple blocks
    49.                         (byte)0x00, // First block (offset)
    50.                         (byte)0x08  // Number of blocks
    51.                     };
    52.                     byte[] userdata = nfcvTag.transceive(cmd);
    53.  
    54.                     // Chop off the initial 0x00 byte:
    55.                     userdata = Arrays.copyOfRange(userdata, 1, 32);
    56.  
    57.                     // Parse the data using the DDMTag class:
    58.                     danishTag = new DDMTag();
    59.                     danishTag.addSystemInformation(systeminfo);
    60.                     danishTag.addUserData(userdata);
    61.  
    62.                     ImageView iv1 = (ImageView) findViewById(R.id.lock_icon);
    63.                     iv1.setVisibility(View.VISIBLE);
    64.  
    65.                     if (danishTag.isAFIsecured()) {
    66.                         iv1.setImageResource(R.drawable.lock_closed);
    67.                     } else {
    68.                         iv1.setImageResource(R.drawable.lock_open);
    69.                     }
    70.  
    71.                     textView1.setText(danishTag.Country());
    72.                     textView2.setText(danishTag.ISIL());
    73.                     textView3.setText(danishTag.Barcode());
    74.                     textView33.setText("Del " + danishTag.getPartNum() + " av " + danishTag.getofParts());
    75.  
    76.                     currentBarcode = danishTag.Barcode();
    77.  
    78.                     webview.loadUrl("javascript:barcodeScanned('" + currentBarcode + "'); return false;");
    79.  
    80.                 } catch (IOException e) {
    81.                     Toast.makeText(getApplicationContext(), "Det oppsto en feil under lesing!", Toast.LENGTH_SHORT).show();
    82.                     return;
    83.                 }
    84.  
    85.                 try {
    86.                     nfcvTag.close();
    87.                 } catch (IOException e) {
    88.                     Toast.makeText(getApplicationContext(), "Klarte ikke å lukke tilkoblingen!", Toast.LENGTH_SHORT).show();
    89.                     return;
    90.                 }
    91.                 sb.append("Tilkobling lukket\n");
    92.             }
    93.         }
    Would be great if someone could help me with this problem :)
    Thx and best wishes
    Martin
     

    Advertisement

    #1 Kellrkind, Oct 10, 2017
    Last edited: Oct 10, 2017
  2. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #8
    Points:
    2,138
    Posts:
    22,298
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,298
    23,695
    2,138
    Male
    space alien ;)
    Indy
    Where does the '89' come from? :thinking:

    (i.e., is that decimal or hex and why is that a value that you want...a little confused as to how / where that might be derived from...)

    [welcome to AF, by the way :) ]
     
  3. Kellrkind

    Kellrkind Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    3
    Joined:
    Oct 10, 2017

    Oct 10, 2017
    3
    2
    6
    Male
    Hey scary ;)

    Thx for the fast response :)
    I speculate that the output should be the number 89. Every member of our guild is marked with a stitched number on their dress. Under the number they've placed a NFC Tag and they've used a little maschine before to administrate every member on every trip. This maschine showed the number (in my case 89) when they've scanned my tag

    So i concluded that it should result this number but i'm not totaly shure because i don't know how to handle the bytes in the hex and decs part of the tag :)

    Thx also for the warm welcome :)
     
    scary alien likes this.
  4. Kellrkind

    Kellrkind Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    3
    Joined:
    Oct 10, 2017

    Oct 10, 2017
    3
    2
    6
    Male
    Update:
    I've found the app NFC tagInfo. The App gives me this information:

    Data (US-ASCII)
    Block 0: (some weird signs)
    Block 1: 089
    Block 2:
    Block 3:
    Block 4:
    Block 5:
    Block 6:
    Block 7:

    Are there anny suggestions how to read the US-ASCII Part?
     
    scary alien likes this.

Share This Page

Loading...