Inheritance: IDeviceWatcher
 /// <summary>
 /// Invoked when the device watcher finds a matching custom sensor device 
 /// </summary>
 /// <param name="watcher">device watcher</param>
 /// <param name="customSensorDevice">device information for the custom sensor that was found</param>
 public async void OnCustomSensorAdded(DeviceWatcher watcher, DeviceInformation customSensorDevice)
 {
     try
     {
         customSensor = await CustomSensor.FromIdAsync(customSensorDevice.Id);
         if (customSensor != null)
         {
             CustomSensorReading reading = customSensor.GetCurrentReading();
             if (!reading.Properties.ContainsKey(CO2LevelKey))
             {
                 rootPage.NotifyUser("The found custom sensor doesn't provide CO2 reading", NotifyType.ErrorMessage);
                 customSensor = null;
             }
         }
         else
         {
             rootPage.NotifyUser("No custom sensor found", NotifyType.ErrorMessage);
         }
     }
     catch (Exception e)
     {
         await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
         {
             rootPage.NotifyUser("The user may have denied access to the custom sensor. Error: " + e.Message, NotifyType.ErrorMessage);
         });
     }
 }
        private void StartWatcher()
        {
            DeviceWatcherEventKind[] triggerEventKinds = { DeviceWatcherEventKind.Add, DeviceWatcherEventKind.Remove, DeviceWatcherEventKind.Update };

            switch (m_deviceType)
            {
            case AudioDeviceType.Input:
            {
                m_deviceClass = DeviceClass.AudioRender;


                break;
            }

            case AudioDeviceType.Output:
            {
                m_deviceClass = DeviceClass.AudioRender;
                break;
            }
            }
            m_deviceWatcher = DeviceInformation.CreateWatcher(m_deviceClass);

            // Get the background trigger for this watcher
            m_deviceWatcherTrigger = m_deviceWatcher.GetBackgroundTrigger(triggerEventKinds);

            // Register this trigger for our background task
            RegisterBackgroundTask(m_deviceWatcherTrigger);
        }
Esempio n. 3
0
        public async Task <bool> StartAsync()
        {
            // only one start allowed on the object
            lock (this)
            {
                if (_started)
                {
                    return(false);
                }

                _started = true;
            }

            if (await WiFiAdapter.RequestAccessAsync() != WiFiAccessStatus.Allowed)
            {
                return(false);
            }

            _started = true;

            // enumerate and monitor WiFi devices in the system
            string deviceSelector = WiFiAdapter.GetDeviceSelector();

            _watcher          = Windows.Devices.Enumeration.DeviceInformation.CreateWatcher(deviceSelector);
            _watcher.Added   += _watcher_Added;
            _watcher.Removed += _watcher_Removed;

            _watcher.Start();

            return(true);
        }
Esempio n. 4
0
        private static void HandleDeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate args)
        {
            var gamepad = _gamepads[args.Id];

            _gamepads.Remove(args.Id);
            GamepadRemoved?.Invoke(sender, gamepad);
        }
