Answered by:
WriteTag option for NDEF record.

Question
-
Hi, I am developing an metro app to write to a static tag using PublishBinaryMessage() here:http://msdn.microsoft.com/en-us/library/windows/apps/hh701129.aspx
It works fine for Windows text message, URI and mime/text formats. However, it fails for NDEF:WriteTag. I get an error as "Incorrect Parameter passed"
Here is the code,
publishedMessageId = proximityDevice.publishBinaryMessage("NDEF:WriteTag", dataWriter.detachBuffer(), NFCWriteTag.WrittentoTag);
input that I give is "\x00http:\\www.google.co.in
Kindly help me in resolving this issue. Thanks.
Cheers, Veena.
Tuesday, July 24, 2012 11:48 AM
Answers
-
Are you saying that the content you have written to the dataWriter is "\x00http:\\www.google.co.in"? That does not appear to be a valid NFC Forum NDEF record. When publishing NDEF, the contents must be properly formatted NDEF records according to NFC Forum standards.
Mike [MSFT]
- Marked as answer by Eric Hanson-MSFTModerator Wednesday, July 25, 2012 11:43 PM
Wednesday, July 25, 2012 11:39 PM -
You would want to refer to the NFC Forum for NDEF specifications: http://www.nfc-forum.org
Can you please clarify what you are trying to accomplish? You mentioned testing, perhaps there is an easier way to test your scenario.
If your goal is to write a Uri to a tag, I would recommend using "WindowsUri:WriteTag", then simply pass the Uri (ie: "http:\\google.com").
-Mike [MSFT]
- Marked as answer by Eric Hanson-MSFTModerator Monday, July 30, 2012 6:08 PM
Thursday, July 26, 2012 5:39 PM -
I'm sorry that things are not working smoothly for you.
You mentioned that writing "testmessage.txt or mypicture.jpeg" doesn't work, but you didn't say what happens? Do you get an error when calling the API, or it appears to succeed but you aren't able to read the tag? And it's not clear what you mean by "testmessage.txt or mypicture.jpeg"; I assume you aren't passing a file name into PublishBinaryMessage with "WindowsMime:WriteTag.image/jpeg"? If you are using "WindowsMime:WriteTag.image/jpeg", you need to pass a buffer containing the jpeg content. If you are using "WindowsMime:WriteTag.text/plain", text content should work.
Regarding your second question, you do need to wrap whatever data you are trying to write in NDEF headers if you are using NDEF:WriteTag. But I would like to clarify that when you use WindowsUri:WriteTag, it converts the content to NDEF for you. So if your intent is to write a URI, there is no need to convert to NDEF first, just use WindowsUri:WriteTag and NDEF will be written to the tag. The same is true for WindowsMime:WriteTag.
Regarding Windows:WriteTag.text/plain not working; do you get an error when calling the API? What are you passing as content? What version of Windows are you running? Can you also please check what version of the NXP proximity device you have by checking its properties in Device Manager and using the Driver tab?
-Mike [MSFT]
- Marked as answer by Eric Hanson-MSFTModerator Wednesday, August 1, 2012 3:05 PM
Friday, July 27, 2012 3:42 PM -
It sounds like everything you were expecting to work was working with the NXP Proximity driver, but the same code is not working with the Broadcom driver? That sounds like there is an issue with the Broadcom driver. You will likely need to contact Broadcom.
-Mike [MSFT]
- Marked as answer by Eric Hanson-MSFTModerator Monday, July 30, 2012 6:09 PM
Monday, July 30, 2012 5:57 PM -
Your app can subscribe to the corresponding NDEF type that was written to the tag and receive the NDEF data. Note that if you subscribe to an NDEF* type, you will receive NDEF formatted content and you'll have to know how to parse that NDEF to make use of it. You also need to either subscribe to just NDEF or subscribe to the correct NDEF* type that corresponds to the data type that was written.
-Mike [MSFT]
- Marked as answer by Eric Hanson-MSFTModerator Wednesday, August 1, 2012 3:06 PM
Tuesday, July 31, 2012 5:55 PM -
I did also try the following code and it appeared to be working for me:
var proximityDevice = Windows.Networking.Proximity.ProximityDevice.getDefault();
if (proximityDevice) {
var dataWriter = new Windows.Storage.Streams.DataWriter();
dataWriter.writeString("My random text data");
var publishedMessageId = proximityDevice.publishBinaryMessage("WindowsMime:WriteTag.text/plain", dataWriter.detachBuffer());
}After writing this to the tag and calling StopPublishingMessage (to stop writing new tags), if I tap the tag I wrote, I get a toast asking me to receive the content. If I accept, the text file opens saying "My random text data".
Let me know if you are not able to reproduce this result.
-Mike [MSFT]
- Marked as answer by Eric Hanson-MSFTModerator Friday, July 27, 2012 9:35 PM
Friday, July 27, 2012 9:34 PM
All replies
-
VeenaU,
I will look into this for you.
Best Wishes - Eric
Wednesday, July 25, 2012 7:06 AMModerator -
Are you saying that the content you have written to the dataWriter is "\x00http:\\www.google.co.in"? That does not appear to be a valid NFC Forum NDEF record. When publishing NDEF, the contents must be properly formatted NDEF records according to NFC Forum standards.
Mike [MSFT]
- Marked as answer by Eric Hanson-MSFTModerator Wednesday, July 25, 2012 11:43 PM
Wednesday, July 25, 2012 11:39 PM -
Which is the valid NDEF record? I tried "http:\\google.com" as an input as well. could you please give me a sample NDEF record that I can write to a tag? My tests are blocked with this:( Thanks.
Cheers, Veena.
Thursday, July 26, 2012 5:26 AM -
You would want to refer to the NFC Forum for NDEF specifications: http://www.nfc-forum.org
Can you please clarify what you are trying to accomplish? You mentioned testing, perhaps there is an easier way to test your scenario.
If your goal is to write a Uri to a tag, I would recommend using "WindowsUri:WriteTag", then simply pass the Uri (ie: "http:\\google.com").
-Mike [MSFT]
- Marked as answer by Eric Hanson-MSFTModerator Monday, July 30, 2012 6:08 PM
Thursday, July 26, 2012 5:39 PM -
Hi Mike,
Thanks for the reply. I am writing a metro app that can write different types of data to the static tag like Uri, image file name, text file name and a simple text message ("Hello world"). I need to use both Windows and NDEF message types in ProximityDevice class. Could you please give me solutions for the below 2 problems I have?
1) I could not write "testmessage.txt or mypicture.jpeg" to a static tag using "WindowsMime:WriteTag.image/jpeg" or "WindowsMime:WriteTag.text/plain". Not even "Windows:WriteTag.text/plain" works!...
2) I could write "http:\\google.com" using "WindowsUri:WriteTag" but not using NDEF:WriteTag. I could see that the data that is published has to be properly formatted NDEF record. Does it mean that every time I write a data to the tag like "http:\\nokia.com, I need to give the data as "030ed1010a5503nokia.comfe" as per this link: http://www.developer.nokia.com/Community/Wiki/Understanding_NFC_Data_Exchange_Format_(NDEF)_messages?
Pointers or samples on these would really help.
Thanks,
Veena.
Cheers, Veena.
- Edited by VeenaU Friday, July 27, 2012 12:31 PM
Friday, July 27, 2012 9:19 AM -
I'm sorry that things are not working smoothly for you.
You mentioned that writing "testmessage.txt or mypicture.jpeg" doesn't work, but you didn't say what happens? Do you get an error when calling the API, or it appears to succeed but you aren't able to read the tag? And it's not clear what you mean by "testmessage.txt or mypicture.jpeg"; I assume you aren't passing a file name into PublishBinaryMessage with "WindowsMime:WriteTag.image/jpeg"? If you are using "WindowsMime:WriteTag.image/jpeg", you need to pass a buffer containing the jpeg content. If you are using "WindowsMime:WriteTag.text/plain", text content should work.
Regarding your second question, you do need to wrap whatever data you are trying to write in NDEF headers if you are using NDEF:WriteTag. But I would like to clarify that when you use WindowsUri:WriteTag, it converts the content to NDEF for you. So if your intent is to write a URI, there is no need to convert to NDEF first, just use WindowsUri:WriteTag and NDEF will be written to the tag. The same is true for WindowsMime:WriteTag.
Regarding Windows:WriteTag.text/plain not working; do you get an error when calling the API? What are you passing as content? What version of Windows are you running? Can you also please check what version of the NXP proximity device you have by checking its properties in Device Manager and using the Driver tab?
-Mike [MSFT]
- Marked as answer by Eric Hanson-MSFTModerator Wednesday, August 1, 2012 3:05 PM
Friday, July 27, 2012 3:42 PM -
I did also try the following code and it appeared to be working for me:
var proximityDevice = Windows.Networking.Proximity.ProximityDevice.getDefault();
if (proximityDevice) {
var dataWriter = new Windows.Storage.Streams.DataWriter();
dataWriter.writeString("My random text data");
var publishedMessageId = proximityDevice.publishBinaryMessage("WindowsMime:WriteTag.text/plain", dataWriter.detachBuffer());
}After writing this to the tag and calling StopPublishingMessage (to stop writing new tags), if I tap the tag I wrote, I get a toast asking me to receive the content. If I accept, the text file opens saying "My random text data".
Let me know if you are not able to reproduce this result.
-Mike [MSFT]
- Marked as answer by Eric Hanson-MSFTModerator Friday, July 27, 2012 9:35 PM
Friday, July 27, 2012 9:34 PM -
Hi Mike, I am sorry for not being clear...Here are some details.
I had previously used NXP Proximity driver and things were working smooth. I could use all the options like, WindowsUri:WriteTag, Windows:WriteTag and WindowsMime:WriteTag, to write to the tag. The problem started when I had to move to Broadcom Proximity driver (It's not my choice!). Now, only WindowsUri:WriteTag works. Here is my sample code:
publishMessage: function () { var dataWriter = new Windows.Storage.Streams.DataWriter(); dataWriter.unicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.utf16LE; dataWriter.writeString(id("messageText").value); //1)Input to this is a simple text like Hello World. - Does not work now publishedMessageId = proximityDevice.publishBinaryMessage("Windows:WriteTag.text", dataWriter.detachBuffer(), NFCWriteTag.WrittentoTag); //2)Input to this is an Uri http:\\google.com - it works fine. publishedMessageId = proximityDevice.publishBinaryMessage("WindowsUri:WriteTag", dataWriter.detachBuffer(), NFCWriteTag.WrittentoTag); //3)Input to this is again a simple text Hello World. Does not work now publishedMessageId = proximityDevice.publishBinaryMessage("WindowsMime:WriteTag.text/plain", dataWriter.detachBuffer(), NFCWriteTag.WrittentoTag);
Please note that I use only one of the above 3 options at a time. I am not trying to publish all of them at the same time. I comment the unused ones every time. After PublishBinaryMessage API is called, I get an exception as "0x80070057 - JavaScript runtime error: The parameter is incorrect." I tried with your code as well. I get an Exception after calling PublishBinaryMessage API.
I am using Windows 8 Release Preview. Proximity driver details are: Broadcom Driver, version 1.0.0.1800. Kindly help me.
Regarding the NDEF stuffs you have mentioned, thanks for the information. It is very nice that "WindowsMime:WriteTag" itself takes care of NDEF stuffs. Thanks again.
Cheers,
Veena.
Cheers, Veena.
Monday, July 30, 2012 5:06 AM -
It sounds like everything you were expecting to work was working with the NXP Proximity driver, but the same code is not working with the Broadcom driver? That sounds like there is an issue with the Broadcom driver. You will likely need to contact Broadcom.
-Mike [MSFT]
- Marked as answer by Eric Hanson-MSFTModerator Monday, July 30, 2012 6:09 PM
Monday, July 30, 2012 5:57 PM -
Thanks Mike, I will do that.
I have another query regarding the same Write Tag options:
From your message above, I understand that "WindowsMime:WriteTag" or Windows:WirteTag or WindowsUri:WriteTag, will write the data in the NDEF format to the static tag.
Suppose that I have use this way to write some data to the tag using "WindowsUri:WriteTag. Can my app subscribe using NDEF:URI and read the data from it? Please let me know if this is allowed.
Thanks,
Veena.
Cheers, Veena.
Tuesday, July 31, 2012 1:26 PM -
Your app can subscribe to the corresponding NDEF type that was written to the tag and receive the NDEF data. Note that if you subscribe to an NDEF* type, you will receive NDEF formatted content and you'll have to know how to parse that NDEF to make use of it. You also need to either subscribe to just NDEF or subscribe to the correct NDEF* type that corresponds to the data type that was written.
-Mike [MSFT]
- Marked as answer by Eric Hanson-MSFTModerator Wednesday, August 1, 2012 3:06 PM
Tuesday, July 31, 2012 5:55 PM