如何知道什么时候QSerialPort准备在QT5更多的数据? [英] How to know when QSerialPort is ready for more data in Qt5?

查看:434
本文介绍了如何知道什么时候QSerialPort准备在QT5更多的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一些方法,我的串行设备已准备好接收更多的数据被通知?

我使用的异步的API实现,要通过串行伺服控制器提要命令的程序。 HTML相对=nofollow> QSerialPort 。该项目工程,但似乎我遇到拥堵。

I am implementing a program that feeds commands to a servo controller over serial using the asynchronous API of QSerialPort. The program works, but it seems that I am experiencing congestion.

在我的应用程序保持最新伺服位置的注册,我希望与低延迟尽量控制器同步。我在尽可能快地时间让我推新数据的串行端口作法会导致什么,我认为是使通信打破完全数据的积累。

In my application I keep a registry of most updated servo position that I wish to synchronize with the controller with as low latency as possible. My attempt at pushing new data to the serial port as quickly as time lets me leads to what I think is a buildup of data that makes the communication break down altogether.

我的问题是,我可以得到通知时,串行接口已准备好以某种方式接收新的数据,而使用 QSerialPort 中的异步的模式?

My question is, can I be notified when the serial interface is ready to receive new data somehow while using QSerialPort in asynchronous mode?

唯一的其他选择我看到的是使用的同步的模式和调用的 waitForBytesWritten()但我真的不想这样做。

The only other option I see is to use synchronous mode and call waitForBytesWritten() But I really don't want to do that.

请注意:我研究href=\"http://doc.qt.io/qt-5/qtserialport-examples.html\" rel=\"nofollow\">串口例子QT5文档谨慎,但对于异步写入的例如不提供信息我需要的,因为它执行一次性退出前送。

NOTE: I have studied the serial port examples in the Qt5 documentation carefully, but the example for asynchronous write does not provide the information I need, as it perform a one-shot send before quitting.

推荐答案

您可以监听信号 bytesWritten 和检查 bytesToWrite 来确定该写缓冲区是空的。无论是从的QIODevice 继承。

You could listen to the signal bytesWritten and check bytesToWrite to determine if the write buffer is empty. Both are inherited from QIODevice.

这篇关于如何知道什么时候QSerialPort准备在QT5更多的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