我正在尝试在我的 Qt 应用程序上显示通过 UART 接收的数据。 我一次从我的微 Controller 发送了所有数据,但我的 qt 应用程序收到了多个部分,这是为什么?
这是我得到的:http://imgur.com/kLXRvU5 代替:http://imgur.com/h2yNZjl
所以每次我收到数据时,我的槽函数都会被调用,因此是“收到的数据”。但是我的数据分为两部分。为什么请?
我的代码:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)//, mijnAnimatie(new animatie())
{
serialPort->setPortName("COM13");
serialPort->setBaudRate(QSerialPort::Baud115200);
// serialPort->setDataBits(QSerialPort::Data8);
// serialPort->setParity(QSerialPort::NoParity);
// serialPort->setStopBits(QSerialPort::OneStop);
if (!serialPort->open(QIODevice::ReadWrite))
{
qDebug("some error when opening\n");
}
connect(serialPort, SIGNAL(readyRead()), this, SLOT(updateReceivedData()));
}
void MainWindow::updateReceivedData()
{
qDebug("received data\n");
QString m_readData;
ui->receiveLabel->setText(m_readData);
QByteArray result = serialPort->readAll();
QString command(result); //to convert byte array to string
qDebug()<<result;
ui->receiveLabel->setText(command);
}
最佳答案
流式连接,如 TCP/IP 或串行端口,零 保证数据如何分割。如果你想要数据包,你必须在流连接之上自己实现它们。
关于c++ - UART 到 Qt 软件错误 - 为什么数据总是 split ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29150934/