public LibUsbConnectionService()
        {
            currentContext = SynchronizationContext.Current;
            NativeMethods.Init(out context);

            HotplugCallbackFunction cb = Callback;

            NativeMethods.HotplugRegisterCallback(context, HotplugEvent.DeviceArrived | HotplugEvent.DeviceLeft, 0,
                                                  (int)TreehopperUsb.Settings.Vid, (int)TreehopperUsb.Settings.Pid, NativeMethods.HotplugMatchAny, cb,
                                                  IntPtr.Zero, callbackHandle);
            InitialAdd();
            Task.Run(async() =>
            {
                while (true)
                {
                    NativeMethods.HandleEvents(context, IntPtr.Zero);
                    await Task.Delay(100).ConfigureAwait(false);
                }
            });
        }
Beispiel #2
0
 internal static extern int HotplugRegisterCallback([In] IntPtr context, HotplugEvent events, int flags,
                                                    int vendor_id, int product_id, int dev_class, HotplugCallbackFunction cb_fn, IntPtr user_data,
                                                    IntPtr HandleRef);