-2

When I Open the NFC wrapper sample codethe program works by stating "SCM_NFC.DLL successfully loaded". But when i tried debugging the code and place the card on the device. i am always getting MessageCount as Zero.

Can anyone tell me whats wrong?

Thanks in Advance

private void ReadNDEF() {   
    UInt32 DeviceCount = 0;
    UInt32 MessageCount = 0;
    UInt32 NextMessageSize = 0;
    UInt32 Result;

    if (NFCWrapper == null) return;

    // Get information about the message queue
    Result = TNFCWrapper.GetNDEFQueueInfo(ref DeviceCount, ref MessageCount, ref NextMessageSize);
    if (MessageCount != 0) {
        if (Result != TNFCWrapper.ERR_SUCCESS) return;

        //Resize the NDEF buffer accordingly to the site of the next message in the queue
        byte[] NDEF = new byte[NextMessageSize];
        UInt32 NDEFSize = NextMessageSize;
        TNFCAddress NFCAddress = new TNFCAddress();
        TMessageInfo MessageInfo = new TMessageInfo();

        //Read the NDEF message from the message queue
        Result = TNFCWrapper.ReadNDEF(ref NFCAddress, ref MessageInfo, ref NDEF[0], ref NDEFSize);
        if (Result != TNFCWrapper.ERR_SUCCESS) return;

        //Display the message details
        string sAddress = "";
        for (int i = 0; i < 12; i++) sAddress = sAddress + NFCAddress.Address[i].ToString("X2") + " ";

        PrintHexDump(NDEF, NDEFSize);

        // convert NDEF into XML
        string XML = "";
        Result = NFCWrapper.NDEF2XML(ref NDEF[0], NDEFSize, ref XML);

        if (Result != TNFCWrapper.ERR_SUCCESS) return;

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(XML);
        var valueRead = XElement.Parse(XML)
                   .Descendants("NDEF_Text")
                   .First()
                   .Value;
        string associateId = valueRead.Substring(5);
        LogMessage(associateId);
        NavigationService navService = NavigationService.GetNavigationService(this);
        navService.Navigate(new System.Uri("Booking.xaml", UriKind.Relative));
    }
}
Michael Roland
  • 39,663
  • 10
  • 99
  • 206
Suresh Savage
  • 425
  • 2
  • 7
  • 16

1 Answers1

1

As indicated by the result of GetNDEFQueueInfo(), no devices and no NDEF messages were detected. Consequently, ReadNDEF() must fail as it can't read something that isn't there.

Without knowing how you initialized the NFC reader and what you programmed on the "card"/NFC tag, it is difficult to say what's going wrong, but here's a list of possible causes that come to my mind:

  1. The NFC tag/"card" must contain a valid NDEF message.
  2. You did not call StartListening() to activate scanning for NFC tags/NFC devices.
  3. You previously disabled scanning for the tag type of your "card" using SetTarget().
Michael Roland
  • 39,663
  • 10
  • 99
  • 206