Example #1
0
        private void Discover(JObject parameters)
        {
            var major = parameters["majorDeviceClass"]?.ToObject <BluetoothMajorClass>();
            var minor = parameters["minorDeviceClass"]?.ToObject <BluetoothMinorClass>();

            if (major == null || minor == null)
            {
                throw JsonRpcException.InvalidParams("majorDeviceClass and minorDeviceClass required");
            }

            var deviceClass = BluetoothClassOfDevice.FromParts(major.Value, minor.Value,
                                                               BluetoothServiceCapabilities.None);
            var selector = BluetoothDevice.GetDeviceSelectorFromClassOfDevice(deviceClass);

            try
            {
                _watcher = DeviceInformation.CreateWatcher(selector, new List <String>
                {
                    SignalStrengthPropertyName,
                    IsPresentPropertyName,
                    BluetoothAddressPropertyName
                });
                _watcher.Added += PeripheralDiscovered;
                _watcher.EnumerationCompleted += EnumerationCompleted;
                _watcher.Updated += PeripheralUpdated;
                _watcher.Stopped += EnumerationStopped;
                _watcher.Start();
            }
            catch (ArgumentException)
            {
                throw JsonRpcException.ApplicationError("Failed to create device watcher");
            }
        }
Example #2
0
        public SpikePortControlViewModel()
        {
            sendOrPostCb = TriggerRefresh;
            context      = SynchronizationContext.Current !;
            var deviceClass = BluetoothDevice.GetDeviceSelectorFromClassOfDevice(BluetoothClassOfDevice.FromParts(BluetoothMajorClass.Toy, BluetoothMinorClass.ToyRobot, BluetoothServiceCapabilities.None));

            deviceWatcherBluetooth = DeviceInformation.CreateWatcher(deviceClass);
            deviceWatcherSerial    = DeviceInformation.CreateWatcher(SerialDevice.GetDeviceSelectorFromUsbVidPid(0x0694, 0x0010), new string[] { "System.DeviceInterface.Serial.PortName" });

            deviceWatcherSerial.Added   += DeviceWatcher_Added;
            deviceWatcherSerial.Removed += DeviceWatcher_Removed;
            deviceWatcherSerial.Updated += DeviceWatcher_Updated;
            deviceWatcherSerial.Stopped += DeviceWatcher_Stopped;
            deviceWatcherSerial.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;

            deviceWatcherBluetooth.Added   += DeviceWatcher_Added;
            deviceWatcherBluetooth.Removed += DeviceWatcher_Removed;
            deviceWatcherBluetooth.Updated += DeviceWatcher_Updated;
            deviceWatcherBluetooth.Stopped += DeviceWatcher_Stopped;
            deviceWatcherBluetooth.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;

            deviceWatcherSerial.Start();
            deviceWatcherBluetooth.Start();
        }