Beispiel #1
0
        public ActionResult OnButton(string parameterName)
        {
            string result = "dummy";

            List<string> deviceNameList = new List<string>();

            NFCContext nfcContext = new NFCContext();

            NFCDevice nfcDevice = nfcContext.OpenDevice(null);

            deviceNameList = nfcContext.ListDeviceNames();

            Console.WriteLine("device count: " + deviceNameList.Count());

            foreach (string deviceName in deviceNameList)
            {
                Console.WriteLine("deviceName: " + deviceName);
            }

            int rtn = nfcDevice.initDevice();
            if (rtn < 0)
            {
                Console.WriteLine("Context init failed");
            }

            nfc_target nfcTarget = new nfc_target();
            List<nfc_modulation> nfc_modulationList = new List<nfc_modulation>();
            nfc_modulation nfcModulation = new nfc_modulation();
            nfcModulation.nbr = nfc_baud_rate.NBR_106;
            nfcModulation.nmt = nfc_modulation_type.NMT_ISO14443A;

            nfc_modulationList.Add(nfcModulation);
            rtn = nfcDevice.Pool(nfc_modulationList, 1, 2, out nfcTarget);

            if (rtn < 0)
            {
                Console.WriteLine("nfc poll targert failed");
            }
            else if (rtn > 0)
            {
                Console.WriteLine("nfc target found!!!");

                string s = nfcDevice.str_target(nfcTarget);

                Console.Write(s);
            }
            else
            {
                Console.WriteLine("no nfc target found");
            }

            Console.WriteLine(result);
            return Json(new { success = true, show = result }, JsonRequestBehavior.AllowGet);
        }
Beispiel #2
0
 public static extern int nfc_initiator_select_passive_target(IntPtr pnd, nfc_modulation nm, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] byte[] pbtInitData, uint szInitData, IntPtr pnt);
Beispiel #3
0
 public static extern int nfc_initiator_list_passive_targets(IntPtr pnd, nfc_modulation nm, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)]  nfc_target[] ant, uint szTargets);
Beispiel #4
0
 public static extern int nfc_initiator_list_passive_targets(IntPtr pnd, nfc_modulation nm, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)]  nfc_target[] ant, uint szTargets);
