public static async Task <BleGattService> GetGattServiceById(this IBleManager bleManager, string deviceId, string gattServiceId) { try { var allGattServices = await bleManager.GetDeviceGattServices(deviceId); return(allGattServices?.FirstOrDefault(g => g.Uuid == Guid.Parse(gattServiceId))); } catch (Exception) { return(null); } }
public async Task <ServiceResponse <IEnumerable <BleGattService> > > GetGattServicesByDeviceId(string deviceId) { var serviceResponse = new ServiceResponse <IEnumerable <BleGattService> >(); var device = await GetDiscoveredDeviceById(deviceId); if (device == null) { serviceResponse.Result = ServiceResponseResult.NotFound; serviceResponse.Message = $"the requested deviceId:\'{deviceId}\' does not exists."; return(serviceResponse); } var deviceGattServices = await _bluetoothManager.GetDeviceGattServices(deviceId) ?? new BleGattService[] { }; serviceResponse.Data = deviceGattServices; serviceResponse.Result = ServiceResponseResult.Success; return(serviceResponse); }