Ejemplo n.º 1
0
        protected virtual void OnReceiveFoundCardMessage(ref Message m)
        {
            IntPtr      pDevInfo    = m.LParam;
            IntPtr      pDeviceData = ParseDeviceData(pDevInfo);
            DEVICE_INFO dev_info    = (DEVICE_INFO)Marshal.PtrToStructure(pDevInfo, typeof(DEVICE_INFO));

            switch (dev_info.target_device)
            {
            case DEVICE_TYPE_NFC_18092_212K:
                DispatchNfcFEvent(pDeviceData);
                break;

            case DEVICE_TYPE_NFC_18092_424K:
                DispatchNfcFEvent(pDeviceData);
                break;

            case DEVICE_TYPE_NFC_14443A_18092_106K:
                DispatchNfcAEvent(pDeviceData);
                break;

            case DEVICE_TYPE_NFC_14443B_106K:
                DispatchNfcBEvent(pDeviceData);
                break;
            }

            FeliCaNfcDllWrapperClass.FeliCaLibNfcStopDevAccess(0x00);
        }
Ejemplo n.º 2
0
        protected virtual void OnReceiveFoundCardMessage(ref Message m)
        {
            IntPtr pDevInfo = m.LParam;
            IntPtr pDeviceData;

            if (IntPtr.Size == 8)
            {
                pDeviceData = (IntPtr)((Int64)pDevInfo
                                       + (Int64)Marshal.OffsetOf(typeof(DEVICE_INFO), "dev_info"));
            }
            else
            {
                pDeviceData = (IntPtr)((Int32)pDevInfo
                                       + (Int32)Marshal.OffsetOf(typeof(DEVICE_INFO), "dev_info"));
            }

            DEVICE_INFO dev_info = (DEVICE_INFO)Marshal.PtrToStructure(pDevInfo, typeof(DEVICE_INFO));

            switch (dev_info.target_device)
            {
            case DEVICE_TYPE_NFC_18092_212K:
            case DEVICE_TYPE_NFC_18092_424K:
                DEVICE_DATA_NFC_18092_212_424K deviceData_F =
                    (DEVICE_DATA_NFC_18092_212_424K)Marshal.PtrToStructure(pDeviceData,
                                                                           typeof(DEVICE_DATA_NFC_18092_212_424K));

                string idm = Util.ToHexString(deviceData_F.NFCID2);
                MessageBox.Show(this, idm, "discover nfc tag");

                break;
            }

            FeliCaNfcDllWrapperClass.FeliCaLibNfcStopDevAccess(0x00);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// ライブラリの解放
        /// (DisposeLibraryを実行した場合、次の利用では再びInitializeLibraryを実行する)
        /// </summary>
        /// <returns></returns>
        public bool DisposeLibrary()
        {
            bool bRet = false;

            if (detected)
            {
                UInt32 RE_NOTIFICATION_SAME_DEVICE = 0x00;
                UInt32 stop_mode = RE_NOTIFICATION_SAME_DEVICE;
                bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcStopDevAccess(stop_mode);
                if (bRet == false)
                {
                    Debug.Write("Failed: FeliCaLibNfcStopDevAccess\n");
                    ErrorRoutine();
                    return(false);
                }
                detected = false;
            }

            if (opend)
            {
                bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcClose();
                if (bRet == false)
                {
                    Debug.Write("Failed: FeliCaLibNfcClose\n");
                    ErrorRoutine();
                    return(false);
                }
                opend = false;
            }

            if (initialized)
            {
                bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcUninitialize();
                if (bRet == false)
                {
                    Debug.Write("Failed: FeliCaLibNfcUninitialize\n");
                    ErrorRoutine();
                    return(false);
                }
                initialized = false;
            }

            cmd = null;
            res = null;
            Debug.Write("Success Dispose Library\n");
            return(true);
        }
Ejemplo n.º 4
0
        static Int32 Main(string[] args)
        {
            bool           bRet              = false;
            String         msg_str_of_find   = "find";
            String         msg_str_of_enable = "enable";
            ListenerWindow lw = new ListenerWindow();

            UInt32 card_find_message = RegisterWindowMessage(msg_str_of_find);

            if (card_find_message == 0)
            {
                Console.Write("Failed: RegisterWindowMessage\n");
                return(EXIT_FAILED);
            }

            UInt32 card_enable_message = RegisterWindowMessage(msg_str_of_enable);

            if (card_enable_message == 0)
            {
                Console.Write("Failed: RegisterWindowMessage\n");
                return(EXIT_FAILED);
            }

            bRet = lw.WatchMessage(card_find_message);
            if (bRet == false)
            {
                Console.Write("Failed: WatchMessage\n");
                return(EXIT_FAILED);
            }

            bRet = lw.WatchMessage(card_enable_message);
            if (bRet == false)
            {
                Console.Write("Failed: WatchMessage\n");
                return(EXIT_FAILED);
            }

            MessageHandler messageHandler
                = new MessageHandler(card_find_message, card_enable_message);

            lw.handler
                += new MessageReceivedEventHandler(messageHandler.messageHandlerFunc);

            bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcInitialize();
            if (bRet == false)
            {
                Console.Write("Failed: FeliCaLibNfcInitialize\n");
                ErrorRoutine();
                return(EXIT_FAILED);
            }

            StringBuilder port_name = new StringBuilder("USB0");

            bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcOpen(port_name);
            if (bRet == false)
            {
                Console.Write("Failed: FeliCaLibNfcOpen\n");
                ErrorRoutine();
                return(EXIT_FAILED);
            }

            bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcSetPollCallbackParameters(
                lw.Handle,
                msg_str_of_find,
                msg_str_of_enable);
            if (bRet == false)
            {
                Console.Write("Failed: FeliCaLibNfcSetPollCallbackParameters\n");
                ErrorRoutine();
                return(EXIT_FAILED);
            }

            const Int32 DEVICE_TYPE_NFC_14443A_18092_106K = 0x00000001;
            UInt32      target_device = DEVICE_TYPE_NFC_14443A_18092_106K;

            bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcStartPollMode(target_device);
            if (bRet == false)
            {
                Console.Write("Failed: FeliCaLibNfcStartPollMode\n");
                ErrorRoutine();
                return(EXIT_FAILED);
            }

            Application.Run(lw);

            if (messageHandler.bRet == false)
            {
                ErrorRoutine();
                return(EXIT_FAILED);
            }

            byte[] command_packet_data = new byte[2] {
                0x30, 0x00
            };                                                          // Command for Mifare ultralight, &H30: 16byte Reading command, &H0: Start address
            UInt16 command_packet_data_length = 2;

            byte[] response_packet_data        = new byte[BUFSIZ];
            UInt16 response_packet_data_length = 0x00;

            bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcThru(
                command_packet_data,
                command_packet_data_length,
                response_packet_data,
                ref response_packet_data_length);
            if (bRet == false)
            {
                Console.Write("Failed: FeliCaLibNfcThru\n");
                ErrorRoutine();
                return(EXIT_FAILED);
            }

            for (Int32 idx = 0; idx < 16; idx++)
            {
                Console.Write("response_packet_data[{0}]: 0x{1:X2}\n", idx, response_packet_data[idx]);
            }

            UInt32 RE_NOTIFICATION_SAME_DEVICE = 0x00;
            UInt32 stop_mode = RE_NOTIFICATION_SAME_DEVICE;

            bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcStopDevAccess(stop_mode);
            if (bRet == false)
            {
                Console.Write("Failed: FeliCaLibNfcStopDevAccess\n");
                ErrorRoutine();
                return(EXIT_FAILED);
            }

            bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcStopPollMode();
            if (bRet == false)
            {
                Console.Write("Failed: FeliCaLibNfcStopPollMode\n");
                ErrorRoutine();
                return(EXIT_FAILED);
            }

            bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcClose();
            if (bRet == false)
            {
                Console.Write("Failed: FeliCaLibNfcClose\n");
                ErrorRoutine();
                return(EXIT_FAILED);
            }

            bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcUninitialize();
            if (bRet == false)
            {
                Console.Write("Failed: FeliCaLibNfcUninitialize\n");
                ErrorRoutine();
                return(EXIT_FAILED);
            }

            Console.Write("Succeed\n");

            return(EXIT_SUCCEED);
        }