QSerialPort can't handle custom baud rate of 500K??
-
I need to receive a large amount of data from an ADC (24 ADC channels at 24 bits and 250 samples per second = 18 kilobytes per second.
when I connect the readyRead() signal to my slot I'm not getting a good output at 500000 baud when I senda short test string from my sensor ("hello"). When I lower the baud rate to 19200 or 9600 I get a correct output.
Can Qt handle 500K baud rate? what could the problem be?
My Qt code and output below, also note that at 500K baud it takes multiple clicks to get the the string and it also misses a character ("hllo" on the second click). At 9600 baud it only takes one click to receive the whole string:
void Dialog::on_connect_clicked() { if(esp_available){ esp->setPortName(espPortName); esp->setBaudRate(500000); esp->setDataBits(QSerialPort::Data8); esp->setParity(QSerialPort::NoParity); esp->setStopBits(QSerialPort::OneStop); esp->setFlowControl(QSerialPort::NoFlowControl); connect(esp, SIGNAL(readyRead()), this, SLOT(onDataReady())); //connect(esp, &QSerialPort::readyRead, this, &Dialog::onDataReady); // I've also tried esp->open(QSerialPort::ReadWrite); esp->clear(); } void Dialog::on_startStream_clicked() { if(esp->isOpen()){ esp->write("hello"); } } void Dialog::onDataReady() { QByteArray ba; if(esp->canReadLine()){ ba = esp->readLine(); ba = ba.simplified(); QString ba_with_time = stamp->currentDateTime().toString("MM.dd.yyyy hh:mm:ss "); ba_with_time.append(ba); ui->output->appendPlainText(ba_with_time); qDebug() << ba; } }
Output at 500000 baud rate:
"04.15.2021 15:31:40 �h" // 1st click 04.15.2021 15:32:09 ello // 2nd click 04.15.2021 15:32:09 hllo //2nd click
Output at 9600 baud rate, only 1 click needed:
"04.15.2021 15:28:10 h" "04.15.2021 15:28:10 e" "04.15.2021 15:28:10 l" "04.15.2021 15:28:10 l" "04.15.2021 15:28:10 o"
-
Hi
Does esp->setBaudRate(500000); return true ?
Also can your hardware / Os handle 50k baud ? -
@epicQt said in QSerialPort can't handle custom baud rate of 500K??:
canReadLine
@epicQt Are you doing loop back reading in serial port? As it looks like same application is sending data and reading it?
Can you try in the void Dialog::onDataReady() function
esp->read(esp->bytesAvailable()) or esp->readAll() to read the data