我有一个使用智能卡读卡器的应用程序允许用户访问系统的各个部分.在一个地方我没有问题.但是另一种具有不同类型的卡制造商的问题存在很多问题.它不断获得零回报.然后查看事件日志,我看到了这个:
这是代码:
card.Connect(reader, SHARE.Shared, PROTOCOL.T0orT1);
var apduGetID = new APDUCommand(0xFF, 0xCA, 0, 0, null, 4);
var apduRespGetID = card.Transmit(apduGetID);
long cardId = BitConverter.ToUInt32(apduRespGetID.Data.Reverse().ToArray(), 0);
Run Code Online (Sandbox Code Playgroud)
第二个问题是,然后尝试调试代码,它工作完美,只有删除断点,我可以看到问题,但不是在哪里.有人可以帮帮我吗?
PS我找到了这个帖子,但它不起作用:https://superuser.com/questions/715688/smart-card-errors
更新:这是Transmit类
public override APDUResponse Transmit(APDUCommand ApduCmd)
{
var RecvLength = (uint)(ApduCmd.Le + APDUResponse.SW_LENGTH);
byte[] ApduBuffer;
var ApduResponse = new byte[ApduCmd.Le + APDUResponse.SW_LENGTH];
var ioRequest = new SCard_IO_Request
{
m_dwProtocol = m_nProtocol,
m_cbPciLength = 8
};
// Build the command APDU
if (ApduCmd.Data == null)
{
ApduBuffer = new byte[APDUCommand.APDU_MIN_LENGTH + ((ApduCmd.Le != 0) ? 1 : 0)];
if (ApduCmd.Le != 0)
{
ApduBuffer[4] = ApduCmd.Le;
}
}
else
{
ApduBuffer = new byte[APDUCommand.APDU_MIN_LENGTH + 1 + ApduCmd.Data.Length];
for (var nI = 0; nI < ApduCmd.Data.Length; nI++)
{
ApduBuffer[APDUCommand.APDU_MIN_LENGTH + 1 + nI] = ApduCmd.Data[nI];
}
ApduBuffer[APDUCommand.APDU_MIN_LENGTH] = (byte)ApduCmd.Data.Length;
}
ApduBuffer[0] = ApduCmd.Class;
ApduBuffer[1] = ApduCmd.Ins;
ApduBuffer[2] = ApduCmd.P1;
ApduBuffer[3] = ApduCmd.P2;
m_nLastError = SCardTransmit(m_hCard, ref ioRequest, ApduBuffer, (uint)ApduBuffer.Length, IntPtr.Zero, ApduResponse, out RecvLength);
if (m_nLastError != 0)
{
var msg = "SCardTransmit error: " + m_nLastError;
throw new SmartCardException(msg, m_nLastError);
}
var apduData = new byte[RecvLength];
for (var nI = 0; nI < RecvLength; nI++)
{
apduData[nI] = ApduResponse[nI];
}
return new APDUResponse(apduData);
}
Run Code Online (Sandbox Code Playgroud)
更新2:我也尝试过放一些Thread.Sleep()
请检查第二台机器上是否拥有智能卡的所有最新驱动程序。此外,有时它有助于替换制造商提供的“Microsoft WUDF 驱动程序”驱动程序 - https://msdn.microsoft.com/en-us/library/windows/hardware/dn653571(v=vs.85) .aspx
请注意,插入操作系统时,操作系统会检测到两种类型的设备 - 智能卡枚举器设备(智能卡读卡器)和智能卡(有时称为智能卡容器)本身。一台智能卡读卡器可以容纳多张智能卡。
智能卡示例,其驱动程序被强制替换为 Microsoft WUDF 以使客户端应用程序 (iBank2) 正常工作:

四个智能卡驱动程序已被强制替换为基本的 Microsoft 驱动程序,以使应用程序正常运行。
| 归档时间: |
|
| 查看次数: |
1611 次 |
| 最近记录: |