Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSerialPort can't handle custom baud rate of 500K??
Forum Updated to NodeBB v4.3 + New Features

QSerialPort can't handle custom baud rate of 500K??

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 5 Posters 666 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    epicQt
    wrote on last edited by
    #1

    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"
    
    eyllanescE 1 Reply Last reply
    0
    • E epicQt

      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"
      
      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

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

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      E 1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

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

        E 1 Reply Last reply
        2
        • eyllanescE eyllanesc

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

          E Offline
          E Offline
          epicQt
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • mrjjM mrjj

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

            E Offline
            E Offline
            epicQt
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by
              #6

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

              C++ is a perfectly valid school of magic.

              1 Reply Last reply
              0
              • fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by
                #7

                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.

                C++ is a perfectly valid school of magic.

                1 Reply Last reply
                0
                • nageshN Offline
                  nageshN Offline
                  nagesh
                  wrote on last edited by
                  #8

                  @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

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    epicQt
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    3

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved