Exemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            _currentState = HUD_STATE.NotDetected;
            System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
            EmbeddedFwMaxIndex = 0;
            string[] ls = a.GetManifestResourceNames();
            for (int z = 0; z < ls.Length; z++)
            {
                if (ls[z].StartsWith(prefixFirmware))
                {
                    cbFirmwareSelector.Items.Add(ls[z].Substring(prefixFirmware.Length));
                    EmbeddedFwMaxIndex++;
                }
            }

            /* custom option */
            Console.WriteLine("Firmware Max Index {0}", EmbeddedFwMaxIndex - 1);
            cbFirmwareSelector.Items.Add("Select Custom File");

            setUI(_currentState);

            hotInitParams = new KHOT_PARAMS();

            // In the real world, you would want to filter for only *your* device(s).
            hotInitParams.PatternMatch.DeviceInterfaceGUID = "*";

            // The PLUG_ALL_ON_INIT flag will force plug events for matching devices that are already connected.
            hotInitParams.Flags = KHOT_FLAG.PLUG_ALL_ON_INIT;

            hotInitParams.OnHotPlug = OnHotPlug;

            // You may set your initial hot handle user context like this.
            // This example is using it to count connected devices and detect the first OnHotPlug event (Int32.MaxValue).
            AllKFunctions.LibK_SetDefaultContext(KLIB_HANDLE_TYPE.HOTK, new IntPtr(Int32.MaxValue));

            // Start hot-plug detection.
            HotK hot = new HotK(ref hotInitParams);

            tbStatus.Text  = "Firmware Updater v1.0\r\n";
            tbStatus.Text += "Application started\r\n";
        }
Exemplo n.º 2
0
        private static void Main()
        {
            KHOT_PARAMS hotInitParams = new KHOT_PARAMS();

            // In the real world, you would want to filter for only *your* device(s).
            hotInitParams.PatternMatch.DeviceInterfaceGUID = "*";

            // The PLUG_ALL_ON_INIT flag will force plug events for matching devices that are already connected.
            hotInitParams.Flags = KHOT_FLAG.PLUG_ALL_ON_INIT;

            hotInitParams.OnHotPlug = OnHotPlug;

            /* Instead of a callback you can send/post messages directly to a window handle.
             * hotInitParams.UserHwnd = MyForm.Handle;
             * hotInitParams.UserMessage = WM_USER_HOT_BASE;
             */

            Console.WriteLine("Monitoring libusbK arrival/removal events.");
            Console.WriteLine("[PatternMatch]");
            Console.WriteLine(hotInitParams.PatternMatch.ToString());
            Console.WriteLine("Press [ENTER] to exit..");

            while (Console.KeyAvailable)
            {
                Console.ReadKey(true);
            }

            // You may set your initial hot handle user context like this.
            // This example is using it to count connected devices and detect the first OnHotPlug event (Int32.MaxValue).
            AllKFunctions.LibK_SetDefaultContext(KLIB_HANDLE_TYPE.HOTK, new IntPtr(Int32.MaxValue));

            // Start hot-plug detection.
            HotK hot = new HotK(ref hotInitParams);

            Console.ReadLine();

            hot.Free();
        }