本文介绍了NET技术的智能卡读取器开发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何监视智能卡的存在并读取卡的UID值吗?

Does anyone know how to monitor the presence of smart card and read the UID value of the card?

是的,我尝试了很多类似网络的示例

Yes I tried lot of examples in web like

.NET的智能卡框架

pcsc清晰

监视智能卡阅读器

但是不知道该怎么做.我可以检测到卡的存在并可以分别获取UID,但是不知道如何在我的应用程序中将它们结合起来:(.

But No idea how to do it. I can detect the presence of a card and can get the UID separately, but no idea how to combine them in my application:( .

帮帮我

推荐答案

我知道了.想与任何有兴趣的人分享.

I figure it out. thought to share with anyone interested.

我使用了 winscard.dll 函数来访问卡数据并与PC进行通信.

I used winscard.dll functions to access card data and communicate with PC.

请注意,我将 Mifare 1K卡用作NFC标签和读取器 ACR 122u .

Note that I used Mifare 1K cards as NFC tag and reader ACR 122u.

    private string getcardUID()//only for mifare 1k cards
    {
        string cardUID = "";
        byte[] receivedUID = new byte[256];
        Card.SCARD_IO_REQUEST request = new Card.SCARD_IO_REQUEST();
        request.dwProtocol = Card.SCARD_PROTOCOL_T1;
        request.cbPciLength = System.Runtime.InteropServices.Marshal.SizeOf(typeof(Card.SCARD_IO_REQUEST));
        byte[] sendBytes = new byte[] { 0xFF, 0xCA, 0x00, 0x00, 0x00 }; //get UID command      for Mifare cards
        int outBytes = receivedUID.Length;
        int status = Card.SCardTransmit(hCard, ref request, ref sendBytes[0], sendBytes.Length, ref request, ref receivedUID[0], ref outBytes);

        if (status != Card.SCARD_S_SUCCESS)
        {
            cardUID = "Error";
        }
        else
        {
            cardUID = BitConverter.ToString(receivedUID.Take(4).ToArray()).Replace("-", string.Empty).ToLower();
        }

        return cardUID;
    }

对于有兴趣的人,我已经在此处编写了逐步指南以实现此目标.

For anyone interested I've written step by step guide to achieve this in here.

用于Windows的简单NFC阅读系统

享受!!!

这篇关于NET技术的智能卡读取器开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 18:02