问题描述
auto f = leDev.GetGattServicesForUuidAsync(servUuid).get(); // returns a GattDeviceServicesResult
auto g = f.Services().GetAt(0); // There is only one such service on the device that I am using
auto h = g.GetcharacteristicsAsync().get(); // Use the service to obtain all the characteristics of the service
auto j = h.characteristics(); // Size of j is 0 despite there are 4 services
我构造 servUuid
的方式是使用具有服务 UUID 的字符串
guid servGUIDstruct = make_guid(servID);
winrt::guid servUuid = reinterpret_cast<winrt::guid&>(servGUIDstruct);
我还尝试了其他方法来获取服务 Uuid,例如,枚举所有服务并存储感兴趣的服务的 Uuid,然后在 GetGattServicesForUuidAsync
中使用它,但看到了同样的问题。
知道我做错了什么会非常有用,谢谢
解决方法
我所理解的问题是,由于我已经枚举了其中的所有服务和特征,因此在再次获取服务之前,我必须对这些服务调用 Close
。
此处的 the link 可能解释了访问被拒绝的原因。