private async Task <bool> ConnectUsbDeviceAsync(UsbDeviceInformation usbDeviceInfo) { // try to determine if we already have this device opened. if (EventHandlerForUsbDevice.Current != null) { // device matches if (EventHandlerForUsbDevice.Current.DeviceInformation == usbDeviceInfo.DeviceInformation) { return(true); } } // Create an EventHandlerForDevice to watch for the device we are connecting to EventHandlerForUsbDevice.CreateNewEventHandlerForDevice(); return(await EventHandlerForUsbDevice.Current.OpenDeviceAsync(usbDeviceInfo.DeviceInformation, usbDeviceInfo.DeviceSelector).ConfigureAwait(false)); }
/// <summary> /// Creates a new instance of EventHandlerForUSBDevice, disables auto reconnect, and uses it as the Current instance. /// Background tasks do not need to worry about app events, so we will not be registering for app events /// </summary> public static void CreateNewEventHandlerForDeviceForBackgroundTasks() { eventHandlerForNanoFrameworkDevice = new EventHandlerForUsbDevice(true); }
/// <summary> /// Creates a new instance of EventHandlerForUSBDevice, enables auto reconnect, and uses it as the Current instance. /// </summary> public static void CreateNewEventHandlerForDevice() { eventHandlerForNanoFrameworkDevice = new EventHandlerForUsbDevice(false); }