private void ProcessScan(IScanResult scanResult) { //Debug.WriteLine(scanResult.AdvertisementData.LocalName); //printdebug(scanResult.AdvertisementData.LocalName); if (scanResult.AdvertisementData.LocalName != null && scanResult.AdvertisementData.LocalName.Trim() == serverName) { server = scanResult.Device; scanner.Dispose(); ConnectToServer(); } }
void OnScanResult(IScanResult result) { // Only interested in Movesense devices Plugin.BluetoothLE.IDevice device = result.Device; if (device.Name != null) { if (device.Name.StartsWith("Movesense")) { if (MovesenseDevices.FirstOrDefault((d) => d.Name == device.Name) == null) { MovesenseDevices.Add(device); Debug.WriteLine($"Discovered device {device.Name}"); } } } }
public Device(Plugin.BluetoothLE.IDevice dev) { device = dev; Name = dev.Name; chararacteristicListener = device.WhenAnyCharacteristicDiscovered().Subscribe(characteristic => { if (characteristic.Uuid.ToString() == BleService.CharacteristictReadUuid) { readCharacteristic = characteristic; OnStateChanged(DeviceState.Connected); RaisePropertyChanged(nameof(ConnectState)); if (readCharacteristic.CanNotify()) { readCharacteristicObserver = characteristic.RegisterAndNotify(true).Subscribe(r => { Read?.Invoke(r.Data); }, exception => { // Crashes.TrackError(exception); }); } } if (characteristic.Uuid.ToString() == BleService.CharacteristicWriteUuid) { if (characteristic.CanWrite()) { writeCharacteristic = characteristic; OnStateChanged(DeviceState.Connected); RaisePropertyChanged(nameof(ConnectState)); } } }, exception => { // Crashes.TrackError(exception); }); stateListener = device.WhenStatusChanged().Subscribe(f => { OnStateChanged(ConnectState); }); }