Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/winrtble/ble/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use windows::{
BluetoothLEPreferredConnectionParameters,
GenericAttributeProfile::{
GattCharacteristic, GattCommunicationStatus, GattDescriptor, GattDeviceService,
GattDeviceServicesResult, GattSession,
GattDeviceServicesResult, GattSession, GattSharingMode,
},
},
Foundation::TypedEventHandler,
Expand Down Expand Up @@ -129,6 +129,16 @@ impl BLEDevice {
pub async fn get_characteristics(
service: &GattDeviceService,
) -> Result<Vec<GattCharacteristic>> {
// Some services refuse characteristic discovery (AccessDenied) until they have been
// opened. Opening shared doesn't stop other apps using the service, and if it fails
// discovery is still tried as before.
match service.OpenAsync(GattSharingMode::SharedReadAndWrite) {
Ok(op) => match op.await {
Ok(status) => trace!("service open status {:?}", status),
Err(e) => debug!("service open failed {:?}", e),
},
Err(e) => debug!("service open failed {:?}", e),
}
let async_result = match timeout(
GATT_CACHE_TIMEOUT,
service
Expand Down