iJa*_*Jay 7 c# smartcard winscard
有谁知道如何监控智能卡的存在并读取卡的UID值?
是的我在网上尝试过很多例子
但不知道该怎么做.我可以检测卡的存在并且可以单独获取UID,但不知道如何在我的应用程序中组合它们:(.
帮我
iJa*_*Jay 13
我明白了.想与任何有兴趣的人分享.
我使用winscard.dll函数来访问卡数据并与PC通信.
请注意,我使用Mifare 1K卡作为NFC标签和读卡器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;
}
Run Code Online (Sandbox Code Playgroud)
对于任何有兴趣的人,我已经写了一步一步的指导来实现这一点.
请享用!!!
| 归档时间: |
|
| 查看次数: |
11658 次 |
| 最近记录: |