Esempio n. 1
0
        /// <summary>
        /// If all the devices have been enumerated, select the device in the list we connected to. Otherwise let the EnumerationComplete event
        /// from the device watcher handle the device selection
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="deviceInformation"></param>
        private void OnDeviceConnected(EventHandlerForUsbDevice sender, DeviceInformation deviceInformation)
        {
            // Find and select our connected device
            if (isAllDevicesEnumerated)
            {
            }

            //rootPage.NotifyUser("Currently connected to: " + EventHandlerForUSBDevice.Current.DeviceInformation.Id, NotifyType.StatusMessage);
        }
Esempio n. 2
0
 /// <summary>
 /// The device was closed. If we will auto-reconnect to the device, reflect that in the UI
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="deviceInformation"></param>
 private async void OnDeviceClosing(EventHandlerForUsbDevice sender, DeviceInformation deviceInformation)
 {
     //await rootPage.Dispatcher.RunAsync(
     //    CoreDispatcherPriority.Normal,
     //    new DispatchedHandler(() =>
     //    {
     //        // We were connected to the device that was unplugged, so change the "Disconnect from device" button
     //        // to "Do not reconnect to device"
     //        if (ButtonDisconnectFromDevice.IsEnabled && EventHandlerForDevice.Current.IsEnabledAutoReconnect)
     //        {
     //            ButtonDisconnectFromDevice.Content = ButtonNameDisableReconnectToDevice;
     //        }
     //    }));
 }
Esempio n. 3
0
        private async Task <bool> ConnectUsbDeviceAsync(UsbDeviceInformation usbDeviceInfo)
        {
            //cast device object to UsbDeviceEntry
            //UsbDeviceInformation usbDeviceInfo = (UsbDeviceInformation)device.DeviceObject;

            // Create an EventHandlerForDevice to watch for the device we are connecting to
            EventHandlerForUsbDevice.CreateNewEventHandlerForDevice();

            // Get notified when the device was successfully connected to or about to be closed
            EventHandlerForUsbDevice.Current.OnDeviceConnected = this.OnDeviceConnected;
            EventHandlerForUsbDevice.Current.OnDeviceClose     = this.OnDeviceClosing;

            //Debug.WriteLine("Trying to open USB device " + device.Description + " @ " + usbDevice.InstanceId);

            // It is important that the FromIdAsync call is made on the UI thread because the consent prompt can only be displayed
            // on the UI thread. Since this method is invoked by the UI, we are already in the UI thread.
            bool openResult = await EventHandlerForUsbDevice.Current.OpenDeviceAsync(usbDeviceInfo.DeviceInformation, usbDeviceInfo.DeviceSelector).ConfigureAwait(false);

            //Debug.WriteLineIf(openResult, "Device open successfully.");
            Debug.WriteLineIf(!openResult, "Failed to open device.");

            return(openResult);
        }
 /// <summary>
 /// Creates a new instance of EventHandlerForUSBEclo, 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()
 {
     eventHandlerForNetMFDevice = new EventHandlerForUsbDevice(true);
 }
 /// <summary>
 /// Creates a new instance of EventHandlerForUSBEclo, enables auto reconnect, and uses it as the Current instance.
 /// </summary>
 public static void CreateNewEventHandlerForDevice()
 {
     eventHandlerForNetMFDevice = new EventHandlerForUsbDevice(false);
 }