• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Problems reading a NfcV Tag

Kellrkind

Lurker
Oct 10, 2017
3
2
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:
            nfcv.connect();
            byte[] tagID = nfcv.getTag().getId();
            String tagInhalt = getHex(tagID);
            Log.d("Hex ID", tagInhalt);
            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:
public void onTagDiscovered(Tag tag) {
    Log.i(TAG, "New tag discovered");
    Log.i(TAG, "Tag: " + VotarProtocol.BuildTagId(tag.getId(),0));
    VotarProtocol mVotarProtocol;
    NfcV nfcvTag = NfcV.get(tag);
    if (nfcvTag != null) {
        mVotarProtocol = new VotarProtocol();
        try {
            // Connect to the remote NFC device
            // set up read command buffer
            nfcvTag.connect();

            mVotarProtocol.setSystemInfo(nfcvTag.transceive(getCommand(tag.getId(), true)));

            Log.i(TAG, "-----------------------");
            Log.i(TAG, "Tag ID: " + mVotarProtocol.tagID());
            Log.i(TAG, "-----------------------");
            byte[] xdata = nfcvTag.transceive(getCommand(tag.getId(), false));
            mVotarProtocol.setBallotData(xdata);

            //Log.i(TAG, VotarProtocol.ByteArrayToHexString(mVotarProtocol.rawdata));
            //Log.i(TAG, "-----------------------");

            Log.i(TAG, mVotarProtocol.toString());
            Log.i(TAG, "------xxxx--------------");

            //aca quiero que mande la cosa entera
            mBallotCallback.get().onBallotReceived(mVotarProtocol);


        } catch (IOException e) {
            Log.e(TAG, "Error communicating with card: " + e.toString());
            mBallotCallback.get().onBallotFailed(e.toString());
        }
    }

}

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:
private void readTagData(Tag tag) {
        StringBuilder sb = new StringBuilder();
        byte[] id = tag.getId();
        //sb.append("Tag ID (hex): ").append(getHex(id)).append("\n");
        //sb.append("Tag ID (hex): ").append(toHex(id)).append("\n");
        //sb.append("Tag ID (dec): ").append(getDec(id)).append("\n");

        final TextView textView1 = (TextView) findViewById(R.id.textView12);
        final TextView textView2 = (TextView) findViewById(R.id.textView22);
        final TextView textView23 = (TextView) findViewById(R.id.textView23);
        final TextView textView3 = (TextView) findViewById(R.id.textView32);
        final TextView textView33 = (TextView) findViewById(R.id.textView33);

        boolean techFound = false;
        for (String tech : tag.getTechList()) {
           
            // Biblioteksbrikkene er NfcV
            if (tech.equals(NfcV.class.getName())) {
                techFound = true;

                sb.append('\n');

                // Get an instance of NfcV for the given tag:
                NfcV nfcvTag = NfcV.get(tag);

                try {                  
                    nfcvTag.connect();
                } catch (IOException e) {
                    Toast.makeText(getApplicationContext(), "Klarte ikke åpne en tilkobling!", Toast.LENGTH_SHORT).show();                   
                    return;
                }
               
                try {

                    // Get system information (0x2B)
                    byte[] cmd = new byte[] {
                        (byte)0x00, // Flags
                        (byte)0x2B // Command: Get system information
                    };
                    byte[] systeminfo = nfcvTag.transceive(cmd);

                    // Chop off the initial 0x00 byte:
                    systeminfo = Arrays.copyOfRange(systeminfo, 1, 15);

                    // Read first 8 blocks containing the 32 byte of userdata defined in the Danish model
                    cmd = new byte[] {
                        (byte)0x00, // Flags
                        (byte)0x23, // Command: Read multiple blocks
                        (byte)0x00, // First block (offset)
                        (byte)0x08  // Number of blocks
                    };
                    byte[] userdata = nfcvTag.transceive(cmd);

                    // Chop off the initial 0x00 byte:
                    userdata = Arrays.copyOfRange(userdata, 1, 32);

                    // Parse the data using the DDMTag class:
                    danishTag = new DDMTag();
                    danishTag.addSystemInformation(systeminfo);
                    danishTag.addUserData(userdata);

                    ImageView iv1 = (ImageView) findViewById(R.id.lock_icon);
                    iv1.setVisibility(View.VISIBLE);

                    if (danishTag.isAFIsecured()) {
                        iv1.setImageResource(R.drawable.lock_closed);
                    } else {
                        iv1.setImageResource(R.drawable.lock_open);
                    }

                    textView1.setText(danishTag.Country());
                    textView2.setText(danishTag.ISIL());
                    textView3.setText(danishTag.Barcode());
                    textView33.setText("Del " + danishTag.getPartNum() + " av " + danishTag.getofParts());

                    currentBarcode = danishTag.Barcode();

                    webview.loadUrl("javascript:barcodeScanned('" + currentBarcode + "'); return false;");

                } catch (IOException e) {
                    Toast.makeText(getApplicationContext(), "Det oppsto en feil under lesing!", Toast.LENGTH_SHORT).show();
                    return;
                }

                try {
                    nfcvTag.close();
                } catch (IOException e) {
                    Toast.makeText(getApplicationContext(), "Klarte ikke å lukke tilkoblingen!", Toast.LENGTH_SHORT).show();
                    return;
                }
                sb.append("Tilkobling lukket\n");
            }
        }

Would be great if someone could help me with this problem :)
Thx and best wishes
Martin
 
Last edited:
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 :)
 
  • Like
Reactions: scary alien
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones