/// <summary> /// 初期化。 /// 最初に必ず呼び出すこと。 /// </summary> /// <returns>初期化処理結果</returns> public bool init() { bool bRet = false; if (mFeliCaNfcDllWrapperClass != null) { //初期化済み。 return(true); } // SDK for NFC Starter Kitのサンプル提供C#ラッパ mFeliCaNfcDllWrapperClass = new felica_nfc_dll_wrapper(); // Win32メッセージ登録 bRet = mListener.init(kMsgFind, kMsgEnable, ref mMessageHandler); if (!bRet) { return(false); } // SDK for NFC Starter Kit初期化 bRet = mFeliCaNfcDllWrapperClass.FeliCaLibNfcInitialize(); if (bRet == false) { Console.Write("Failed: FeliCaLibNfcInitialize\n"); ErrorRoutine(); return(false); } // R/Wオープン StringBuilder port_name = new StringBuilder("USB0"); bRet = mFeliCaNfcDllWrapperClass.FeliCaLibNfcOpen(port_name); if (bRet == false) { Console.Write("Failed: FeliCaLibNfcOpen\n"); ErrorRoutine(); return(false); } return(true); }
/// <summary> /// ライブラリの初期化 /// </summary> public void InitializeLibrary() { bool bRet = false; bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcInitialize(); if (bRet == false) { Debug.Write("Failed: FeliCaLibNfcInitialize\n"); Exception ex = GetMfException(); if (!(ex is NfcLibException) || ((NfcLibException)ex).ApiError != ApiErrorKind.FELICA_NFC_E_ALREADY_INITIALIZED) { ErrorRoutine(); throw ex; } } initialized = true; StringBuilder port = new StringBuilder(20); port.Append(""); bRet = FeliCaNfcDllWrapperClass.FeliCaLibNfcOpen(ref port); if (bRet == false) { Debug.Write("Failed: FeliCaLibNfcOpen\n"); Exception ex = GetMfException(); if (!(ex is NfcLibException) || ((NfcLibException)ex).ApiError != ApiErrorKind.FELICA_NFC_E_PORT_OPENED) { ErrorRoutine(); throw ex; } } opend = true; cmd = new byte[BUFFER_LENGTH]; res = new byte[BUFFER_LENGTH]; PollingTimeout = POLLING_TIMEOUT; Console.Write("Initialized MfLib\n"); }
//------------------------------------------------------------------------------// // 基本処理 //------------------------------------------------------------------------------// /// <summary> /// 初期化。 /// 最初に必ず呼び出すこと。 /// </summary> /// <returns>初期化処理結果</returns> public bool init() { bool bRet = false; if(mFeliCaNfcDllWrapperClass != null) { //初期化済み。 return true; } // SDK for NFC Starter Kitのサンプル提供C#ラッパ mFeliCaNfcDllWrapperClass = new felica_nfc_dll_wrapper(); // Win32メッセージ登録 #if true bRet = mListener.init(kMsgFind, kMsgEnable, ref mMessageHandler); if(!bRet) { return false; } #else UInt32 card_find_message = RegisterWindowMessage(kMsgFind); if(card_find_message == 0) { Console.Write("Failed: RegisterWindowMessage\n"); return false; } UInt32 card_enable_message = RegisterWindowMessage(kMsgEnable); if(card_enable_message == 0) { Console.Write("Failed: RegisterWindowMessage\n"); return false; } bRet = mListener.WatchMessage(card_find_message); if(bRet == false) { Console.Write("Failed: WatchMessage\n"); return false; } bRet = mListener.WatchMessage(card_enable_message); if(bRet == false) { Console.Write("Failed: WatchMessage\n"); return false; } mMessageHandler = new MessageHandler(card_find_message, card_enable_message); mListener.handler += new MessageReceivedEventHandler(mMessageHandler.messageHandlerFunc); #endif // SDK for NFC Starter Kit初期化 bRet = mFeliCaNfcDllWrapperClass.FeliCaLibNfcInitialize(); if(bRet == false) { Console.Write("Failed: FeliCaLibNfcInitialize\n"); ErrorRoutine(); return false; } // R/Wオープン StringBuilder port_name = new StringBuilder("USB0"); bRet = mFeliCaNfcDllWrapperClass.FeliCaLibNfcOpen(port_name); if(bRet == false) { Console.Write("Failed: FeliCaLibNfcOpen\n"); ErrorRoutine(); return false; } return true; }
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); }
//------------------------------------------------------------------------------// // 基本処理 //------------------------------------------------------------------------------// /// <summary> /// 初期化。 /// 最初に必ず呼び出すこと。 /// </summary> /// <returns>初期化処理結果</returns> public bool init() { bool bRet = false; if (mFeliCaNfcDllWrapperClass != null) { //初期化済み。 return(true); } // SDK for NFC Starter Kitのサンプル提供C#ラッパ mFeliCaNfcDllWrapperClass = new felica_nfc_dll_wrapper(); // Win32メッセージ登録 #if true bRet = mListener.init(kMsgFind, kMsgEnable, ref mMessageHandler); if (!bRet) { return(false); } #else UInt32 card_find_message = RegisterWindowMessage(kMsgFind); if (card_find_message == 0) { Console.Write("Failed: RegisterWindowMessage\n"); return(false); } UInt32 card_enable_message = RegisterWindowMessage(kMsgEnable); if (card_enable_message == 0) { Console.Write("Failed: RegisterWindowMessage\n"); return(false); } bRet = mListener.WatchMessage(card_find_message); if (bRet == false) { Console.Write("Failed: WatchMessage\n"); return(false); } bRet = mListener.WatchMessage(card_enable_message); if (bRet == false) { Console.Write("Failed: WatchMessage\n"); return(false); } mMessageHandler = new MessageHandler(card_find_message, card_enable_message); mListener.handler += new MessageReceivedEventHandler(mMessageHandler.messageHandlerFunc); #endif // SDK for NFC Starter Kit初期化 bRet = mFeliCaNfcDllWrapperClass.FeliCaLibNfcInitialize(); if (bRet == false) { Console.Write("Failed: FeliCaLibNfcInitialize\n"); ErrorRoutine(); return(false); } // R/Wオープン StringBuilder port_name = new StringBuilder("USB0"); bRet = mFeliCaNfcDllWrapperClass.FeliCaLibNfcOpen(port_name); if (bRet == false) { Console.Write("Failed: FeliCaLibNfcOpen\n"); ErrorRoutine(); return(false); } return(true); }
/// <summary> /// 初期化。 /// 最初に必ず呼び出すこと。 /// </summary> /// <returns>初期化処理結果</returns> public bool init() { bool bRet = false; if(mFeliCaNfcDllWrapperClass != null) { //初期化済み。 return true; } // SDK for NFC Starter Kitのサンプル提供C#ラッパ mFeliCaNfcDllWrapperClass = new felica_nfc_dll_wrapper(); // Win32メッセージ登録 bRet = mListener.init(kMsgFind, kMsgEnable, ref mMessageHandler); if(!bRet) { return false; } // SDK for NFC Starter Kit初期化 bRet = mFeliCaNfcDllWrapperClass.FeliCaLibNfcInitialize(); if(bRet == false) { Console.Write("Failed: FeliCaLibNfcInitialize\n"); ErrorRoutine(); return false; } // R/Wオープン StringBuilder port_name = new StringBuilder("USB0"); bRet = mFeliCaNfcDllWrapperClass.FeliCaLibNfcOpen(port_name); if(bRet == false) { Console.Write("Failed: FeliCaLibNfcOpen\n"); ErrorRoutine(); return false; } return true; }
private void NFCForm_Load(object sender, EventArgs e) { // デザインモードではNFCを動作させない if (DesignMode) { return; } string configPath = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath; Console.WriteLine("PATH"); Console.WriteLine(configPath); Console.WriteLine(configPath); Console.WriteLine(configPath); Console.WriteLine(configPath); if (Settings.Default.EnableNativeNfcLog) { string nativeNfcLog = Settings.Default.NativeNfcLog; Debug.WriteLine("Enable Nfc Log"); string fileName = Directory.GetCurrentDirectory() + @"\" + nativeNfcLog; FeliCaNfcDllWrapperClass.FeliCaLibNfcStartLogging(fileName); } Debug.WriteLine("RegisterWindowMessage, message=" + MSG_STR_OF_FIND); cardFindMessage = RegisterWindowMessage(MSG_STR_OF_FIND); if (cardFindMessage == 0) { Console.Error.WriteLine("Failed to register window message, param=" + MSG_STR_OF_FIND); return; } Debug.WriteLine("RegisterWindowMessage, message=" + MSG_STR_OF_ENABLE); cardEnableMessage = RegisterWindowMessage(MSG_STR_OF_ENABLE); if (cardEnableMessage == 0) { Console.Error.WriteLine("Failed to register window message, param=" + MSG_STR_OF_ENABLE); return; } bool result; Debug.WriteLine("initialize nfc library"); result = FeliCaNfcDllWrapperClass.FeliCaLibNfcInitialize(); if (!result) { Console.Error.WriteLine("Failed to nfc initialize library"); DispatchErrorEvent(); DisposeNfc(); return; } StringBuilder portName = new StringBuilder("USB0"); Debug.WriteLine("open nfc usb port, port name=" + portName.ToString()); result = FeliCaNfcDllWrapperClass.FeliCaLibNfcOpen(portName); if (!result) { Console.Error.WriteLine("Failed to nfc open, port_name=" + portName); DispatchErrorEvent(); DisposeNfc(); return; } Debug.WriteLine("set poll callback parameters, msf_str_of_find=" + MSG_STR_OF_FIND + ", msg_str_of_enable=" + MSG_STR_OF_ENABLE); result = FeliCaNfcDllWrapperClass.FeliCaLibNfcSetPollCallbackParameters(this.Handle, MSG_STR_OF_FIND, MSG_STR_OF_ENABLE); if (!result) { Console.Error.WriteLine("Failed to set poll callback parameters, msf_str_of_find=" + MSG_STR_OF_FIND + ", msg_str_of_enable=" + MSG_STR_OF_ENABLE); DispatchErrorEvent(); DisposeNfc(); return; } }
private void HandleForm_Shown(object sender, EventArgs e) { bool result; // NFCライブラリを初期化します result = FeliCaNfcDllWrapperClass.FeliCaLibNfcInitialize(); if (!result) { Console.Error.WriteLine("Failed to nfc initialize"); Close(); return; } // NFCライブラリを開きます StringBuilder portName = new StringBuilder("USB0"); result = FeliCaNfcDllWrapperClass.FeliCaLibNfcOpen(portName); if (!result) { Console.Error.WriteLine("Failed to nfc open, port_name=" + portName); HandleError(); Close(); return; } // NFCデバイス補足時のWindowメッセージを登録します。 cardFindMessage = RegisterWindowMessage(MsgStrOfFind); if (cardFindMessage == 0) { Console.Error.WriteLine("Failed to register window message, param=" + MsgStrOfFind); Close(); return; } cardEnableMessage = RegisterWindowMessage(MsgStrOfEnable); if (cardEnableMessage == 0) { Console.Error.WriteLine("Failed to register window message, param=" + MsgStrOfEnable); Close(); return; } result = FeliCaNfcDllWrapperClass.FeliCaLibNfcSetPollCallbackParameters(this.Handle, MsgStrOfFind, MsgStrOfEnable); if (!result) { Console.Error.WriteLine("Failed to set pall callback parameters, msf_str_of_find=" + MsgStrOfFind + ", msg_str_of_enable=" + MsgStrOfEnable); HandleError(); Close(); return; } // 補足するデバイスの種類を決定します。 UInt32 targetDevice = 0; targetDevice = targetDevice | DEVICE_TYPE_NFC_18092_212K; targetDevice = targetDevice | DEVICE_TYPE_NFC_18092_424K; // ポーリングを開始します。 FeliCaNfcDllWrapperClass.FeliCaLibNfcStartPollMode(targetDevice); if (!result) { Console.Error.WriteLine("Failed to start poll mode, target_device=" + targetDevice); HandleError(); Close(); return; } }