C# Windows 10 Mobile Bluetooth BLE - OnAdvertisementReceived -
i'm trying learn how use ble in c# windows 10 mobile smartphone. i'm trying connect oral-b toothbrush in order data off it.
unfortnately in code "onadvertisementreceived" never gets called , don't know why, toothbrush ble enabled , using analyzer app on android smartphone can see sending beacons/advertisments in order connected, text of debug- textbox doesn't change.
here's complete c# code:
public sealed partial class mainpage : page { private bluetoothleadvertisementwatcher watcher; public mainpage() { this.initializecomponent(); // create , initialize new watcher instance. watcher = new bluetoothleadvertisementwatcher(); watcher.signalstrengthfilter.inrangethresholdindbm = -70; watcher.signalstrengthfilter.outofrangethresholdindbm = -75; watcher.signalstrengthfilter.outofrangetimeout = timespan.frommilliseconds(2000); watcher.received += onadvertisementreceived; watcher.stopped += onadvertisementwatcherstopped; app.current.suspending += app_suspending; app.current.resuming += app_resuming; } private void app_suspending(object sender, windows.applicationmodel.suspendingeventargs e) { watcher.stop(); watcher.received -= onadvertisementreceived; watcher.stopped -= onadvertisementwatcherstopped; } private void app_resuming(object sender, object e) { watcher.received += onadvertisementreceived; watcher.stopped += onadvertisementwatcherstopped; } private async void onadvertisementreceived(bluetoothleadvertisementwatcher watcher, bluetoothleadvertisementreceivedeventargs eventargs) { textbox1.text = "true"; var address = eventargs.bluetoothaddress; bluetoothledevice device = await bluetoothledevice.frombluetoothaddressasync(address); var cnt = device.gattservices.count; watcher.stop(); } private void onadvertisementwatcherstopped(bluetoothleadvertisementwatcher watcher, bluetoothleadvertisementwatcherstoppedeventargs eventargs) { } private void button_click(object sender, routedeventargs e) { watcher.start(); } }
thanks
Comments
Post a Comment