-2
當我打開NFC包裝示例代碼時,程序通過聲明「SCM_NFC.DLL成功加載」工作。但是,當我嘗試調試代碼並將卡放置在設備上時。我總是將MessageCount作爲零。NFC軟件開發套件NFC包裝示例代碼
誰能告訴我什麼是錯的?提前
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));
}
}
再次感謝您將再次嘗試您的評論... –