Пример #1
0
        void SendCommand(IntPtr hContext, string readerName)
        {
            int dwResponseSize;

            byte[] response = new byte[2048];
            long   lResult;

            byte[] commnadSelectFile = { 0xff, 0xA4, 0x00, 0x01, 0x02, 0x0f, 0x09 };
            byte[] commnadReadBinary = { 0xff, 0xb0, 0x00, 0x00, 0x00 };

            IntPtr SCARD_PCI_T1 = getPciT1();

            NfcApi.SCARD_IO_REQUEST ioRecv = new NfcApi.SCARD_IO_REQUEST();
            ioRecv.cbPciLength = 2048;
            IntPtr hCard = connect(hContext, readerName);

            dwResponseSize = response.Length;
            lResult        = NfcApi.SCardTransmit(hCard, SCARD_PCI_T1, commnadSelectFile, commnadSelectFile.Length, ioRecv, response, ref dwResponseSize);
            if (lResult != NfcConstant.SCARD_S_SUCCESS)
            {
                Debug.WriteLine("SelectFile error\n");
                return;
            }
            dwResponseSize = response.Length;
            lResult        = NfcApi.SCardTransmit(hCard, SCARD_PCI_T1, commnadReadBinary, commnadReadBinary.Length, ioRecv, response, ref dwResponseSize);
            if (lResult != NfcConstant.SCARD_S_SUCCESS)
            {
                Debug.WriteLine("ReadBinary error\n");
                return;
            }
            parse_tag(response);
        }
Пример #2
0
        int transmit(IntPtr hCard, byte[] sendBuffer, byte[] recvBuffer)
        {
            NfcApi.SCARD_IO_REQUEST ioRecv = new NfcApi.SCARD_IO_REQUEST();
            ioRecv.cbPciLength = 255;

            int    pcbRecvLength = recvBuffer.Length;
            int    cbSendLength  = sendBuffer.Length;
            IntPtr SCARD_PCI_T1  = getPciT1();
            uint   ret           = NfcApi.SCardTransmit(hCard, SCARD_PCI_T1, sendBuffer, cbSendLength, ioRecv, recvBuffer, ref pcbRecvLength);

            if (ret != NfcConstant.SCARD_S_SUCCESS)
            {
                Debug.LogWarning("カードへの送信に失敗しました。code = " + ret);
            }
            return(pcbRecvLength); // 受信したバイト数(recvBufferに受け取ったバイト数)
        }