Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How can I use qMessage bar in a function for receive data for UART?
Forum Updated to NodeBB v4.3 + New Features

How can I use qMessage bar in a function for receive data for UART?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 2 Posters 263 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.
  • M Offline
    M Offline
    Mohit Tripathi
    wrote on last edited by
    #1

    Hi,
    There are two case:
    Case 1: I do not get any response after sending the query.
    Case 2: I get two responses. 1st one similar to Case 1. I t means that I don't get any things but after some time I get the response of 8 bytes.

    Here, I am giving some condition to get the message if I have not received any response but the condition is that I am getting two condition similar in both conditions. How can I rectify that?

    void transmit(QSerialPort & port, const QByteArray & data) {
        port.write(data);
        port.flush();
        qDebug() << "\nWrote" << data.size() << ":" << data.toHex().constData();
        chkError(port);
    }
    
    void receive(QSerialPort & port) {
        QMessageBox msg;
        auto data = port.readAll();
        qDebug()<<data;
    
        qDebug() << "\nRead" << data.size() << ":" << data.toHex().constData();
        data = data.toHex().constData();
        int x,y,z,m,n;
         x = QString::compare("4a", data, Qt::CaseInsensitive);
         y = QString::compare("01", data, Qt::CaseInsensitive);
         z = QString::compare("5b", data, Qt::CaseInsensitive);
         m = QString::compare("03", data, Qt::CaseInsensitive);
         n = QString::compare("", data, Qt::CaseInsensitive);
    
        qDebug() << "x: "<<x;
        qDebug() << "y: "<<y;
        qDebug() << "z: "<<z;
        qDebug() << "m: "<<m;
        qDebug() << "n: "<<n;
        if(x==0)
        {
            msg.setText("\nConnection Error\n");
            msg.exec();
           // return;
        } else
        if(y==0)
        {
            msg.setText("Transmission Error");
            msg.exec();
            //return;
        }else
        if(z==0)
        {
            msg.setText("\nCRC ERROR\n");
            msg.exec();
           // return;
        } else
        if(m==0)
        {
            msg.setText("\nData Mismatch\n");
            msg.exec();
           // return;
        } else
            if(n!=0)
        {
            msg.setText("\nConnection failed\n");
            msg.exec();
        }else
        {
            ;
        }
    
        chkError(port);
    }
    

    The condition n is for not getting the data but how can I identify in both conditions? I am getting the response "condition failed" in both case.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How are you using QSerialPort ? Asynchronously or synchronously ?

      In any case you have to take into account that you might not receive all your data at once. You have to cumulate what you get until you can ensure that you have a full frame of your data and then process it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mohit Tripathi
        wrote on last edited by
        #3

        I am using the synchronously.
        I am not receiving the data at once.

           do {
                  receive(port);
            } while (port.waitForReadyRead(3000));
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Out of curiosity, why use it synchronously ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

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