Web串行API可读流代码不能很好地工作
while (true) {
let { value, done } = await reader.read();
if (done) {
// |reader| has been canceled.
console.log("brack");
break;
}
console.log(value);
console.log()
}
} catch (error) {
// Handle |error|...
} finally {
reader.releaseLock();
console.log("f1");
}
当我从串行端口读取数据时,我的整个数据都被完美接收,但是“done”变量的
值永远不会改变,它仍然为假,并且代码在此阶段停止“let {value,done}=等待读者。读();”。
while (true) {
let { value, done } = await reader.read();
if (done) {
// |reader| has been canceled.
console.log("brack");
break;
}
console.log(value);
console.log()
}
} catch (error) {
// Handle |error|...
} finally {
reader.releaseLock();
console.log("f1");
}
}
when I read data from the serial port, my whole data is perfectly received, but the value of the "done" variable never changes it remains false and the code is stop on this stage " let { value, done } = await the reader.read();".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非串行端口遇到错误,否则您始终能够读取更多数据,因此
done
永远不会设置为true
。如果您的程序已经读取了它想要读取的所有数据,那么它应该停止调用 read() 直到它想要接收更多数据。请注意,如果设备发送的数据多于打开端口时指定的缓冲区大小,并且您的应用程序未调用read()
将其从缓冲区中拉出,则该数据可能会丢失。Unless the serial port encounters an error you will always be able to read more data and so
done
is never set totrue
. If your program has read all the data it intends to then it should stop callingread()
until it wants to receive more data. Note, if the device sends more data than the buffer size specified when opening the port this data may be lost if your application isn't callingread()
to pull it out of the buffer.