Esempio n. 5
0
        //public ObservableCollection<clsDevType> DevTypes = new ObservableCollection<clsDevType>();

        async void WatchDevices_Click(object sender, RoutedEventArgs eventArgs)
        {
            if (watcher != null)
            {
                watcher = null;
            }
            count = 0;
            isEnumerationComplete = false;
            StopStatus            = null;
            //DeviceInterfacesOutputList.Items.Clear();

            try
            {
                dispatcher = Window.Current.CoreWindow.Dispatcher;
                watcher    = DeviceInformation.CreateWatcher();
                // Add event handlers
                watcher.Added   += watcher_Added;
                watcher.Removed += watcher_Removed;
                watcher.Updated += watcher_Updated;
                watcher.EnumerationCompleted += watcher_EnumerationCompleted;
                watcher.Stopped += watcher_Stopped;
                watcher.Start();
                OutputText.Text = "Enumeration started.";

                this.btnWatchDevices.IsEnabled = false;
                this.btnStop.IsEnabled         = !(this.btnWatchDevices.IsEnabled);
            }
            catch (ArgumentException)
            {
                //The ArgumentException gets thrown by FindAllAsync when the GUID isn't formatted properly
                //The only reason we're catching it here is because the user is allowed to enter GUIDs without validation
                //In normal usage of the API, this exception handling probably wouldn't be necessary when using known-good GUIDs
                OutputText.Text = "Caught ArgumentException. Failed to create watcher.";
            }
        }
        /// <summary>
        /// Invoked when the device watcher detects that the proximity sensor was added.
        /// </summary>
        /// <param name="sender">The device watcher.</param>
        /// <param name="device">The device that was added.</param>
        private async void OnProximitySensorAddedAsync(DeviceWatcher sender, DeviceInformation device)
        {
            if (this.proximitySensor == null)
            {
                var addedSensor = ProximitySensor.FromId(device.Id);

                if (addedSensor != null)
                {
                    var minimumDistanceSatisfied = true;

                    //if we care about minimum distance
                    if (this.MinimumDistanceInMillimeters > Int32.MinValue)
                    {
                        if ((this.MinimumDistanceInMillimeters > addedSensor.MaxDistanceInMillimeters) ||
                            (this.MinimumDistanceInMillimeters < addedSensor.MinDistanceInMillimeters))
                        {
                            minimumDistanceSatisfied = false;
                        }
                    }

                    if (minimumDistanceSatisfied)
                    {
                        this.proximitySensor = addedSensor;

                        await SetActiveFromReadingAsync(this.proximitySensor.GetCurrentReading());

                        this.proximitySensor.ReadingChanged += ProximitySensor_ReadingChangedAsync;
                    }
                }
            }
        }
Esempio n. 7
0
 private void OnDeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate deviceInformationUpdate)
 {
     if (Disconnected != null)
     {
         Disconnected();
     }
 }
Esempio n. 8
0
        async void watcher_Removed(Windows.Devices.Enumeration.DeviceWatcher sender, DeviceInformationUpdate devUpdate)
        {
            ;
            int count2 = 0;
            //Convert interfaces array to a list (IList).
            List <DeviceInformation> interfaceList = new List <DeviceInformation>(interfaces);

            foreach (DeviceInformation deviceInterface in interfaces)
            {
                if (count2 < count)
                {
                    if (interfaces[count2].Id == devUpdate.Id)
                    {
                        //Remove the element.
                        interfaceList.RemoveAt(count2);
                    }
                }
                count2 += 1;
            }
            //Convert the list back to the interfaces array.
            interfaces = interfaceList.ToArray();
            count     -= 1;
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                OutputText.Text = "Enumeration device was removed. ";
                DisplayDeviceInterfaceArray();
            });
        }
Esempio n. 9
0
        static public void StartSearch()
        {
            // Additional properties we would like about the device.
            // Property strings are documented here https://msdn.microsoft.com/en-us/library/windows/desktop/ff521659(v=vs.85).aspx
            string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected", "System.Devices.Aep.Bluetooth.Le.IsConnectable", "System.Devices.Aep.AepId", "System.Devices.Aep.Category" };

            // BT_Code: Example showing paired and non-paired in a single query.
            string aqsAllBluetoothLEDevices = "(System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\")";

            deviceWatcher =
                DeviceInformation.CreateWatcher(
                    aqsAllBluetoothLEDevices,
                    requestedProperties,
                    DeviceInformationKind.AssociationEndpoint);

            // Register event handlers before starting the watcher.
            deviceWatcher.Added   -= DeviceWatcher_Added;
            deviceWatcher.Updated -= DeviceWatcher_Updated;
            deviceWatcher.Removed -= DeviceWatcher_Removed;
            deviceWatcher.EnumerationCompleted -= DeviceWatcher_EnumerationCompleted;
            deviceWatcher.Stopped -= DeviceWatcher_Stopped;
            deviceWatcher.Added   += DeviceWatcher_Added;
            deviceWatcher.Updated += DeviceWatcher_Updated;
            deviceWatcher.Removed += DeviceWatcher_Removed;
            deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;
            deviceWatcher.Stopped += DeviceWatcher_Stopped;

            // Start the watcher.
            deviceWatcher.Start();
            if (_searchMethod == 0)
            {
                _autoEvent.WaitOne();
            }
        }
