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. Reading data from Serial Port is extremely slow
Forum Updated to NodeBB v4.3 + New Features

Reading data from Serial Port is extremely slow

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 606 Views 1 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.
  • serkan_trS Offline
    serkan_trS Offline
    serkan_tr
    wrote on last edited by
    #1

    On the QT C++ side, I want to transfer the potentiometer data I got from Arduino to the slider on the screen. but 3-5 minutes after moving the potentiometer, the slider starts to move this is a huge delay codes i think it's an error in the code part:
    arduino Code:

    void setup() {
      Serial.begin(115200);
    }
    void loop(){
    void loop() {
      uint8_t data = map(analogRead(A0),0,1023,0,255);
      Serial.write(data);
    }
    

    QT C++ code

    joy = std::thread{std::bind(&MainWindow::setRxData, this)};
    .
    .
    bool MainWindow::rxData(){
            while(true){
                if(serial_.waitForReadyRead(10)){
                    uint8_t value;
                    quint64 size = serial_.read((char*)&value, sizeof(value));
                    qDebug() << "Read" << value << "bytes:";
                    data_ch[0] =  value;
                    sliderChange();
    }}}
    
    void MainWindow::sliderChange(){
        ui->slider_1->setValue(data_ch[0]);
    }
    
    
    JonBJ 1 Reply Last reply
    0
    • serkan_trS serkan_tr

      On the QT C++ side, I want to transfer the potentiometer data I got from Arduino to the slider on the screen. but 3-5 minutes after moving the potentiometer, the slider starts to move this is a huge delay codes i think it's an error in the code part:
      arduino Code:

      void setup() {
        Serial.begin(115200);
      }
      void loop(){
      void loop() {
        uint8_t data = map(analogRead(A0),0,1023,0,255);
        Serial.write(data);
      }
      

      QT C++ code

      joy = std::thread{std::bind(&MainWindow::setRxData, this)};
      .
      .
      bool MainWindow::rxData(){
              while(true){
                  if(serial_.waitForReadyRead(10)){
                      uint8_t value;
                      quint64 size = serial_.read((char*)&value, sizeof(value));
                      qDebug() << "Read" << value << "bytes:";
                      data_ch[0] =  value;
                      sliderChange();
      }}}
      
      void MainWindow::sliderChange(){
          ui->slider_1->setValue(data_ch[0]);
      }
      
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @serkan_tr
      Does it make any difference if you do not create a separate thread and use waitForReadyRead() but rather just use Qt's asynchronous serial calls instead?

      serkan_trS 1 Reply Last reply
      0
      • JonBJ JonB

        @serkan_tr
        Does it make any difference if you do not create a separate thread and use waitForReadyRead() but rather just use Qt's asynchronous serial calls instead?

        serkan_trS Offline
        serkan_trS Offline
        serkan_tr
        wrote on last edited by
        #3

        @JonB I do not fully understand

        JonBJ 1 Reply Last reply
        0
        • serkan_trS serkan_tr

          @JonB I do not fully understand

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @serkan_tr
          I do not know why you use std::thread, a while(true) loop and waitForReadyRead(). I suggested you try with Qt's QSerialPort asynchronous signals/slots and no separate thread to see whether that affected performance. I do not know whether that is an issue.

          Furthermore (all related to your thread usage): do I understand that your MainWindow::rxData() runs in some other thread? But it calls ui->slider_1->setValue(), it is forbidden in Qt to access the main UI widgets from any other thread....

          serkan_trS 1 Reply Last reply
          4
          • serkan_trS serkan_tr has marked this topic as solved on
          • JonBJ JonB

            @serkan_tr
            I do not know why you use std::thread, a while(true) loop and waitForReadyRead(). I suggested you try with Qt's QSerialPort asynchronous signals/slots and no separate thread to see whether that affected performance. I do not know whether that is an issue.

            Furthermore (all related to your thread usage): do I understand that your MainWindow::rxData() runs in some other thread? But it calls ui->slider_1->setValue(), it is forbidden in Qt to access the main UI widgets from any other thread....

            serkan_trS Offline
            serkan_trS Offline
            serkan_tr
            wrote on last edited by
            #5

            @JonB
            Thank you

            1 Reply Last reply
            0

            • Login

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