You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用合适的.Net库读取NXP ICode SLIX的Tag ID与NDEF记录?

Reading NDEF Records & Tag ID from NXP ICode SLIX Tags in .NET

Hey there, I totally get the frustration here—NXP ICode SLIX tags (which follow the ISO 15693 standard) are way less supported in the .NET ecosystem compared to more common MIFARE cards, and most off-the-shelf PC/SC libraries only handle generic smart card operations without tailored support for this specific tag type.

The good news is: since these tags adhere to ISO 15693, you can bypass the lack of high-level library support by sending raw ISO 15693 commands directly via a basic PC/SC library like pcsc-sharp. Let’s break this down step by step:

1. Set Up Card Connection with pcsc-sharp

First, establish a connection to your reader and the tag using pcsc-sharp (it’s the most reliable low-level PC/SC library for .NET):

using PCSC;
using System;
using System.Linq;

var context = new SCardContext();
context.Establish(SCardScope.System);

var readers = context.GetReaders();
if (readers.Length == 0)
{
    Console.WriteLine("No compatible readers detected");
    return;
}

// Connect to the first detected reader, auto-negotiate protocol
using var card = new SCardCard(context, readers[0], SCardShareMode.Shared, SCardProtocol.Any);
card.Connect();

Make sure your reader supports ISO 15693 (most NFC readers like ACR122U do).

2. Read the Tag ID (UID)

Use the ISO 15693 Inventory command (0x01) to fetch the tag’s unique ID. This is the most reliable way to get the UID for ISO 15693 tags:

// ISO 15693 Inventory command: [CLA, INS, Command, Flags]
// Flags 0x00 = no subcarrier, no address required
var inventoryCmd = new byte[] { 0x00, 0x00, 0x01, 0x00 };
var response = card.Transmit(inventoryCmd);

// Response format: [Status Code (1 byte) + UID (8 bytes)]
if (response.Length >= 9 && response[0] == 0x00) // 0x00 = success
{
    var tagId = BitConverter.ToString(response.Skip(1).Take(8).ToArray()).Replace("-", "");
    Console.WriteLine($"Tag ID (UID): {tagId}");
}
else
{
    Console.WriteLine("Failed to retrieve Tag ID—check reader/tag compatibility");
}

If this fails, try adjusting the Flags byte to 0x20 (enables subcarrier, required for some readers).

3. Read & Parse NDEF Records

NDEF data on ICode SLIX tags is stored in contiguous memory blocks (typically 4 bytes per block). Use the ISO 15693 Read Multiple Blocks command (0x23) to pull this data, then parse it with an NDEF library.

Step 3.1: Fetch Raw Block Data

// Read blocks 0 to 10 (adjust range based on your tag's NDEF storage location)
// Command format: [CLA, INS, Command, Flags, Start Block, Number of Blocks]
var readBlocksCmd = new byte[] { 0x00, 0x00, 0x23, 0x00, 0x00, 0x0A };
var ndefRawResponse = card.Transmit(readBlocksCmd);

if (ndefRawResponse[0] != 0x00)
{
    Console.WriteLine("Failed to read NDEF blocks");
    return;
}

// Skip the status code byte to get raw NDEF data
var ndefRawData = ndefRawResponse.Skip(1).ToArray();

Note: Check the ICode SLIX datasheet for your specific model to confirm the starting block for NDEF storage (some variants use block 4 instead of 0).

Step 3.2: Parse NDEF Data

Use the NdefLibrary NuGet package to handle NDEF parsing (it’s lightweight and works well with raw ISO 15693 data):

using NdefLibrary.Ndef;

try
{
    var ndefMessage = NdefMessage.FromByteArray(ndefRawData);
    foreach (NdefRecord record in ndefMessage)
    {
        Console.WriteLine("\nNDEF Record Details:");
        Console.WriteLine($"Type: {BitConverter.ToString(record.Type)}");
        Console.WriteLine($"Payload: {Encoding.UTF8.GetString(record.Payload)}");
    }
}
catch (Exception ex)
{
    Console.WriteLine($"Failed to parse NDEF data: {ex.Message}");
}

If you can’t use the NuGet package, you can manually parse the NDEF structure by checking the TNF (Type Name Format) byte at the start of the raw data.

4. Troubleshooting Tips

  • Protocol Issues: If commands fail, force the connection to use SCardProtocol.T1 (ISO 15693 often uses this protocol).
  • Tag Variants: ICode SLIX-L/SLIX-S have different memory layouts—always refer to the official NXP datasheet for your tag model.
  • Cardwerk API: If you prefer using Cardwerk’s library, look for a method to send raw APDUs (e.g., TransmitCommand) and use the same ISO 15693 commands above.

By working directly with the underlying ISO 15693 standard, you can bypass the lack of pre-built .NET support for ICode SLIX tags.

内容的提问来源于stack exchange,提问作者Guillaume Raymond

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:43:41