Why making
In previous post, I practice tag NXP213 for writing and reading by Sony Pasori.
I search web page of only NDEF library, but I can’t find out NDEF library for simply analysing and making.
So I make simple NDEF library on my own reading NDEF Specification and refering to pages.
andijakl/ndef-nfc is UWP and control reader’s library. I want to use this but give up using this library.
Specifications
- NXP21X needs Type2 Tag NDEF. We insert Lock Control TLV.(*1)
- ControlTLV、MessageTLV are implemented.。
- NDEF Record Type only “U”is implemented.(*2)
- Only “SR”Short Record” is implemented.
- I confirm class “NdefTLV” and “NdefRecord” by unit test and join test code.
These data samples are refering spec. sheet and web pages. - Release under MIT License.
*1 I know this from smart phone application writing byte array. I read lock control TLV spec. but i can’t understand all.
*2 If you need T, please implement by yourself.
ダウンロード
Please download from below button. (I want to know download count and refer count. I release here.)
“Simple Ndef Parser Class Lib v1.0” をダウンロード SimpleNdefParserClass_V1.0.zip – 533 回のダウンロード – 889 KB
If test code doesn’t work well, change .Net Framework.
NDEF Specifications and Refering pages
- NFC Data Exchange Format (NDEF) Technical Specification NFC ForumTM NDEF 1.0
- Type 2 Tag Operation Specification
- 【NFC】NDEFについて理解する
NDEF structure
NDEF TLV include NDEF Record.
NDEF Reccord include PayLoad. (This payload include byte array.)
(LockTLV is using only Type2 Tag ?)
Simple Ndef Parser analyze and make these NDEF structure.
- NDEF TLV – SimpleNP_NdefTLV.cs
- NDEF Record – SimpleNP_NdefRecord.cs
- その他 – SimpleNP_NdefUtility.cs (common functions and enum including)
How to use these class by Test code.
Refer to UnitTest1.cs, UnitTest2.cs files.
Using for tag-reading
1. From NDEF byte array to string(NDEF Record)
NdefRecord sample1_record = new NdefRecord(sample1); //① string answer = "http://www.nfc.com"; Assert.AreEqual(answer, sample1_record.URI, "取得したURIデータが異なります。"); //②
① Analyze NDEF byte arrry and make uri string in NdefRecord Class
② Compare the string (result output)
2. From NDEF byte array to string (NDEF TLV)
NdefTLV ndefTLV = new NdefTLV(sample4_MyType2Tag); //① Assert.AreEqual("https://office-fun.com", ndefTLV.record.URI, "NdefMeasageの解釈でエラーが発生しました。");
① Analyze NDEF TLV and NDEF Record in byte array, mage uri string.
Using for tag-writting
Compare original byte array and converted byte array, check all element.
3.From string to NDEF byte array. (Record)
string orgData = "mms://example.com/download.wmv"; NdefRecord sample_ndefData = new NdefRecord(orgData, UriIdentifierCode.UnAbridgedURI); for (int i = 0; i < sample3.Length; ++i) { Assert.AreEqual(sample3[i], sample_ndefData.RawData[i], i.ToString() + "番目でエラーが発生しました。"); }
4. From string to NDEF byte array.(NDEF TLV)
string orgData = "https://office-fun.com"; NdefTLV ndefTLV = new NdefTLV(orgData, UriIdentifierCode.UnAbridgedURI, TLVBlock.LockControlTLV);
Comment
Please use lightly and with ease.