Esempio n. 10
0
 public ExternalDeviceService()
 {
     _deviceWatcher = DeviceInformation.CreateWatcher(DeviceClass.PortableStorageDevice);
     _deviceWatcher.Added += DeviceAdded;
     _deviceWatcher.Removed += DeviceRemoved;
     _deviceWatcher.Start();
 }
Esempio n. 11
0
 private void DeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate args)
 {
     if (ExternalDeviceRemoved != null)
     {
         ExternalDeviceRemoved(this, args.Id);
     }
 }
Esempio n. 12
0
 public UsbScopeDevice()
 {
     var usbScopeSelector = HidDevice.GetDeviceSelector(UsagePage, UsageId, Vid, Pid);
     ScopeDeviceWatcher = DeviceInformation.CreateWatcher(usbScopeSelector);
     ScopeDeviceWatcher.Added += new TypedEventHandler<DeviceWatcher, DeviceInformation>(OnDeviceAdded);
     ScopeDeviceWatcher.Removed += new TypedEventHandler<DeviceWatcher, DeviceInformationUpdate>(OnDeviceRemoved);
     ScopeDeviceWatcher.Start();
 }
        public Scenario4_BackgroundProximitySensor()
        {
            this.InitializeComponent();

            watcher = DeviceInformation.CreateWatcher(ProximitySensor.GetDeviceSelector());
            watcher.Added += OnProximitySensorAdded;
            watcher.Start();
        }
Esempio n. 14
0
        private static async void HandleDeviceAdded(DeviceWatcher sender, DeviceInformation args)
        {
            var device = await HidDevice.FromIdAsync(args.Id, FileAccessMode.Read);
            var gamepad = new HidGamepad(args, device);

            _gamepads.Add(args.Id, gamepad);
            GamepadAdded?.Invoke(sender, gamepad);
        }
Esempio n. 15
0
 public NetworkPresenter()
 {
     WiFiAdaptersWatcher = DeviceInformation.CreateWatcher(WiFiAdapter.GetDeviceSelector());
     WiFiAdaptersWatcher.EnumerationCompleted += AdaptersEnumCompleted;
     WiFiAdaptersWatcher.Added += AdaptersAdded;
     WiFiAdaptersWatcher.Removed += AdaptersRemoved;
     WiFiAdaptersWatcher.Start();
 }
Esempio n. 16
0
 protected async override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     watcher = DeviceInformation.CreateWatcher(ProximitySensor.GetDeviceSelector());
     watcher.Added += OnProximitySensorAdded;
     watcher.Start();
     timer = new Timer(TimerCallBack, null, Timeout.Infinite, 4000);
     await InitializeCameraAsync();
 }
        /// <summary>
        /// Invoked when the device watcher finds a proximity sensor
        /// </summary>
        /// <param name="sender">The device watcher</param>
        /// <param name="device">Device information for the proximity sensor that was found</param>
        private async void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation device)
        {
            if (null == sensor)
            {
                ProximitySensor foundSensor = ProximitySensor.FromId(device.Id);
                if (null != foundSensor)
                {
                    if (null != foundSensor.MaxDistanceInMillimeters)
                    {
                        // Check if this is the sensor that matches our ranges.

                        // TODO: Customize these values to your application's needs.
                        // Here, we are looking for a sensor that can detect close objects
                        // up to 3cm away, so we check the upper bound of the detection range.
                        const uint distanceInMillimetersLValue = 30; // 3 cm
                        const uint distanceInMillimetersRValue = 50; // 5 cm

                        if (foundSensor.MaxDistanceInMillimeters >= distanceInMillimetersLValue &&
                            foundSensor.MaxDistanceInMillimeters <= distanceInMillimetersRValue)
                        {
                            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                rootPage.NotifyUser("Found a proximity sensor that meets the detection range", NotifyType.StatusMessage);
                            });
                        }
                        else
                        {
                            // We'll use the sensor anyway, to demonstrate how events work.
                            // Your app may decide not to use the sensor.
                            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                rootPage.NotifyUser("Proximity sensor does not meet the detection range, using it anyway", NotifyType.StatusMessage);
                            });
                        }
                    }
                    else
                    {
                        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            rootPage.NotifyUser("Proximity sensor does not report detection ranges, using it anyway", NotifyType.StatusMessage);
                        });
                    }

                    if (null != foundSensor)
                    {
                        sensor = foundSensor;
                    }
                }
                else
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        rootPage.NotifyUser("Could not get a proximity sensor from the device id", NotifyType.ErrorMessage);
                    });
                }
            }
        }
 private async void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
 {
     await coreDispatcher.RunAsync(
         CoreDispatcherPriority.Normal,
         () =>
         {
             FoundDeviceList.Add(args);
         });
 }
