HarmonyOS 鸿蒙Next中gattClient.writeCharacteristicValue(this.writeCharacteristic, ble.GattWriteType.WRITE_NO_RESPONSE) ble调用发送特征值,报错{"code":

HarmonyOS 鸿蒙Next中gattClient.writeCharacteristicValue(this.writeCharacteristic, ble.GattWriteType.WRITE_NO_RESPONSE) ble调用发送特征值,报错{“code”:

gattClient.writeCharacteristicValue(this.writeCharacteristic, ble.GattWriteType.WRITE_NO_RESPONSE) 调用发送特征值时出现错误 {"code":-18,"message":"Inner error."}  
此错误是什么原因?如何解决?  
日志和问题发生时间见 附件

更多关于HarmonyOS 鸿蒙Next中gattClient.writeCharacteristicValue(this.writeCharacteristic, ble.GattWriteType.WRITE_NO_RESPONSE) ble调用发送特征值,报错{"code":的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

麻烦使用

hdc shell hilog -Q domainoff
hdc shell hilog -b D -D 0x00a00
hdc shell hilog -b D -D 0xD002E00
hdc shell hilog -r
hdc shell hilog > 111111.txt

再发一份日志,执行上面的命令后,在复现几次ble发送数据报错的操作。

-18是使用的gattClientDevice对象已经释放了。可以复现吗?从日志中没找到这个gattClientDevice创建的时间点

更多关于HarmonyOS 鸿蒙Next中gattClient.writeCharacteristicValue(this.writeCharacteristic, ble.GattWriteType.WRITE_NO_RESPONSE) ble调用发送特征值,报错{"code":的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,gattClient.writeCharacteristicValue(this.writeCharacteristic, ble.GattWriteType.WRITE_NO_RESPONSE)调用时出现报错{"code":,可能是由于以下原因之一:

  1. 权限问题:确保应用已获取必要的蓝牙权限,如ohos.permission.USE_BLUETOOTHohos.permission.LOCATION

  2. 设备未连接:在执行写操作之前,确保蓝牙设备已成功连接。

  3. 特征值不支持:检查目标特征值是否支持WRITE_NO_RESPONSE操作。有些特征值可能只支持WRITEWRITE_DEFAULT

  4. 参数错误:确认this.writeCharacteristic参数是否正确,且特征值对象有效。

  5. GATT状态:检查GATT客户端的状态,确保其处于可用状态。

  6. 系统限制:某些设备或系统版本可能对WRITE_NO_RESPONSE操作有限制。

  7. 错误码解析:根据返回的错误码进一步排查问题。常见的错误码包括1(GATT失败)、2(GATT未连接)、3(GATT忙)等。

具体错误码需要进一步分析以确定根本原因。

在HarmonyOS鸿蒙Next中,调用 gattClient.writeCharacteristicValue 方法时,如果返回错误代码,可能的原因包括:

  1. 特征值不可写:确保 this.writeCharacteristic 支持写入操作。
  2. 连接状态异常:检查设备是否已正确连接到GATT服务器。
  3. 权限问题:确保应用已获得必要的蓝牙权限。
  4. GATT写类型不匹配:确认 ble.GattWriteType.WRITE_NO_RESPONSE 与特征值支持的写类型一致。

建议检查日志以获取更多错误信息,并根据具体错误代码进一步排查问题。

回到顶部