コード例 #1
0
        protected DokanError ReadPayload(out byte[] payload, out string extension)
        {
            payload   = null;
            extension = String.Empty;

            // Make sure the chip is still here
            if (!rfidListener.ReconnectOnCard())
            {
                log.Error("Card reconnection failed");
                return(DokanError.ErrorNotReady);
            }

            IChip        chip = rfidListener.GetChip();
            ICardService svc  = chip.GetService(CardServiceType.CST_NFC_TAG);
            IDESFireEV1NFCTag4CardService nfcsvc = svc as IDESFireEV1NFCTag4CardService;

            if (nfcsvc == null)
            {
                log.Error("No NFC service.");
                // If no NFC service for this chip, we must fail
                return(DokanError.ErrorNotReady);
            }

            try
            {
                NdefMessage ndef = nfcsvc.ReadNDEFFile();
                if (ndef != null)
                {
                    if (ndef.GetRecordCount() > 0)
                    {
                        // For now, only support for one Ndef record per card
                        object[] records = ndef.Records as object[];
                        if (records != null)
                        {
                            INdefRecord record     = records[0] as INdefRecord;
                            object      payloadobj = record.Payload;
                            if (payloadobj != null)
                            {
                                payload = payloadobj as byte[];
                                payload = ParsePayload(record, payload, out extension);
                            }
                            else
                            {
                                log.Error("Bad record payload");
                            }
                        }
                    }
                    else
                    {
                        log.Info("No NDEF record in the message");
                    }
                }
                else
                {
                    log.Info("No NDEF message on this card");
                }
            }
            catch (COMException ex)
            {
                log.Info("NDEF read error", ex);
            }

            return(DokanError.ErrorSuccess);
        }