Esempio n. 19
0
    private async void DevicesRemoved(DeviceWatcher sender, DeviceInformationUpdate args)
    {
      //Debug.WriteLine("Removed USB device: " + args.Id);

      await dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
      {
        UpdateDevices();
      });
    }
Esempio n. 20
0
 private void watcher_Removed(Windows.Devices.Enumeration.DeviceWatcher sender, Windows.Devices.Enumeration.DeviceInformationUpdate args)
 {
     Debug.WriteLine(args.Id);
     this.BeginInvoke((Action)(() =>
     {
         //perform on the UI thread
         PrintDrives();
     }));
 }
Esempio n. 21
0
    private async void DevicesEnumCompleted(DeviceWatcher sender, object args)
    {
      //Debug.WriteLine("USB Devices Enumeration Completed");

      await dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
      {
        UpdateDevices();
      });
    }
Esempio n. 22
0
 public void Dispose()
 {
     if (_deviceWatcher != null)
     {
         _deviceWatcher.Stop();
         _deviceWatcher.Added -= DeviceAdded;
         _deviceWatcher.Removed -= DeviceRemoved;
         _deviceWatcher = null;
     }
 }
Esempio n. 23
0
 static HidGamepad()
 {
     var deviceSelector = HidDevice.GetDeviceSelector(0x01, 0x05);
     _watcher = DeviceInformation.CreateWatcher(deviceSelector);
     _watcher.Added += HandleDeviceAdded;
     _watcher.Updated += HandleDeviceUpdated;
     _watcher.Removed += HandleDeviceRemoved;
     _watcher.EnumerationCompleted += HandleEnumerationCompleted;
     _watcher.Start();
 }
Esempio n. 24
0
 async void watcher_EnumerationCompleted(Windows.Devices.Enumeration.DeviceWatcher sender, object args)
 {
     isEnumerationComplete = true;
     await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         OutputText.Text = "Enumeration complete. ";
         DisplayDeviceInterfaceArray();
         tblLatest.Text = "";
     });
 }
        /// <summary>
        /// Invoked when the device watcher detects that the proximity sensor was removed.
        /// </summary>
        /// <param name="sender">The device watcher.</param>
        /// <param name="device">The device that was removed.</param>
        private void OnProximitySensorRemoved(DeviceWatcher sender, DeviceInformationUpdate device)
        {
            if ((this.proximitySensor != null) && (this.proximitySensor.DeviceId == device.Id))
            {
                this.proximitySensor.ReadingChanged -= ProximitySensor_ReadingChangedAsync;
                this.proximitySensor = null;

                SetActive(false);
            }
        }
Esempio n. 26
0
    public ConnectedDevicePresenter(CoreDispatcher dispatcher)
    {
      this.dispatcher = dispatcher;

      usbConnectedDevicesWatcher = DeviceInformation.CreateWatcher(usbDevicesSelector);
      usbConnectedDevicesWatcher.EnumerationCompleted += DevicesEnumCompleted;
      usbConnectedDevicesWatcher.Updated += DevicesAdded;
      usbConnectedDevicesWatcher.Removed += DevicesRemoved;
      usbConnectedDevicesWatcher.Start();
    }
        /// <summary>
        /// Create a PosDeviceWatcher.
        /// </summary>
        /// <param name="deviceSelector">Device Selector string to use with DeviceWatcher</param>
        /// <param name="dispatcher">Associated UI element's Dispatcher so that updates to this.FoundDeviceList are done safely.</param>
        public PosDeviceWatcher(string deviceSelector, CoreDispatcher dispatcher)
        {
            FoundDeviceList = new ObservableCollection<DeviceInformation>();
            coreDispatcher = dispatcher;

            deviceWatcher = DeviceInformation.CreateWatcher(deviceSelector);
            deviceWatcher.Added += DeviceWatcher_Added;
            deviceWatcher.Removed += DeviceWatcher_Removed;
            deviceWatcher.Updated += DeviceWatcher_Updated;
        }
