Flutter ble 写入失败

问题描述 投票:0回答:2

Flutter ble - 写入特性错误

我无法使用

flutter_blue
库在 ble 外围设备上写入,它会抛出此异常:

Unhandled Exception: PlatformException(write_characteristic_error, service (0000ff06-0000-1000-8000-00805f9b34fb) could not be located on the device, null, null)
E/flutter (29808): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (29808): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter (29808): <asynchronous suspension>
E/flutter (29808): #2      BluetoothCharacteristic.write (package:flutter_blue/src/bluetooth_characteristic.dart:120:18)
E/flutter (29808): <asynchronous suspension>
E/flutter (29808): #3      DeviceScreen._buildServiceTiles.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:untitled/main.dart:176:23)

或另一个错误说:不允许写入。 我正在使用 flutter blue 库提供的示例代码,这是我在连接设备后尝试编写的代码:

onWritePressed: () async {
                      await c.write(_getRandomBytes(), withoutResponse: true);
                      await c.read();
                    },
                    onNotificationPressed: () async {
                      await c.setNotifyValue(!c.isNotifying);
                      if (c.properties.read) {
                        await c.read();
                      }
List<int> _getRandomBytes(){
String command = "55 AA 00 01 50 3C 00";
return command.codeUnits;
}

Kotlin 中硬件设备工作正常,数据发送和接收。

android ios flutter dart bluetooth-lowenergy
2个回答
0
投票

看起来找不到该特征所属的服务(或者错误中显示的 uuid 为哪个服务)。在尝试写作之前尝试拨打

discoverServices


0
投票

确保连接设备

        await device.connect();
© www.soinside.com 2019 - 2024. All rights reserved.