Beispiel #5
0
 public static extern int nfc_initiator_select_passive_target(IntPtr pnd, nfc_modulation nm, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] byte[] pbtInitData, uint szInitData, IntPtr pnt);
        private static void ThreadSmartCard()
        {
            var gpio23 = TinyGPIO.Export(23);
            gpio23.Direction = (GPIODirection)GPIODirection.Out;

            List<string> deviceNameList = new List<string>();

            NFCContext nfcContext = new NFCContext();

            NFCDevice nfcDevice = nfcContext.OpenDevice(null);

            deviceNameList = nfcContext.ListDeviceNames();

            Console.WriteLine("Device Count: " + deviceNameList.Count());

            foreach (string deviceName in deviceNameList)
            {
                Console.WriteLine("Device Name: " + deviceName);
            }

            int rtn = nfcDevice.initDevice();
            if (rtn < 0)
            {
                Console.WriteLine("Context init failed");
            }

            nfc_target nfcTarget = new nfc_target();
            List<nfc_modulation> nfc_modulationList = new List<nfc_modulation>();
            nfc_modulation nfcModulation = new nfc_modulation();
            nfcModulation.nbr = nfc_baud_rate.NBR_106;
            nfcModulation.nmt = nfc_modulation_type.NMT_ISO14443A;

            nfc_modulationList.Add(nfcModulation);

            string currentSignalRStr = null;
            string currentConsoleStr = null;
            string signalRStr;
            string consoleStr;
            string state = "---";

            for (; ; )
            {
                gpio23.Value = 0;
                Thread.Sleep(100);
                rtn = nfcDevice.Pool(nfc_modulationList, 1, 2, out nfcTarget);

                if (rtn < 0)
                {
                    consoleStr = "NFC-Poll Targert Not Found!";
                    signalRStr = "---";
                    gpio23.Value = 0;

                }
                else
                {
                    signalRStr = string.Join(
                        separator: "",
                        values: nfcTarget.nti.abtUid.Take((int)nfcTarget.nti.szUidLen).Select(b => b.ToString("X2").ToLower())
                     );

                    signalRStr = "0x" + signalRStr;

                    consoleStr = string.Format("NFC-Poll Target Found: uid is [{0}]", signalRStr);
                }
                if (signalRStr != state)
                {
                    if (signalRStr != currentSignalRStr)
                    {
                        NFC.Instance.UpdateNFCStatus(signalRStr);
                        currentSignalRStr = signalRStr;
                        gpio23.Value = 1;
                        Thread.Sleep(100);
                    }
                    else
                    {
                        gpio23.Value = 0;
                    }
                }
                else
                {
                    gpio23.Value = 0;
                    NFC.Instance.UpdateNFCStatus(signalRStr);
                    currentSignalRStr = signalRStr;
                }

                if (consoleStr != currentConsoleStr)
                {
                    Console.WriteLine(consoleStr);
                    currentConsoleStr = consoleStr;
                }
            }
        }
        private static void ThreadSmartCard()
        {
            RaspPiGPIOMemLcdTransferProvider lcdProvider = new RaspPiGPIOMemLcdTransferProvider(
            GPIOPins.V2_GPIO_07,
            GPIOPins.V2_GPIO_08,
            GPIOPins.V2_GPIO_25,
            GPIOPins.V2_GPIO_24,
            GPIOPins.V2_GPIO_23,
            GPIOPins.V2_GPIO_18);
            Lcd lcd = new Lcd(lcdProvider);
            lcd.Begin(16, 2);
            lcd.Clear();
            lcd.SetCursorPosition(0, 0);
            lcd.Write("No NFC Card!");

            var gpio22 = TinyGPIO.Export(22);
            gpio22.Direction = (GPIODirection)GPIODirection.Out;

            List<string> deviceNameList = new List<string>();
            NFCContext nfcContext = new NFCContext();
            NFCDevice nfcDevice = nfcContext.OpenDevice(null);
            deviceNameList = nfcContext.ListDeviceNames();
            Console.WriteLine("Device Count: " + deviceNameList.Count());
            foreach (string deviceName in deviceNameList)
            {
                Console.WriteLine("Device Name: " + deviceName);
            }
            int rtn = nfcDevice.initDevice();
            if (rtn < 0)
            {
                Console.WriteLine("Context init failed");
            }

            nfc_target nfcTarget = new nfc_target();
            List<nfc_modulation> nfc_modulationList = new List<nfc_modulation>();
            nfc_modulation nfcModulation = new nfc_modulation();
            nfcModulation.nbr = nfc_baud_rate.NBR_106;
            nfcModulation.nmt = nfc_modulation_type.NMT_ISO14443A;
            nfc_modulationList.Add(nfcModulation);

            string currentSignalRStr = null;
            string currentConsoleStr = null;
            string currentlcdStr = null;
            string signalRStr;
            string consoleStr;
            string lcdStr;
            string state = "---";

            for (; ; )
            {
                gpio22.Value = 0;
                Thread.Sleep(100);
                rtn = nfcDevice.Pool(nfc_modulationList, 1, 2, out nfcTarget);

                if (rtn < 0)
                {
                    consoleStr = "NFC-Poll Targert Not Found!";
                    signalRStr = "---";
                    lcdStr = "No NFC Card!";
                    gpio22.Value = 0;
                }
                else
                {
                    signalRStr = string.Join(
                        separator: "",
                        values: nfcTarget.nti.abtUid.Take((int)nfcTarget.nti.szUidLen).Select(b => b.ToString("X2").ToLower())
                     );
                    signalRStr = "0x" + signalRStr;
                    consoleStr = string.Format("NFC-Poll Target Found: uid is [{0}]", signalRStr);
                    lcdStr = "NFC Detected!";
                }
                if (signalRStr != state)
                {
                    if (signalRStr != currentSignalRStr)
                    {
                        NFC.Instance.UpdateNFCStatus(signalRStr);
                        currentSignalRStr = signalRStr;
                        gpio22.Value = 1;
                        lcd.Begin(16, 2);
                        lcd.Clear();
                        lcd.SetCursorPosition(0, 0);
                        lcd.Write("NFC Detected!");
                        lcd.SetCursorPosition(0, 1);
                        lcd.Write(signalRStr);
                        currentlcdStr = lcdStr;
                        Thread.Sleep(100);
                    }
                    else
                    {
                        gpio22.Value = 0;
                    }
                }
                else
                {
                    if (lcdStr != currentlcdStr)
                    {
                        gpio22.Value = 0;
                        NFC.Instance.UpdateNFCStatus(signalRStr);
                        currentSignalRStr = signalRStr;
                        lcd.Begin(16, 2);
                        lcd.Clear();
                        lcd.SetCursorPosition(0, 0);
                        lcd.Write("No NFC Card!");
                        currentlcdStr = lcdStr;
                    }
                }
                if (consoleStr != currentConsoleStr)
                {
                    Console.WriteLine(consoleStr);
                    currentConsoleStr = consoleStr;
                }
            }
        }