Esempio n. 28
0
        private void StartListeningForSerialPortChanges()
        {
            serialPortWatcher = DeviceInformation.CreateWatcher(SerialDevice.GetDeviceSelector());

            serialPortWatcher.Added += SerialPortWatcher_Added;
            serialPortWatcher.Removed += SerialPortWatcher_Removed;
            serialPortWatcher.Updated += SerialPortWatcher_Updated;

            serialPortWatcher.Start();
        }
        public MidiDeviceWatcher(DeviceWatcher watcher)
        {
            _watcher = watcher;

            // wire up events

            _watcher.Added += Watcher_Added;
            _watcher.Removed += Watcher_Removed;
            _watcher.Updated += Watcher_Updated;
            _watcher.EnumerationCompleted += Watcher_EnumerationCompleted;
        }
Esempio n. 30
0
        public DeviceWatcher()
        {
            subject = new Subject <IDevice>();
            const string selector = "System.Devices.InterfaceClassGuid:= \"{4D1E55B2-F16F-11CF-88CB-001111000030}\" AND System.Devices.InterfaceEnabled:= System.StructuredQueryType.Boolean#True";

            watcher          = DeviceInformation.CreateWatcher(selector);
            watcher.Added   += Watcher_Added;
            watcher.Removed += Watcher_Removed;
            watcher.Updated += Watcher_Updated;
            watcher.Stopped += Watcher_Stopped;
        }
Esempio n. 31
0
        public DeviceWatcher()
        {
            subject = new Subject <IDevice>();
            const string selector = "System.Devices.InterfaceClassGuid:= \"{A5DCBF10-6530-11D2-901F-00C04FB951ED}\" AND System.Devices.InterfaceEnabled:= System.StructuredQueryType.Boolean#True";

            watcher          = DeviceInformation.CreateWatcher(selector);
            watcher.Added   += Watcher_Added;
            watcher.Removed += Watcher_Removed;
            watcher.Updated += Watcher_Updated;
            watcher.Stopped += Watcher_Stopped;
        }
        public Scenario2_Polling()
        {
            String customSensorSelector = "";

            this.InitializeComponent();

            customSensorSelector = CustomSensor.GetDeviceSelector(GUIDCustomSensorDeviceVendorDefinedTypeID);
            watcher = DeviceInformation.CreateWatcher(customSensorSelector);
            watcher.Added += OnCustomSensorAdded;
            watcher.Start();
        }
Esempio n. 33
0
        static Blink1()
        {
            var selector = HidDevice.GetDeviceSelector(0xFF00, 0x0001, 0x27B8, 0x01ED);

            _watcher = DeviceInformation.CreateWatcher(selector);
            _watcher.Added += HandleDeviceAdded;
            _watcher.Updated += HandleDeviceUpdated;
            _watcher.Removed += HandleDeviceRemoved;
            _watcher.EnumerationCompleted += HandleEnumerationCompleted;
            _watcher.Start();
        }
Esempio n. 34
0
 async void watcher_Stopped(Windows.Devices.Enumeration.DeviceWatcher sender, object args)
 {
     if (watcher.Status == Windows.Devices.Enumeration.DeviceWatcherStatus.Aborted)
     {
         StopStatus = "Enumeration stopped unexpectedly. Click Watch to restart enumeration.";
     }
     else if (watcher.Status == Windows.Devices.Enumeration.DeviceWatcherStatus.Stopped)
     {
         StopStatus = "You requested to stop the enumeration. Click Watch to restart enumeration.";
     }
 }
        /// <summary>
        /// Constructor: Initialize and hook up Device Watcher events
        /// </summary>
        /// <param name="midiSelectorString">MIDI Device Selector</param>
        /// <param name="dispatcher">CoreDispatcher instance, to update UI thread</param>
        /// <param name="portListBox">The UI element to update with list of devices</param>
        internal MidiDeviceWatcher(string midiSelectorString, CoreDispatcher dispatcher, ListBox portListBox)
        {
            this.deviceWatcher = DeviceInformation.CreateWatcher(midiSelectorString);
            this.portList = portListBox;
            this.midiSelector = midiSelectorString;
            this.coreDispatcher = dispatcher;

            this.deviceWatcher.Added += DeviceWatcher_Added;
            this.deviceWatcher.Removed += DeviceWatcher_Removed;
            this.deviceWatcher.Updated += DeviceWatcher_Updated;
            this.deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;
        }
