获取智能卡序列号SCardGetAttrib返回错误50

本文关键字:错误 返回 SCardGetAttrib 智能卡 序列号 获取 | 更新日期: 2023-09-27 18:22:25

我正在使用ACS-ACR88智能读卡器。我正在尝试使用Winscard.dll中的SCardGetAttrib功能读取智能卡序列号,但它总是返回错误50。50未在智能卡返回值中定义。错误50为0x32,可能是ERROR_NOT_SUPPORTED

我寻找它可能的含义,发现它可能意味着读卡器的驱动程序!以下是答案的链接:Re:SCardGetAttrib,SERIAL_NO,error 50。

我更新了司机,但运气不好。以下是我迄今为止所做的:

private static UInt32 SCardAttrValue(UInt32 attrClass, UInt32 val)
{
    return (attrClass) * (2 << 16) | val;
}
private const uint SCARD_CLASS_VENDOR_DEFINED = 7;
public static UInt32 VENDOR_NAME { get { return SCardAttrValue(SCARD_CLASS_VENDOR_DEFINED, 0x100); } }
private void button2_Click(object sender, EventArgs e)
{
    var lReturn = GetAttribute((uint)hCard, VENDOR_NAME);
    lblData.Text = lReturn.ToString();    
}
public byte[] GetAttribute(uint m_hCard, UInt32 AttribId)
{
    byte[] attr = new byte[] { };// null;
    UInt32 attrLen = 0;
    attr.Initialize();
    int m_nLastError = ModWinsCard.SCardGetAttrib(m_hCard, AttribId, attr, out attrLen); //====    error 50 occurs here
    if (m_nLastError == 0)
    {
        if (attrLen != 0)
        {
            attr = new byte[attrLen];
            m_nLastError = ModWinsCard.SCardGetAttrib(m_hCard, AttribId, attr, out attrLen);
            if (m_nLastError != 0)
            {
                string msg = "SCardGetAttr error: " + m_nLastError;
                throw new Exception(msg);
            }
        }
    }
    else
    {
        string msg = "SCardGetAttr error: " + m_nLastError;
        throw new Exception(msg);
    }
}

为什么我在使用SCardGetAttrib时收到错误,以及如何修复它?

获取智能卡序列号SCardGetAttrib返回错误50

也许为时已晚,但我认为您的AttribId值是错误的。您可以在下面的链接中查找AttribId值,而不是自己从六进制转换为十进制

http://pyscard.sourceforge.net/epydoc/smartcard.scard.scard-module.html