当前位置: 首页 > 知识库问答 >
问题:

BGScript GATT特征从C#写入不工作

汪文光
2023-03-14

在我的设备配置中,gatt。在xml中,我添加了一个带有自定义UUID的自定义GATT特性,并启用了读写属性。配对后使用windows Bluetooth API,当我尝试读取GATT特性时,它工作正常,但写入GATT特性不起作用。我一直被拒绝访问,只有一个例外。下面我添加了gatt样本。xml、bgs和C#代码。我使用的是Bluegiga v1。3.1_API。当前的设置可以与USB加密狗配合使用,但我正在尝试用Windows蓝牙API替换它。

关贸总协定。xml

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>

<service uuid="180A">
  <description>Device Information</description>
  
  <characteristic uuid="2a29">
    <properties read="true" const="true" />
    <value>company name</value>
    <description>Manufacturer Name String</description>
  </characteristic>
  
  <characteristic uuid="2a24">
    <properties read="true" const="true" />
    <value>device name</value>
    <description>Model Number String</description>
  </characteristic>
      
  <characteristic uuid="2a27">
    <properties read="true" const="true"/>
    <value>2.0</value>
    <description>Hardware Revision String</description>
  </characteristic>
  
  <characteristic uuid="95551f84-7562-4c30-9455-be0750914ac2" id="xgatt_Params">
    <properties read="true" write="true"/>
    <value type="user" length="5"/>
    <description>Params</description>

  </characteristic>
      
</service>
    
</configuration>

bgs脚本中的属性值事件

event attributes_value(connection, reason, handle, offset, value_len, value_data)
    if handle = xgatt_Params then
        if value_len = 2 then
            if value_data(0:2) = $0115 then
                memcpy(addrPaired(0), addrConnected(0),6)
                updatePairing=1
                call attributes_user_write_response(connection, 0)
            else
                call attributes_user_write_response(connection, $80)
            end if
        else
            if value_len >= numParams then
                memcpy(params(0), value_data(0), numParams)
                call updateParams()
                call attributes_user_write_response(connection, 0)
            else
                call attributes_user_write_response(connection, $80)
            end if
        end if
    end if
end

C#代码

if (properties.HasFlag(GattCharacteristicProperties.Write))
{
    try
    {
        var writer = new DataWriter();
        writer.WriteByte(01);
        writer.WriteByte(15);
        var result = await characteristic.WriteValueAsync(writer.DetachBuffer(), 
GattWriteOption.WriteWithResponse);

        if (result == GattCommunicationStatus.Success)
        {
            Console.Write("\n Success");
        }
        else if (result == GattCommunicationStatus.AccessDenied)
        {
            Console.Write("\n Access Denied");
        }
        else if (result == GattCommunicationStatus.Unreachable)
        {
            Console.Write("\n Unreachable");
        }

        else if (result == GattCommunicationStatus.ProtocolError)
        {
            Console.Write("\n ProtocolError");
        }
    }
    catch (Exception ex) when ((uint)ex.HResult == 0x80650003 || (uint)ex.HResult == 
0x80070005)
    {
        Console.Write("\n " + ex.Message);
    }

}

共有1个答案

班泽语
2023-03-14

Windows不允许写入GAP服务。所以我所做的就是使用下面这样的自定义UUID创建一个具有特性的服务,现在它开始工作了。

<service uuid="97b6682c-ca92-11eb-b8bc-0242ac130003">
  <description>meso service</description>

  <!-- custom write-only characteristic -->
    <characteristic uuid="97b66a7a-ca92-11eb-b8bc-0242ac130003" id="xgatt_params_windows">
      <description>Data</description>
      <properties write="true" />
      <value type="user" length="5"/>
    </characteristic>
</service>

另一件需要记住的事情是,您需要从窗口以相反的顺序写入十六进制值。例如,在我的BGScript中,它的预期值是0115,所以您应该从窗口中反向写入值。这完全取决于您使用的系统,例如,BigEndian(MSB优先,例如:摩托罗拉处理器)或LittleEndian(LSB优先,例如:英特尔处理器)。

var writer = new DataWriter();
writer.WriteByte(15);
writer.WriteByte(01);
 类似资料:
  • Feature engineering is an informal topic, but one that is absolutely known and agreed to be key to success in applied machine learning. In creating this guide I went wide and deep and synthesized all

  • 特征工程是指从原始数据转换为特征向量的过程。特征工程是机器学习中最重要的起始步骤,会直接影响机器学习的效果,并通常需要大量的时间。典型的特征工程包括数据清理、特征提取、特征选择等过程。 数据清理 缩放特征值(归一化):将浮点特征值从自然范围(如 100 到 900)转换为标准范围(如 0 到 1)。特征集包含多个特征时,缩放特征可以加快梯度下降的收敛过程,并可以避免 NaN 陷阱。特征缩放的方法一

  • 现在我知道这个问题已经被问了十亿次了。 我已经通读了其中的大部分(这个网站对我的问题没有太大帮助),我已经通读了文档,我已经通读了示例和教程。 我想做的是: 将hello world发送到可移动设备(连接到arduino) 到目前为止我所做的: 与使用内置设置的设备配对(我的应用程序中没有编程逻辑) 使用GATT服务器与设备连接。 然而,当我试图编写一个特征时,相应的状态返回布尔值总是false。

  • 本文向大家介绍特征工程的问题相关面试题,主要包含被问及特征工程的问题时的应答技巧和注意事项,需要的朋友参考一下 参考回答: 特征工程包括数据与特征处理、特征选择和降纬三部分。数据与特征处理包括: 1.数据选择、清洗、采样 数据格式化; 数据清洗,填充缺失值、去掉脏数据,将不可信的样本丢掉,缺省值极多的字段考虑不用; 采样:针对正负样本不平衡的情况,当正样本远大于负样本时,且量都很大时,使用下采样,

  • 本文向大家介绍C++ Eigen库计算矩阵特征值及特征向量,包括了C++ Eigen库计算矩阵特征值及特征向量的使用技巧和注意事项,需要的朋友参考一下 本文主要讲解利用Eigen库计算矩阵的特征值及特征向量并与Matlab计算结果进行比较。 C++Eigen库代码 计算结果: 最大最小特征值及其索引位置 Matlab 代码 Matlab计算结果 使用sort()函数对特征值排序 主成份分析以及许多

  • 将跟踪和跨度添加到Slf4J MDC,以便您可以从日志聚合器中的给定跟踪或跨度中提取所有日志。示例日志: 2016-02-02 15:30:57.902 INFO [bar,6bfd228dc00d216b,6bfd228dc00d216b,false] 23030 --- [nio-8081-exec-3] ... 2016-02-02 15:30:58.372 ERROR [bar,6bfd