public static bool TasteMifareMini(this NfcTarget target)
        {
            NfcModulation      nm  = target.ReadModulation();
            nfc_iso14443a_info nai = target.ReadInfo <nfc_iso14443a_info>();

            return(nm.ModulationType == NfcModulationType.ISO14443A && (
                       nai.btSak == 0x09
                       ));
        }
示例#2
0
        protected override async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            this.m_logger.LogInformation("Started nfcService");
            //byte pollNr = 20;
            //byte period = 2;
            //var modulations = new[]
            //{
            //    new NfcModulation(NfcModulationType.ISO14443A, NfcBaudRate.BR106),
            //    new NfcModulation(NfcModulationType.ISO14443B, NfcBaudRate.BR106),
            //    new NfcModulation(NfcModulationType.Felica, NfcBaudRate.BR212),
            //    new NfcModulation(NfcModulationType.Felica, NfcBaudRate.BR424),
            //    new NfcModulation(NfcModulationType.Jewel, NfcBaudRate.BR106),
            //};


            NfcModulation mod = new NfcModulation(NfcModulationType.ISO14443A, NfcBaudRate.BR106);

            using (NfcContext ctx = new NfcContext())
                using (var device = ctx.Open(null))
                {
                    var initiator = device.InitInitiator(false);

                    while (!cancellationToken.IsCancellationRequested)
                    {
                        var tag = initiator.SelectMifareTag();
                        if (tag == null)
                        {
                            await Task.Delay(100, cancellationToken);

                            continue;
                        }

                        using (tag)
                        {
                            this.m_logger.LogInformation("Card detected");
                            this.m_hub.All.cardOn();
                            while (tag.IsPresent() && !cancellationToken.IsCancellationRequested)
                            {
                                await Task.Delay(100, cancellationToken);
                            }
                            this.m_logger.LogInformation("Card removed");
                            this.m_hub.All.cardOff();
                        }
                        await Task.Delay(1000, cancellationToken);
                    }
                }
            this.m_logger.LogInformation("Stopped nfcService");
        }
示例#3
0
        private static void PollTagsAndDisplayInfo(INfcInitiator initiator)
        {
            NfcModulation mod = new NfcModulation(NfcModulationType.ISO14443A, NfcBaudRate.BR106);

            using (var tags = initiator.ListPassiveTargets(mod))
            {
                Console.WriteLine("Found tags: {0} for modulation {1}", tags.Count, mod);
                Console.WriteLine("Last error: {0}", ((NfcDevice)initiator).LastError);
                if (tags.Count == 0)
                {
                    return;
                }

                foreach (var target in tags)
                {
                    DisplayInfo(target);
                }
            }
            ////There are tags, select one
            //Console.WriteLine("Selecting Mifare tag");
            //var tag = initiator.SelectMifareTag();
            //if (tag == null)
            //{
            //    Console.WriteLine("No corresponding tags selected");
            //    return;
            //}
            //using (tag)
            //{
            //    Console.WriteLine("Tag on board");


            //    while (tag.IsPresent())
            //    {
            //        Thread.Sleep(300);
            //        Console.Write(".");
            //    }
            //    Console.WriteLine();
            //    Console.WriteLine("Tag removed");
            //}
        }
 public static extern int initiator_select_passive_target(IntPtr device, NfcModulation modulation, IntPtr pbtInitData, int szInitData, IntPtr pnt);
 public static extern int initiator_list_passive_targets(IntPtr device, NfcModulation modulation, IntPtr targets, int targetsCount);