Esempio n. 36
0
        private async void Watcher_Added(Windows.Devices.Enumeration.DeviceWatcher sender, DeviceInformation args)
        {
            // FIXME: async void - need to log error or something
            var device = await HidDevice.FromIdAsync(args.Id, FileAccessMode.ReadWrite);

            if (device == null)
            {
                // we probably don't have permission to use it
                return;
            }
            subject.OnNext(new Device(args, device));
        }
Esempio n. 37
0
 async void watcher_Added(Windows.Devices.Enumeration.DeviceWatcher sender, DeviceInformation deviceInterface)
 {
     interfaces[count] = deviceInterface;
     count            += 1;
     if (isEnumerationComplete)
     {
         await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
         {
             DisplayDeviceInterfaceArray();
             OutputText.Text = "Watcher added: Enumeration was already complete.";
         });
     }
 }
        public Scenario3()
        {
            this.InitializeComponent();

            //Create our watcher and have it find casting devices capable of video casting
            watcher = DeviceInformation.CreateWatcher(CastingDevice.GetDeviceSelector(CastingPlaybackTypes.Video));

            //Register for watcher events
            watcher.Added += Watcher_Added;
            watcher.Removed += Watcher_Removed;
            watcher.Stopped += Watcher_Stopped;
            watcher.EnumerationCompleted += Watcher_EnumerationCompleted;
        }
        private void btnWatcher_Click(object sender, RoutedEventArgs e)
        {
            if (_fWatcherStarted == false)
            {
                _publisher.Start();

                if (_publisher.Status != WiFiDirectAdvertisementPublisherStatus.Started)
                {
                    rootPage.NotifyUser("Failed to start advertisement.", NotifyType.ErrorMessage);
                    return;
                }

                DiscoveredDevices.Clear();
                rootPage.NotifyUser("Finding Devices...", NotifyType.StatusMessage);

                String deviceSelector = WiFiDirectDevice.GetDeviceSelector(
                    Utils.GetSelectedItemTag<WiFiDirectDeviceSelectorType>(cmbDeviceSelector));

                _deviceWatcher = DeviceInformation.CreateWatcher(deviceSelector, new string[] { "System.Devices.WiFiDirect.InformationElements" });

                _deviceWatcher.Added += OnDeviceAdded;
                _deviceWatcher.Removed += OnDeviceRemoved;
                _deviceWatcher.Updated += OnDeviceUpdated;
                _deviceWatcher.EnumerationCompleted += OnEnumerationCompleted;
                _deviceWatcher.Stopped += OnStopped;

                _deviceWatcher.Start();

                btnWatcher.Content = "Stop Watcher";
                _fWatcherStarted = true;
            }
            else
            {
                _publisher.Stop();

                btnWatcher.Content = "Start Watcher";
                _fWatcherStarted = false;

                _deviceWatcher.Added -= OnDeviceAdded;
                _deviceWatcher.Removed -= OnDeviceRemoved;
                _deviceWatcher.Updated -= OnDeviceUpdated;
                _deviceWatcher.EnumerationCompleted -= OnEnumerationCompleted;
                _deviceWatcher.Stopped -= OnStopped;

                _deviceWatcher.Stop();

                rootPage.NotifyUser("Device watcher stopped.", NotifyType.StatusMessage);
            }
        }
