如何解决等待所有字节再继续操作Flutter
在我的代码中,我使用flutter_bluetooth_serial库与微控制器进行通信。
在继续执行我的功能的下一步之前,我该如何等待所有字节到达?
static download_file() {
send_data(Costanti.cmd_download_1,1028); // here I send the command via bluetooth
// 1028 are the number of bytes I expect as answer
//--- WAIT THE ARRIVE OF ALL BYTES BEFORE PROCCED---------//
// manipulation of 1028 bytes
});
我发送数据的功能
static void send_data(List<int> charCodes,int byte_to_read){
Uint8List bytes = Uint8List.fromList(charCodes);
Costanti.dati_arrivati = new List<int>(); //------>> array where I accumulate incoming bytes
Costanti.connection.output.add(bytes); // Sending data
}
读取传入字节的功能
static stream_read(){
Costanti.connection.input.listen((datiLetti) {
// print("${datiLetti.length}");
for(int i=0; i< datiLetti.length; i++){
Costanti.dati_arrivati.add(datiLetti[i])
}
}).onDone((){
toast_message("Device no longer connected");
});
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。