UART to Qt software error - why data always split?

戏子无情 提交于 2019-12-08 07:53:11

问题


I am tryig to display data I receive via UART on my Qt application. I send all my data from my microcontroller at once, but my qt application receives it in multiple parts why?

this is what I get: http://imgur.com/kLXRvU5 in stead of: http://imgur.com/h2yNZjl

So every time I receive data my slot function gets called, hence the "data received". But my data is split in two parts. Why please?

my code:

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);
}

回答1:


Streaming connections, like TCP/IP or serial ports, give you zero guaranties about how the data is cut up into pieces. If you want packets, you have to implement them yourself on top of a streaming connection.



来源:https://stackoverflow.com/questions/29150934/uart-to-qt-software-error-why-data-always-split

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!