两周以来,我一直致力于读取有源 NFC TI 芯片的标签和存储的链接。
我在阅读 ATR 时也有问题。
我的阅读器是 Springcard H663。
我使用 winScard.dll 并设法使用SCardEstablishContext()
并SCardConnect()
成功开始工作,包括它们作为包装器。
现在我有一个星期的问题,没有任何进展。
我不知道如何访问标签或存储的信息或为函数提供哪些值。
[StructLayout(LayoutKind.Sequential)]
public struct SCARD_IO_REQUEST
{
public int dwProtocol;
public int cbPciLength;
}
和
[DllImport("WinScard.dll")]
public static extern int SCardTransmit(IntPtr hCard,
ref SCARD_IO_REQUEST pioSendPci,
ref byte[] pbSendBuffer,
int cbSendLength,
ref SCARD_IO_REQUEST pioRecvPci,
ref byte[] pbRecvBuffer,
ref int pcbRecvLength);
是io结构和包装器的实现。
这是我尝试访问信息的方式:
internal static void _readtag(string readername)
{
IntPtr phCard = IntPtr.Zero;
IntPtr activeProtocoll = IntPtr.Zero;
try
{
get_readerconnection(readername,
(uint)PROTOCOL_T1,
phCard,
activeProtocoll); // SCardEstablishContext and SCardConnection
int Rueckgabewert;
SCARD_IO_REQUEST ioRequest = new SCARD_IO_REQUEST();
ioRequest.dwProtocol = (int)wrapper.PROTOCOL_T0;
ioRequest.cbPciLength = 8;
byte[] commandBytes = new byte[] { 0xFF, 0xCA, 0x00, 0x00, 0x00 };
byte[] reciveBytes = new byte[10];
int rcvLenght = 0;
Rueckgabewert = SCardTransmit(phCard,
ref ioRequest,
ref commandBytes,
commandBytes.Length,
ref ioRequest,
ref reciveBytes,
ref rcvLenght);
if (Rueckgabewert != 0)
Console.WriteLine("Failed querying tag UID: " + Error_in_String((uint)Rueckgabewert));
Console.WriteLine(Methoden.ByteToString(reciveBytes));
wrapper.SCardDisconnect(phCard, 0);
}
finally
{
wrapper.SCardReleaseContext(phCard);
}
return;
为了完整起见,我向您展示了我的 ByteToString 函数:
public static string ByteToString(byte[] ByteArray)
{
ASCIIEncoding ascii = new ASCIIEncoding();
string multi_string = ascii.GetString(ByteArray);
return multi_string;
}
也是我的get_readerconnection(...)
功能:
internal static void get_readerconnection(string readername,
uint Reader_Protocol,
IntPtr phCard,
IntPtr ActiveProtocol)
{
try
{
phCard = IntPtr.Zero;
ActiveProtocol = IntPtr.Zero;
IntPtr hContext = get_hContext();
// using mode =2
// readerprotocol =3
int result = SCardConnect(hContext, readername, 2, Reader_Protocol, ref phCard, ref ActiveProtocol);
Error_in_String((uint)result);
}
catch
{
}
}
我的问题是如何_readertag(..)
处理获取标签、链接或 ATR 的功能。我怎样才能显示结果?
我在网上搜索过,但大多数代码对我来说都太先进了,而 MSDN 对我没有帮助,而且代码项目上的代码对我来说也很复杂。
我将非常感谢您的帮助!
弗雷德里克