Example #1
0
        //CARD IDENTIFICATION COMMANDS

        #region GetCSN
        /// <summary>
        /// Obtiene el número serial de la tarjeta mifare.
        /// </summary>
        /// <param name="csn">Arreglo de 6 bytes donde se guarda el CSN.</param>
        /// <param name="numbytes">Número de bytes recibidos</param>
        /// <returns>SUCCESS en caso de Exito o MifareStatusCodes.</returns>
        public int GetCSN(ref byte[] csn, ref int numbytes)
        {
            int status = 0;

            byte[] ucByteSend     = new byte[16];
            byte[] pucReceiveData = new byte[16];
            ucByteSend[0] = 0xFF; //CLA
            ucByteSend[1] = 0xCA; //INS
            ucByteSend[2] = 0x00; //P1
            ucByteSend[3] = 0x00; //P2
            ucByteSend[4] = 0x00; //Le
            int ulnByteSend           = 5;
            int pullReceiveDataBufLen = 36;

            int rc = scardr.Transmit(ucByteSend, ulnByteSend, ref pucReceiveData, ref pullReceiveDataBufLen);

            if (rc == 0)
            {
                status = pucReceiveData[pullReceiveDataBufLen - 2] << 8;
                status = status | pucReceiveData[pullReceiveDataBufLen - 1];

                if (status == MifareStatusCodes.SUCCESS)
                {
                    for (int i = 0; i < pullReceiveDataBufLen - 2; i++)
                    {
                        csn[i] = pucReceiveData[i];
                    }
                    numbytes = pullReceiveDataBufLen - 2;
                }
            }


            return(status);
        }