Esempio n. 1
0
        void SendCommand(IntPtr hContext, string readerName)
        {
            int  dwResponseSize;
            long lResult;

            byte[] response          = new byte[2048];
            byte[] commnadSelectFile = { 0xff, 0xA4, 0x00, 0x01, 0x02, 0x0b, 0x10 };
            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.Log("SelectFile error");
                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.Log("ReadBinary error");
                return;
            }
            parse_tag(response);
        }
Esempio n. 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に受け取ったバイト数)
        }