Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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"
    


  • @epicQt 9600 is very slow, why don't you use 115200? That is an industry standard speed.


  • Lifetime Qt Champion

    Hi
    Does esp->setBaudRate(500000); return true ?
    Also can your hardware / Os handle 50k baud ?



  • @eyllanesc 115200 is not fast enough for my application. That's the point.



  • @mrjj yes, it returns true. The hardware can handle it (ESP32). I'm using it nodejs and it works perfectly at 500000 baud. I'm trying to port it to Qt.



  • Does the esp autonegotiate? Are you setting speed to 500K on esp itself?
    Trying to eliminate variables.



  • Also, complete examples of both ends would help. I have esp at home, but I am not going to gin up an esp and qt program to test this.



  • @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



  • The problem was with my Arduino code. I have modified it and it now works even at 500K baud rate!


Log in to reply