Esempio n. 40
0
        private void watcher_Added(Windows.Devices.Enumeration.DeviceWatcher sender, Windows.Devices.Enumeration.DeviceInformation args)
        {
            string name = GetPortableDeviceName(args.Id);
            string type = GetPortableDeviceType(args.Id);

            if (!deviceTypeList.ContainsKey(name))
            {
                deviceTypeList.Add(GetPortableDeviceName(args.Id), GetPortableDeviceType(args.Id));
            }
            this.BeginInvoke((Action)(() =>
            {
                //perform on the UI thread
                PrintDrives();
            }));
        }
        public Scenario2_Polling()
        {
            String customSensorSelector = "";

            this.InitializeComponent();

            customSensorSelector = CustomSensor.GetDeviceSelector(GUIDCustomSensorDeviceVendorDefinedTypeID);
            watcher = DeviceInformation.CreateWatcher(customSensorSelector);
            watcher.Added += OnCustomSensorAdded;
            watcher.Start();

            // Register to be notified when the user disables access to the custom sensor through privacy settings.
            deviceAccessInformation = DeviceAccessInformation.CreateFromDeviceClassId(GUIDCustomSensorDeviceVendorDefinedTypeID);
            deviceAccessInformation.AccessChanged += new TypedEventHandler<DeviceAccessInformation, DeviceAccessChangedEventArgs>(OnAccessChanged);
        }
Esempio n. 42
0
        static public void Stop()
        {
            /// <summary>
            /// Stops watching for all nearby Bluetooth devices.
            /// </summary>
            if (deviceWatcher != null)
            {
                // Unregister the event handlers.
                deviceWatcher.Added -= DeviceWatcher_Added;

                // Stop the watcher.
                deviceWatcher.Stop();
                deviceWatcher = null;
            }
        }
 /// <summary>
 /// Invoked when the device watcher finds a proximity sensor
 /// </summary>
 /// <param name="sender">The device watcher</param>
 /// <param name="device">Device information for the proximity sensor that was found</param>
 private async void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation device)
 {
     if (null == sensor)
     {
         sensor = ProximitySensor.FromId(device.Id);
         if (null == sensor)
         {
             // failed to find the sensor corresponding to the id
             await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
                 rootPage.NotifyUser("Could not get a proximity sensor from the device id", NotifyType.ErrorMessage);
             });
         }
     }
 }
 private async void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate args)
 {
     await coreDispatcher.RunAsync(
         CoreDispatcherPriority.Normal,
         () =>
         {
             for (int index = 0; index < FoundDeviceList.Count; ++index)
             {
                 if (FoundDeviceList[index].Id == args.Id)
                 {
                     FoundDeviceList.RemoveAt(index);
                     break;
                 }
             }
         });
 }
Esempio n. 45
0
        /// <summary>
        /// Initializes a new instance of the MainForm form class.
        /// </summary>
        public MainForm()
        {
            LocRM = new ResourceManager("win81FactoryTest.AppResources.Res", typeof(win81FactoryTest.TestForm).Assembly);

            InitializeComponent();
            SetString();
            this.FormBorderStyle = FormBorderStyle.None;//Full screen and no title
            this.WindowState     = FormWindowState.Maximized;

            //Initialize device watcher
            watcher = Windows.Devices.Enumeration.DeviceInformation.CreateWatcher(Windows.Devices.Enumeration.DeviceClass.PortableStorageDevice);

            watcher.Added   += watcher_Added;
            watcher.Removed += watcher_Removed;
            watcher.EnumerationCompleted += watcher_EnumerationCompleted;
            watcher.Start();
        }
Esempio n. 46
0
        async void watcher_Updated(Windows.Devices.Enumeration.DeviceWatcher sender, DeviceInformationUpdate devUpdate)
        {
            int count2 = 0;

            foreach (DeviceInformation deviceInterface in interfaces)
            {
                if (count2 < count)
                {
                    if (interfaces[count2].Id == devUpdate.Id)
                    {
                        //Update the element.
                        interfaces[count2].Update(devUpdate);
                    }
                }
                count2 += 1;
            }
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                OutputText.Text = "Enumeration updated: Device added ";
                DisplayDeviceInterfaceArray();
            });
        }
Esempio n. 47
0
 private void Watcher_Updated(Windows.Devices.Enumeration.DeviceWatcher sender, DeviceInformationUpdate args)
 {
     // TODO: notify devices
 }
Esempio n. 48
0
 private void Watcher_Updated(Windows.Devices.Enumeration.DeviceWatcher sender, Windows.Devices.Enumeration.DeviceInformationUpdate args)
 {
 }
Esempio n. 49
0
 private void Watcher_Stopped(Windows.Devices.Enumeration.DeviceWatcher sender, object args)
 {
     subject.OnCompleted();
 }