Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我应该在我的UWP应用程序中使用哪些蓝牙功能来读取我的BLE设备中的特征_C#_Uwp_Bluetooth Lowenergy - Fatal编程技术网

C# 我应该在我的UWP应用程序中使用哪些蓝牙功能来读取我的BLE设备中的特征

C# 我应该在我的UWP应用程序中使用哪些蓝牙功能来读取我的BLE设备中的特征,c#,uwp,bluetooth-lowenergy,C#,Uwp,Bluetooth Lowenergy,我正在尝试从我的BLE设备(蓝色壁虎bgm13p22)读取温度特征 我已经在C#Windows BLE代码中进行了尝试 这个 还有这个 GattReadResult result = await selectedCharacteristic.ReadValueAsync();//ReadValueAsync-->Performs a Characteristic Value read from the value cache maintained by Windows or retriev

我正在尝试从我的BLE设备(蓝色壁虎bgm13p22)读取温度特征 我已经在C#Windows BLE代码中进行了尝试 这个

还有这个

GattReadResult result = await selectedCharacteristic.ReadValueAsync();//ReadValueAsync-->Performs a Characteristic Value read from the value cache maintained by Windows or retrieve from Windows
在package.appxmanifest中 我加了这个

 <DeviceCapability Name="bluetooth.genericAttributeProfile">
       <Device Id="any">
          <Function Type="name:healthThermometer" />
       </Device>
    </DeviceCapability>   
  </Capabilities>

从BLE设备读取温度值,但仍无法读取


感谢您的帮助

蓝壁虎使用蓝牙SIG健康温度计服务。 SIG的文件说明如下: 资料来源:

一旦由收集器配置,温度计通常会保持不变 在两次使用之间关闭电源,只会发布广告并允许收集器 当温度计有数据要发送时进行连接。在这种情况下, 温度计将进入间隙连接模式并启动 当有数据要发送给收集器时进行广告。收藏家 通常将执行间隙连接建立程序,如 它正在用白名单扫描温度计。当 连接建立后,温度计发送一个或多个 对收集器的指示或通知。当数据传输 温度计完成后,通常会终止连接

收集器是你的应用程序,温度计是你的蓝色壁虎

对于UWP,这意味着:使用广告观察者收听设备并获取设备。 获取服务并连接。 获取特征并将客户端特征配置描述符设置为通知。 实现特征值更改方法

这意味着温度计值在通知中,或者您必须在通知到达后读取这些值。 如果没有通知,则无需阅读

我在Github上做了一个例子,解释了advertisementwatcher和subscribing tor通知:

该示例是为visual studio 2017编写的,但是您可以阅读最重要的方法并获得想法 在Github上打开MainPage.xaml.cs

读取字节数组中的温度,其中包含flagsfield(8位)、temperature(4位)和可选的时间戳(7位)、诱惑类型(8位) 从
您的appxmanifest必须包含:

 <Capabilities>
    <Capability Name="internetClient" />
    <DeviceCapability Name="bluetooth" />
</Capabilities>
要添加的行:

 GattCharacteristicProperties properties = charac.CharacteristicProperties;

                           if (properties.HasFlag(GattCharacteristicProperties.Read))
                           {
                              Debug.WriteLine("This characteristic supports reading from it.");                              
                           }
                           if (properties.HasFlag(GattCharacteristicProperties.Write))
                           {
                              Debug.WriteLine("This characteristic supports writing to it.");                              
                           }
                           if (properties.HasFlag(GattCharacteristicProperties.Notify))
                           {
                              Debug.WriteLine("This characteristic supports subscribing to notifications.");
                           }
                           if (properties.HasFlag(GattCharacteristicProperties.Indicate))
                           {
                              Debug.WriteLine("This characteristic supports subscribing to Indication");
                           }

您的代码看起来是正确的。您是否正在尝试读取have read属性(换句话说:是否可读)?是的,我正在使用Simplication studio,在GATT编辑器中,我已将读取属性设置为true。您是否能够使用其他设备(比如您的手机)读取特征值?是的,我能够通过Blue gecko应用程序读取。但我想在我的UWP应用程序中添加一件事,当我使用bluetoothLeDevice.GetGattServicesAsync(BluetoothCacheMode.Cached)时;然后只建立连接,当我使用bluetoothLeDevice.GetGattServicesAsync(BluetoothCacheMode.Uncached);,代码不起作用。使用“未缓存”会产生问题。你能提出一些建议吗?你可以在这里看到代码:这个代码使用“Uncached”并表示它可以工作,但在我的代码中它可以与缓存模式一起工作谢谢你的回答,但这似乎是针对Windows phone应用程序的,我正在尝试创建一个桌面应用程序。在部署项目时,会出现错误SmartDeviceException-Windows Phone IP over USB传输(IpOverUsbSvc)未运行。从服务管理控制台启动Windows Phone IP over USB传输(IpOverUsbSvc)后重试。在IDE中,将平台设置为x86和本地计算机。是的,好的,我已经下载了模拟器。另一个警告是找不到证书文件“SimpleBleExample\u by_Devicename\u TemporaryKey.pfx”。SimpleBleExample\u by_DevicenameI将装有Windows 10的dell平板电脑与我的笔记本电脑连接起来,并运行SimpleBleExample\u byDevicename,但它显示-->DEP6200:引导失败。找不到设备。SmartDeviceException-部署失败,因为未检测到任何设备。确保设备已连接并通电。它只是一个桌面应用程序。为了保持简单,结果显示在调试输出中。正如我前面提到的:在VisualStudioIDE中,选择x86作为解决方案平台,并将其设置为在本地计算机上运行。您可能需要在configuration manager中设置正在使用的windows版本。
 characteristicFoundMilis = stopwatch.ElapsedMilliseconds;
                           Debug.WriteLine("Characteristic found in " +
                                          (characteristicFoundMilis - serviceFoundMilis) + " ms");
 GattCharacteristicProperties properties = charac.CharacteristicProperties;

                           if (properties.HasFlag(GattCharacteristicProperties.Read))
                           {
                              Debug.WriteLine("This characteristic supports reading from it.");                              
                           }
                           if (properties.HasFlag(GattCharacteristicProperties.Write))
                           {
                              Debug.WriteLine("This characteristic supports writing to it.");                              
                           }
                           if (properties.HasFlag(GattCharacteristicProperties.Notify))
                           {
                              Debug.WriteLine("This characteristic supports subscribing to notifications.");
                           }
                           if (properties.HasFlag(GattCharacteristicProperties.Indicate))
                           {
                              Debug.WriteLine("This characteristic supports subscribing to Indication");
                           }