仅当ACR122U读卡器完全读取MiFare 1k卡时发出蜂鸣声

时间:2018-12-27 10:48:05

标签: c# smartcard mifare

如果在发出哔声后立即将卡取出,则会产生错误。

我只想要卡的UID;如果保留了存储卡,则可以使用,但是一旦听到蜂鸣声,我们往往会删除存储卡。 简而言之,我想延迟蜂鸣声,因此在完全读取之前不会取出卡。

public bool connectCard()
    {
        connActive = true;

        retCode = Card.SCardConnect(hContext, readername, Card.SCARD_SHARE_SHARED,
                  Card.SCARD_PROTOCOL_T0 | Card.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

        if (retCode != Card.SCARD_S_SUCCESS)
        {
            MessageBox.Show(Card.GetScardErrMsg(retCode), "Card not available");
            connActive = false;
            return false;
        }
        return true;
    }
 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(7).ToArray()).Replace("-", string.Empty).ToLower();
        }

        return cardUID;
    }

0 个答案:

没有答案