Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# read/write mifare nfc tag

Tags:

c#

nfc

I've searched a lot but I'm not able to find some C# simple sdk that lets me write and read in a nfc mifare 1k classic tags.

Could you give me some help please?

Thanks a lot.

like image 383
uoah Avatar asked Nov 13 '22 16:11

uoah


1 Answers

Just check my library for ACR122u readers. It also supports insert/discard events. It is so simple to use it. Basically you create a class and register two events to that class. Afterwards, call the Watch function. It watches the changes on your device.

//Initializing
NFCReader NFC = new NFCReader();

//Inserted Event 
NFC.CardInserted += new NFCReader.CardEventHandler(...Some function);

//Ejected Event
NFC.CardEjected += new NFCReader.CardEventHandler(... Some function);


//Enabling Event Watching
NFC.Watch();

If any change occurs, it calls the related event. You handle what you want to do there.

public void Card_Inserted()
{
  try
  {
    if (NFC.Connect())
    {
        //Do stuff like NFC.GetCardUID(); ...
    }
    else
    {
        //Give error message about connection...
    }
  }
  catch (Exception ex)
  {
    //Something went wrong
  }
}

public void Card_Ejected()
{
   //Do stuff...
   NFC.Disconnect();
}

See the related repo and links for more information.

Medium introduction tutorial: https://medium.com/@hakbas/nfcreader-a-very-simple-nfc-library-for-c-that-supports-insert-and-discard-events-93db29f79b5

Github address: https://github.com/h4kbas/NfcReader

like image 200
Hüseyin Akbaş Avatar answered Nov 15 '22 04:11

Hüseyin Akbaş