QSerialPort许多线路的正确发送
QSerialPort proper sending of many lines
本文关键字:许多线 QSerialPort 更新时间:2023-10-16
我正试图使用QSerialPort(QT 5.3.1)将非常大的文件写入串行端口。问题是,我不断发送超出设备处理能力的文件。程序工作方式如下(此函数在50ms内调用一次):
void MainWindow::sendNext()
{
if(sending && !paused && port.isWritable())
{
if(currentLine >= gcode.size()) //check if we are at the end of array
{
sending = false;
currentLine = 0;
ui->sendBtn->setText("Send");
ui->pauseBtn->setDisabled("true");
return;
}
if(sendLine(gcode.at(currentLine))) currentLine++; //check if this was written to a serial port
ui->filelines->setText(QString::number(gcode.size()) + QString("/") + QString::number(currentLine) + QString(" Lines"));
ui->progressBar->setValue(((float)currentLine/gcode.size()) * 100);
}
}
但它最终会出现缺陷并挂起(在设备上,而不是在PC上)。如果我能以某种方式检查设备是否准备好下一行就好了,但我在QSerial文档中找不到类似的东西。有什么想法吗?
您可以使用QSerialPort::waitForBytesWritten
来确保写入字节。然而,这个函数会阻塞线程,建议在新线程中使用它,否则主线程会被阻塞,应用程序会定期冻结。
RS232确实具有一些流量控制功能。检查您的设备是否使用RTS/CTS,如果使用,请更改连接属性以使用硬件流控制。QSerialPort还允许使用dataTerminalReady
或requestToSend
手动检查流量控制线路
相关文章:
- 从不同线程使用int64的不同字节安全吗
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 在C++中使用cURL和多线程
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 在cuda线程之间共享大量常量数据
- 如何将元素添加到数组的线程安全函数?
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 异常属于C++中的线程还是进程
- C++中的线程安全删除
- C++使用params创建线程函数会导致转换错误
- 在具有许多内核的计算机上,使用 Boost ASIO 只能使用 1 个线程
- std::shared_ptr 在一个写入器中,许多阅读器设计是线程安全的吗?
- 当许多线程的输出是可变长度时,我应该如何合并它?
- pthreads如何创建许多线程
- QSerialPort许多线路的正确发送
- 从另一个线程将数据发送到 QSerialPort
- 如何使用boost::statechart在固定数量的线程上复用许多异步状态机
- 我如何避免许多线程锁在互斥锁(拥有)的线程睡眠