flutter_blue解决分包问题

Flutter_blue 发送包长度大于20时 解决分包问题

 void write(characteristics,device) async{
    final mtu = await device.mtu.first;
    print("mtu:$mtu");
    var buffer = new WriteBuffer();
    List<int> ll=[0x4E,0x57,0x00,0x13,0x00,0x00,0x00,0x00,0x06,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x68,0x00,0x00,0x01,0x27];
    int pos=0;
    int bytes=ll.length;
    print('开始写入数据');
     if(ll.length>0){
      if(ll.length<mtu){
        await characteristics.write(ll,withoutResponse: true);
      }else{
        while(bytes>0){
          List<int> tmp;
          buffer=new WriteBuffer();
          if(bytes>mtu){
            tmp=ll.sublist(pos,pos+mtu);
            pos+=mtu;
            bytes-=mtu;
            tmp.forEach((element) {
              buffer.putUint8(element);
            });
            final ByteData written=buffer.done();
            final ReadBuffer read = ReadBuffer(written);
            characteristics.write(read.getUint8List(mtu),withoutResponse:true).asStream();
          }else{
            return await Future.delayed(Duration(milliseconds: 25),(){
              tmp=ll.sublist(pos,pos+bytes);
              pos+=bytes;
              bytes-=bytes;
              tmp.forEach((element) {
                buffer.putUint8(element);
              });
              final ByteData written=buffer.done();
              final ReadBuffer read = ReadBuffer(written);
              characteristics.write(read.getUint8List(pos%mtu),withoutResponse:true).asStream();
            });
          }
        }
      }
    }
    print('写入数据完成$buffer');
  }
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[2\]提到,Flutter_blue只兼容Android SDK的19版本及以上。因此,如果你想在Android上使用flutter_blue,你需要在android/app/build.gradle文件中更改相应的配置。具体的更改步骤可以参考该引用内容中的说明。 另外,引用\[3\]提到,要了解如何使用flutter_blue_plus,最好的方法是查阅文档或者查看flutter_reactive_ble库的代码。你可以从flutter_reactive_ble库的example目录下的示例代码开始,逐步学习如何使用flutter_blue_plus。在示例代码中,可以看到在main.dart文件中创建了一个名为FlutterBlueApp的根组件。通过运行该组件,你可以开始使用flutter_blue_plus库。 #### 引用[.reference_title] - *1* *3* [Flutter蓝牙框架-flutter_blue_plus使用及源码解析](https://blog.csdn.net/Yaoobs/article/details/131570861)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [flutter_blue](https://blog.csdn.net/weixin_31865445/article/details/117817409)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值