C++ 尝试读取时QextSerialPort块
我在Windows上使用QextSerialPort使我的Qt/C++应用程序能够从串行端口读写 我只想在有字节要读取时从串行端口读取字节 首先,我尝试将C++ 尝试读取时QextSerialPort块,c++,qt,serial-port,qextserialport,C++,Qt,Serial Port,Qextserialport,我在Windows上使用QextSerialPort使我的Qt/C++应用程序能够从串行端口读写 我只想在有字节要读取时从串行端口读取字节 首先,我尝试将QextSerialPort::readyRead()信号连接到主类中的插槽,但我注意到应用程序挂起 然后我尝试使用返回读取字节数的QextSerialPort::read(char*,uint64),然后我尝试将QextSerialPort::bytesavasible()和QextSerialPort::read(char*,uint64)
QextSerialPort::readyRead()
信号连接到主类中的插槽,但我注意到应用程序挂起
然后我尝试使用返回读取字节数的QextSerialPort::read(char*,uint64)
,然后我尝试将QextSerialPort::bytesavasible()
和QextSerialPort::read(char*,uint64)
组合起来,看看这是否有助于我的应用程序不被阻塞
但是,由于应用程序不响应任何鼠标或键盘事件,因此该应用程序始终会被阻止并必须终止。我按下按钮,应用程序冻结,因为读取例程阻塞
有没有办法用QextSerialPort执行非阻塞读取
如果没有,我应该使用什么库从Windows上的串行端口进行非阻塞读取
更新:
我尝试使用
QextSerialPort::atEnd()
来检查是否有字节要读取,而不是使用QextSerialPort::bytesavable()
或QextSerialPort::size()
,它总是返回false。读取应该是非阻塞的,除非您将查询模式设置为轮询
inline QueryMode queryMode() const { return _queryMode; }
/*!
* Set desired serial communication handling style. You may choose from polling
* or event driven approach. This function does nothing when port is open; to
* apply changes port must be reopened.
*
* In event driven approach read() and write() functions are acting
* asynchronously. They return immediately and the operation is performed in
* the background, so they doesn't freeze the calling thread.
* To determine when operation is finished, QextSerialPort runs separate thread
* and monitors serial port events. Whenever the event occurs, adequate signal
* is emitted.
*
* When polling is set, read() and write() are acting synchronously. Signals are
* not working in this mode and some functions may not be available. The advantage
* of polling is that it generates less overhead due to lack of signals emissions
* and it doesn't start separate thread to monitor events.
*
* Generally event driven approach is more capable and friendly, although some
* applications may need as low overhead as possible and then polling comes.
除非将查询模式设置为轮询,否则读取应该是非阻塞的
inline QueryMode queryMode() const { return _queryMode; }
/*!
* Set desired serial communication handling style. You may choose from polling
* or event driven approach. This function does nothing when port is open; to
* apply changes port must be reopened.
*
* In event driven approach read() and write() functions are acting
* asynchronously. They return immediately and the operation is performed in
* the background, so they doesn't freeze the calling thread.
* To determine when operation is finished, QextSerialPort runs separate thread
* and monitors serial port events. Whenever the event occurs, adequate signal
* is emitted.
*
* When polling is set, read() and write() are acting synchronously. Signals are
* not working in this mode and some functions may not be available. The advantage
* of polling is that it generates less overhead due to lack of signals emissions
* and it doesn't start separate thread to monitor events.
*
* Generally event driven approach is more capable and friendly, although some
* applications may need as low overhead as possible and then polling comes.
恐怕我在任何地方都找不到这个函数。但是,我没有将查询模式设置为轮询(除非我不知道这样做了)。我也无法使用
queryMode()
。默认设置为事件驱动(在ctor中设置)。您使用的是新版本吗?我使用的是来自的1.1版。我已经设法解决了阻塞I/O的问题。我刚刚使用Mercurial从Google代码下载了源代码,但是我仍然有一个字符编码的问题。我将就此提出另一个问题。恐怕我在任何地方都找不到该函数。但是,我没有将查询模式设置为轮询(除非我不知道这样做了)。我也无法使用queryMode()
。默认设置为事件驱动(在ctor中设置)。您使用的是新版本吗?我使用的是来自的1.1版。我已经设法解决了阻塞I/O的问题。我刚刚使用Mercurial从Google代码下载了源代码,但是我仍然有一个字符编码的问题。我将就此提出另一个问题。