Can QSerialPort read more than 512 bytes of data?

前端 未结 2 1456
温柔的废话
温柔的废话 2021-01-28 06:28

I want to use QSerialPort to read data transmitted from a device. The device transmits a frame of 4000 data bytes each time. I try with the following simple code



        
2条回答
  •  面向向阳花
    2021-01-28 06:54

    There's no limit, but you don't necessarily receive all data in single chunk. You have to keep listening until you have the number of bytes you're waiting for (or a timeout).

    void MainWindow::serialReceived()
    {
        receivedData.append(serialPort->readAll());
        if(receivedData.size() >= 4000) {
           // we're full
        }
    }
    

提交回复
热议问题