我正在使用Windows 8.1 Store应用程序从ti Sensortag蓝牙低能耗设备接收数据。
通过DeviceInformation扫描设备:: FindAllAsync正常工作:
void App1::MainPage::ScanButton_Click(Platform::Object^ sender,
Windows::UI::Xaml::RoutedEventArgs^ e)
{
create_task(DeviceInformation::FindAllAsync(GattDeviceService::GetDeviceSelectorFromUuid(GattServiceUuids::GenericAttribute), nullptr))
.then
([this](DeviceInformationCollection^ Geräteliste)
{
int Anzahl = Geräteliste->Size;
auto Geräteliste_Iterator = Geräteliste->First();
TestId = Geräteliste_Iterator->Current->Id;
TestName = Geräteliste_Iterator->Current->Name;
}
);
Geräte_Namen_Block->Text = TestName + TestId;
}
但是,当我尝试获取Device的特性或服务时,我会回到一个空的Ivector:
Guid DeviceInformationServiceUuid(0xf0002800, 0x0451, 0x4000, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
Guid PeripheralPrivacyFlagCharacteristic(0xf0002a02, 0x0451, 0x4000, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
void App1::MainPage::___Service_Button__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
create_task(GattDeviceService::FromIdAsync(TestId)).then([this](GattDeviceService^ Mein_Gerät)
{
TestId_vonDeviceService = Mein_Gerät->DeviceId;
//GattCharacteristic^ FirstCharacteristic = Mein_Gerät->GetCharacteristics(PeripheralPrivacyFlagCharacteristic)->GetAt(0);
ServicesVector = Mein_Gerät->GetIncludedServices(DeviceInfoUuid);
CharacteristicsVector = Mein_Gerät->GetCharacteristics(PeripheralPrivacyFlagCharacteristic);
ServicesLength = ServicesVector->Size;
CharacteristicsLength = CharacteristicsVector->Size;
});
}
我已经在app manifest xml中添加了两个服务的ID,如下所示:
m2:Function Type="serviceId:f0002a29-0451-4000-b000-000000000000"/> <!--Device Name-->
m2:Function Type="serviceId:f0002a01-0451-4000-b000-000000000000"/> <!--Appearance-->
<m2:Function Type="serviceId:f0002a02-0451-4000-b000-000000000000"/> <!--Periperal Privacy Flag-->
我认为这应该是正确的。所以现在我不知道为什么?