NFC Tags Example

This example demonstrates the usage of Tag discovery and NDEF discovery APIs and various read\write operations, which can be performed with the tags.

Note: This example is developed for devices with NFC support.

Download

Click on the following link to download the example: nfctags.zip

Click: browse to view the example code.

Use cases

The following use cases are demonstrated by the example:

  • Tag Discovery : How to detect Type 1, Type 2, Type 3, Type 4 and MIFARE Classic type tags.

  • NDEF Discovery: How to detect different types of NDEF messages.

  • Operations on tags: How to do read\write operations on the tags.

APIs demonstrated

MNfcTagConnectionListener::TagDetected( MNfcTag* )

MNfcTagConnectionListener::TagLost()

MNdefMessageListener::MessageDetected( CNdefMessage* )

CNfcTagSubscription::AddConnectionModeL(TNfcConnectionInfo::TNfcConnectionMode )

CNfcTagDiscovery::AddTagSubscriptionL( const CNfcTagSubscription& )

MNfcTag::OpenConnection( MNfcConnection& )

CNdefDiscoveryr::AddNdefMessageListener( MNdefMessageListener& )

CNdefDiscovery::AddNdefSubscription( const CNdefRecord::TNdefRecordTnf , const TDesC8& aType )

CNdefDiscovery::AddNdefMessageListener( MNdefMessageListener& )

CNdefDiscovery::RemoveNdefMessageListener()

CNdefDiscovery::RemoveAllNdefSubscription()

CNfcTagDiscovery::RemoveTagConnectionListener()

CNfcTagDiscovery::RemoveTagSubscription()

CIso14443Connection::ExchangeData( TRequestStatus& , const TDesC8& , TDes8& )

CNfcType1Connection::Write( TRequestStatus& , const TDesC8& , const TNfcType1Address& )

CNfcType1Connection::Read( TRequestStatus& , TDes8&aBuffer, TUint , const TNfcType1Address& )

CNfcType2Connection::Read( TRequestStatus& , TDes8& aBuffer, TUint , const TNfcType2Address& )

CNfcType2Connection::Write( TRequestStatus& , const TDesC8& , TUint32 )

CNfcType3Connection::Check( TRequestStatus& , TDes8& , TUint aAmount, const TNfcType3Address& aAddress )

CNfcType3Connection::Update( TRequestStatus& , const TDes8& , const TNfcType3Address& )

CMifareClassicConnection::ReadSector(TRequestStatus& aStatus, CMifareClassicSector& , TUint8 , const TDesC8& , const TDesC8& )

CMifareClassicConnection::WriteSector( TRequestStatus& , const CMifareClassicSector& , TUint8 , const TDesC8& , const TDesC8& )

CNfcTagDiscovery::RemoveTagSubscription()

Building and configuring

You can build the example from your IDE or the command line.

If you use an IDE, import the nfcexample.pro file of the example into your IDE, and use the build command of the IDE.

If you use the command line, complete the following:

  1. Open a command prompt.

  2. Set the current directory to the source code directory of the example.

  3. Build the example with the following SBSv2 build commands:

    • qmake
    • sbs

This example builds an executable called nfctags.exe in the standard locations.

Running the example

After running the example application, the user is provided with the following menu options.

  • Start Tag Discovery.

  • Start NDEF Discovery

Start Tag Discovery :

If you select this menu option, the NFC enabled device:

  1. Detects the tag, when in NFC range.

  2. Opens a connection with the tag.

  3. Writes data to the tag.

  4. Reads data from the tag.

  5. Displays the information read from the tag.

The menu option then changes to Stop Tag Discovery, you can stop discovering the tags by using this menu item.

Once Stop Tag discovery is selected, you will return to the main menu.

Start NDEF Discovery:

If you select this menu option, the NFC enabled device:

  1. Searches for NDEF messages, according to the user subscription.

  2. On detection, displays the message.

The menu option then changes to Stop NDEF Discovery, you can stop discovering the NDEF messages by using this menu item.

Once Stop NDEF discovery is selected, you will return to the main menu.