SO I have been trying to replicate the example program from the ACRBLE plugin, and I am having trouble getting it to work on visual studio 2019. For the functionality of scanning for device, I have a similar setup as the scantoggle in the example program.
IAdapter adapter = CrossBleAdapter.Current;
IDisposable scan;
public ICommand ScanToggle { get; private set; }
private ICommand FindAdapter { get; }
[Reactive] public bool IsScanning { get; private set; }
[Reactive] public string adapter_is_scanning { get; private set; }
[Reactive] public string connected_devices { get; private set; }
[Reactive] public string adapter_status { get; private set; }
public IObservableCollection<ScanResultViewModel> Devices { get; }
this.ScanToggle = ReactiveCommand.Create(
() =>
{
if (!IsScanning) //when (Press to scan)
{
this.IsScanning = true;
this.scan = this.adapter.Scan().Buffer(TimeSpan.FromSeconds(1)).ObserveOn(RxApp.MainThreadScheduler).Subscribe(
results =>
{
this.connected_devices = results.Count().ToString();
this.adapter_is_scanning = this.adapter.IsScanning.ToString();
this.adapter_status = this.adapter.Status.ToString();
foreach (var r in results)
{
var dev = this.Devices.FirstOrDefault(x => x.Uuid.Equals(r.Device.Uuid));
if (dev != null)
{
dev.TrySet(r);
}
else
{
dev = new ScanResultViewModel();
dev.TrySet(r);
}
Devices.Add(dev);
}
}
).DisposeWith(this.DeactivateWith);
}
else
{
this.scan?.Dispose();
this.Devices.Clear();
this.IsScanning = false;
this.adapter_is_scanning = this.adapter.IsScanning.ToString();
this.adapter_status = this.adapter.Status.ToString();
}
}
);
============================================================================================
I am binding the text property of a label to connection_devices which should update how many results I get after each instance of scan.
this.connected_devices = results.Count().ToString();
However it always returns 0, and nothing gets added to the observablecollection Devices either. I tried using nRF Connect and the bluetooth peripheral could work just fine. What am I doing wrong?