2017-06-23 137 views
0

是否可以使用UWP將空的NTAG213格式化爲NDEF?發現this post,談論「Windows Phone 8.1支持格式化爲NDEF for MIFARE Classic,MIFARE Ultralight和DESFire」。但是NTAG213或其他什麼呢?那麼UWP和Win10呢?在Windows 10上將NTAG213格式化爲NDEF UWP App

預格式化爲NDEF標籤效果良好。在預先格式化的標籤上寫下如下:

 string launchAppMessage = string.Join("#", new string[] { 
       "MyAppName", 
       "\tWindows\t", 
       message+"#" 
     }); 
     var dataWriter = new Windows.Storage.Streams.DataWriter(); 
     dataWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE; 
     dataWriter.WriteString(launchAppMessage); 
     _publishingMessageId = _device.PublishBinaryMessage("LaunchApp:WriteTag", dataWriter.DetachBuffer(), MessageWrittenHandler); 

但如何將空標籤格式化爲NDEF?下面的代碼總是拋出System.ArgumentException:值不在預期範圍內

try 
    { 
     // empty NDEF message 
     var test = new byte[] { 0x03, 0x03, 0xD0, 0x00, 0x00, 0xFE}; 
     var dataWriter = new Windows.Storage.Streams.DataWriter(); 
     dataWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE; 
     dataWriter.WriteBytes(test); 
     _publishingMessageId = _device.PublishBinaryMessage("NDEF:Empty", dataWriter.DetachBuffer(), MessageWrittenHandler); 
    } 
    catch (Exception ex) 
    { 
     var mesasge = ex.Message; 
    } 

我真的不知道我正在使用正確的消息類型(「NDEF:空」)或什麼我test變量包含正確的字節。但不知道該怎麼做。

也許有人做過這個?提前致謝!

編輯:

經過一番研究,我想在這代碼未格式化標籤。這不會引發異常,但標記仍然是空的。好像這個代碼只是什麼都不做:

string launchAppMessage = string.Join("#", new string[] { 
    "MyAppName", 
    "\tWindows\t", 
    "TEST"+"#" 
    }); 

var dataWriter = new Windows.Storage.Streams.DataWriter(); 
dataWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE; 
dataWriter.WriteString(launchAppMessage); 
_publishingMessageId = _device.PublishBinaryMessage("LaunchApp:WriteTag", dataWriter.DetachBuffer(), MessageWrittenHandler); 

EDIT2:

我收集更多信息,使我的問題更容易理解。

下面您可以看到相同標籤的兩種狀態。

enter image description here

右側標籤被格式化爲出廠默認值(而不是從我的應用程序訪問),左側NDEF格式化(從應用程序訪問)。您可以在左側看到空的NDEF消息(03 03 D0 00 00 FE)。

我用黃色邊框標記了這種狀態之間的區別。

所以我的問題。有一種方法可以將標記從「正確」狀態格式化爲「左側」?

+0

請在這裏查看我的MSDN帖子https://social.msdn.microsoft.com/Forums/zh-CN/a60a4c61-32d1-4851-add5-63ad5e6342d2/uwpformat-ntag213-to-ndef-on-windows-10 -uwp-app?forum = wpdevelop查看是否可以更改消息類型。第一種消息類型似乎不正確。也許你可以嘗試那種不知道的類型 –

+0

謝謝!我會嘗試一下並告訴你結果。 – ashchuk

+0

不,它不起作用。在EDIT2 – ashchuk

回答

1

在Windows 10 UWP,手機或臺式機上,您可以使用NDEF格式的NTAG213或NTAG216。而不是使用ProximityDevice類,請使用Windows.Devices.SmartCards.SmartCardReader類。還有一個有用的PCSC包裝MS寫在這裏:https://nfcsmartcardreader.codeplex.com/ 沒有正確的手機或芯片在手機中,它不會工作,但如果你確實有正確的模式,這是行不通的。這將使您可以低級別訪問標籤,以便根據需要寫入塊以設置NDEF格式的標籤。

+0

中回答SmartCardReader枚舉總是返回'null',即使這樣我在Windows服務中啓用了SmartCardReader枚舉服務。這意味着我無法使用平板電腦使用我現在擁有的低級別功能。標記爲答案。非常感謝! – ashchuk