Skip to main content
DDve.1
Associate II
March 8, 2022
Solved

Simple C# interface for read/write - what to use?

  • March 8, 2022
  • 4 replies
  • 12864 views

Hi! I develop access system using NFC(14443-A) tags on Windows(.NET) platform + USB ST25R3911B-DISCO. I need simple API to read/write my data to the tag (like person name or ID, nothing secure). What API(and library) I have to use? I'm lost in all possible libs. :( I successfully run (and understood) demo 'Demo_dll_main.cs', but I need write sample too (no any secure things, just plain data). Thanks!

This topic has been closed for replies.
Best answer by Ulysses HERNIOSUS

Hi,

iso14443 does not specify anything about reading and writing memory. NFC Forum defines standard card types on the basis of pre-existing proprietary cards, e.g. T2T interface for MifareUltralight and others. T4T for cards basing on a smartcard interface implementing T=CL/ISODEP/Layer4.

The tab I mentioned previously is called "Nfc Type 2" in the 3911 GUI.

I think you have two options: Become a member of NFC Forum, download the specs - especially NFC Forum T4T, and use it to implement your own procedures to read/write T2Tag, T4Tag, ....

Or base on other software, either the ST25 SDK or the embedded ST25 NFC Lib which are implementing these procedures. The aim of our "Disco" deliveries is to discover the reader chip, not to provide stacks and all the high-level procedures to read all possible tags in the world.

Regards, Ulysses

4 replies

Ulysses HERNIOSUS
Technical Moderator
March 8, 2022

Hi,

one possibility would be the ST25 SDK but then you are in the Java world. I am not aware of C# code to achieve exactly what you are wishing for.

Also what exactly to do you want to achieve on which tags? There are a plethora of different tags (T4T and T2T are NFC Forum definitions of standards for ISO14443-A tags) around and it depends how you want to write the data:

  • Do you want to write NDEF data? (To be readable by mobiles?)
  • Your own proprietary write scheme? For which tags exactly?

If it comes to NDEF then inside the ST25 Embedded NFC lib are examples how to read/write NFC Forum tags (T2T, T3T, T4T, T5T).

BR, Ulysses

DDve.1
DDve.1Author
Associate II
March 8, 2022

Fortunately you have "ST25R3911_Interface.cs" - it has all functions exported from ST25R3911DISCOComm.dll. I hope they are enough for my task.

I'm noob in NFC world, I cannot say what tags I have - some noname cards, which give output:

14443-A UID (size = 4) NOT compliant with ISO/IEC 14443-4

What I 100% sure I do not need any NDEF or any bank standards. Like I already said, I need just ability to write my custom data on the tag. Type of tag is known - 14443-A.

Have you any sample to write info on such card? I cannot deep in Java-world, sorry :) Solution should be C# only.

Brian TIDAL
Technical Moderator
March 11, 2022

Hi,

As explained by Ulysses, ISO 14443-A does not define a tag type but a communication protocol: the tag memory layout and the way to read/write from/to a tag memory depends on the tag type. The sample code you have provided in your post does not work for every ISO 14443-A tags but only for a Mifare Classic tag which has a proprietary memory layout and a proprietary crypto. If your question is 'Does ST has an API to read/write Mifare classic tag on ST25R3911B_DISCO?" , I am sorry to say "No" because this would violate legal rules. As mentioned by Ulysses, I would suggest to use a T2T tag such as ST25TN if your application does not require crypto.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
DDve.1
DDve.1Author
Associate II
March 11, 2022

Hi, Brian! Thanks for explanation. My code sample was just demo of real C# API (and how convenient it should be). You narrow my question, while it was more generic: I need C# sample on how I can write data on NFC card. Let's assume I have mentioned T2T tag. How I can read and write data on such card? Short C# sample could be fine, please. Currently ST provides VERY limited sample "how to read card UID". Unfortunately list of functions in ST25R3911DISCOComm.dll doesn't give me anything.

Brian TIDAL
Technical Moderator
March 14, 2022

Hi,

There is no ready to use demo fitting your needs, but as explained by Ulysses, for a T2T tag, you can use t2tRead4Pages for a 4 blocks read (and t2tWritePage for a single block write).

You can also use rfalTransceiveBlockingTxRx to send arbitrary command to the tag.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
DDve.1
DDve.1Author
Associate II
March 14, 2022

Brian, I'm not sure you're aware what is contained in C# demo. It has "ST25R3911_Interface.cs" - wrapper for ST25R3911DISCOComm.dll; But this wrapper has not a single function you mentioned. All I found related writing is:

iso14443bWriteAttrb iso15693WriteBlock topazWriteByte

While all my tags are 14443-A. Can you please clarify, what is completion status of "ST25R3911DISCOComm.dll"? I need to write 14443-A tag with ST25R3911DISCO reader, but this simplistic task has too much problems. There is no even the "C" code for that. Guessing algorithm from function names also pointless. That's why I need professional support with this task. Can anybody provide it? I need just short samples reading/writing tags, it is primary functions of NFC - pity they still not reflected in a demo.

Brian TIDAL
Technical Moderator
March 14, 2022

Hi,

t2tRead4Pages and t2tWritePage are exported in the ST25R391x_Interface.cs used for ST25R3916-DISCO whereas you are using the ST25R3911B-DISCO with ST25R3911_Interface.cs. Sorry for having mixed up the 2 different Discovery boards and the 2 DLL interfaces.

ST does provide a lot of examples of reading and writing tags of various technologies for embedded applications (i.e. C code and libraries for MCUs connected to ST25R3911B expansion board). On PC side, the ST25 SDK based on ST25R3911DISCOComm.dll provides a Java API to communicate with tags of various technologies (T2T, T4T, etc.) over the ST25R3911B-DISCO. Unfortunately, for C#, the demo code only provides tag inventory and entry points to the DLL. As previously said, you can use rfalTransceiveBlockingTxRx from the DLL to send arbitrary commands to the tag but this supposes to know the commands set of the tag and to encode/decode the various commands and responses.

I would suggest to contact your local ST sales and marketing to have a local support for your application.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Ulysses HERNIOSUS
Technical Moderator
March 15, 2022

Hi,

for completeness:

the t2t* functions are exported by the DLL but not used inside the C# code. Feel free to add them to C# (C headers are available).

BR, Ulysses

DDve.1
DDve.1Author
Associate II
March 17, 2022

Yep, that's what I did! But my own usage of the function produces only error "NoMessage" :( This is my code:

uint data_len = 32;
var card_data = new sbyte[data_len];
ErrorCode = ST25R3911_Dll.t2tRead4Pages(Handle, 0, card_data, ref data_len);
if (ErrorCode == ST25R3911ComError.NoError) {
	Console.WriteLine("I read: " + card_data.Take((int)data_len).Select(b => ((byte)b).ToX()).Join(" "));
} else {
	Console.WriteLine("Error reading data: " + ErrorCode);
}