我的工作,需要读取Mifare卡序列号的应用程序,我有工作语言是C#。
I am working on an application that required reading the mifare card serial number, the language I am working with is C#.
我是新来的MIFARE读卡器编程,所以我很抱歉问愚蠢的问题。 起初,我想知道是否有UID的Mifare和Mifare序列号之间的不同。
I am new to mifare reader programming, so I am sorry for asking dumb question. At first I would like to know if there is a different between Mifare UID and Mifare Serial number.
我设法得到的UID与WinSCard库的帮助,但我不能弄明白如何让这应该是10位数字的卡的序列号。
I have managed to get UID with the help of WinSCard library, but I cant figure it out how to get the card serial number which should be 10 digit numbers.
我做AP preciate如果你可以点我到正确的方向。
I do appreciate if you could point me to the right direction.
在此先感谢您的帮助。 问候
Thanks in advance for the help. Regards
C#签名SCardTransmit法
[StructLayout(LayoutKind.Sequential)]
public struct SCARD_IO_REQUEST
{
public int dwProtocol;
public int cbPciLength;
}
[DllImport("winscard.dll")]
public static extern int SCardTransmit(int hCard, ref SCARD_IO_REQUEST pioSendRequest, ref byte SendBuff, int SendBuffLen, ref SCARD_IO_REQUEST pioRecvRequest,
ref byte RecvBuff, ref int RecvBuffLen);
有关Mifare卡读取UID的 code示例
Code Example for read UID of mifare card
private SmartcardErrorCode GetUID(ref byte[] UID)
{
byte[] receivedUID = new byte[10];
UnsafeNativeMethods.SCARD_IO_REQUEST request = new UnsafeNativeMethods.SCARD_IO_REQUEST();
request.dwProtocol = 1; //SCARD_PROTOCOL_T1);
request.cbPciLength = System.Runtime.InteropServices.Marshal.SizeOf(typeof(UnsafeNativeMethods.SCARD_IO_REQUEST));
byte[] sendBytes = new byte[] { 0xFF, 0xCA, 0x00, 0x00, 0x04 }; //get UID command for Mifare cards
int outBytes = receivedUID.Length;
int status = SCardTransmit(_hCard, ref request, ref sendBytes[0], sendBytes.Length, ref request, ref receivedUID[0], ref outBytes);
UID = receivedUID.Take(8).ToArray();
return status;
}