Is it possible to format empty NTAG213 to NDEF using UWP? Found this post, where talking about " Windows Phone 8.1 support for formatting to NDEF for MIFARE Classic, MIFARE Ultralight and DESFire". But what about NTAG213 or something else? And what about UWP and Win10?
Preformatted to NDEF tag working well. Writing on a preformatted tag is below:
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);
But how to format empty tag to NDEF? The code below always throws System.ArgumentException: Value does not fall within the expected range.
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;
}
I'm not really sure what I'm using right message type ("NDEF:Empty") or what my test
variable contains right bytes. But don't know what to do else.
Maybe anybody made this before? Thanks in advance!
EDIT:
After some research, I tried this code on not formatted tag. This not throws an exception, but tag is still empty. Seems like this code just doing nothing:
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:
I collected more info to make my question more understandable.
Below you can see two states of the same tag.
Right side tag is formatted to factory default values (and not accessible from my app), left side formatted in NDEF (and accessible from the app). You can see an empty NDEF message on the left side (03 03 D0 00 00 FE).
I marked the difference between this states by a yellow border.
And so my question. There is a way to format tag from the "right" state to "left"?
You can NDEF format NTAG213 or NTAG216 in Windows 10 UWP, on phone or desktop. Instead of using the ProximityDevice classes, use the Windows.Devices.SmartCards.SmartCardReader classes. There's also a useful PCSC wrapper MS wrote here: https://nfcsmartcardreader.codeplex.com/ Without the correct phone or chip in the phone, it won't work, but if you do have the right model, this does work. This will give you low level access to the tag to write blocks as needed to set up the tag with the NDEF format.