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. Qt Serial port Not Receive data until send data to mc.
Qt 6.11 is out! See what's new in the release blog

Qt Serial port Not Receive data until send data to mc.

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 3.3k 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #2

    What Qt version do you use? There were some problems with 5.12.x (@aha_1980: you know better) with the readyRead() signal.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    M 1 Reply Last reply
    2
    • Christian EhrlicherC Christian Ehrlicher

      What Qt version do you use? There were some problems with 5.12.x (@aha_1980: you know better) with the readyRead() signal.

      M Offline
      M Offline
      Marco Flad
      wrote on last edited by
      #3

      @Christian-Ehrlicher said in Qt Serial port Not Receve data until send data to mc.:

      12
      iam using Qt 5.14.0 (MSVC 2017, 32 bit)
      thanks for replay

      1 Reply Last reply
      0
      • M Marco Flad

        i used the blockingslave Example to Ensure the Micro Controller send data and received it correct without any missing in data i mean " if any input pin on micro controller status changes from low to high and vs versa send data over serial port to QT"
        my problem the readyrad() signal doesn't emitted until i send any data to micro controller from qt and by the way i send data to micro controller suspenseful without no error or missing.

        //mainwindow.h
        #ifndef MAINWINDOW_H
        #define MAINWINDOW_H
        #include <QMainWindow>
        #include <QtDebug>
        
        QT_BEGIN_NAMESPACE
        namespace Ui { class MainWindow; }
        QT_END_NAMESPACE
        class QSerialPort ;
        class MainWindow : public QMainWindow
        {
            Q_OBJECT
        
        public:
            MainWindow(QWidget *parent = nullptr);
            ~MainWindow();
        private slots:
        
        private:
            Ui::MainWindow *ui;
            //Serial
            QSerialPort *mc;
            //for Rs232 Cable NotArduino
            static const quint16 arduino_uno_vendor_id  =  1367;   //9025 ; 
            static const quint16 arduino_uno_product_id =  8200;   //67   ; 
            QString mc_port_name;
            bool mc_is_available;
        };
        #endif // MAINWINDOW_H
        

        //mainwindow.cpp
        
        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QSerialPort>
        #include <QSerialPortInfo>
        
            ui->setupUi(this);
           QMainWindow::showFullScreen();
        
            //********************************************DoSerialAutoConnect***********************************************//
            //**************************************************************************************************************//
        
        MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent )  //, Qt::FramelessWindowHint
            , ui(new Ui::MainWindow)
        {
            mc_is_available = false;
            mc_port_name = "";
            mc = new QSerialPort(this);
        
        
            qDebug() << "Number of available ports: " << QSerialPortInfo::availablePorts().length();
            foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){
                qDebug() << "Has vendor ID: " << serialPortInfo.hasVendorIdentifier();
                if(serialPortInfo.hasVendorIdentifier()){
                    qDebug() << "Vendor ID: " << serialPortInfo.vendorIdentifier();
                }
                qDebug() << "Has Product ID: " << serialPortInfo.hasProductIdentifier();
                if(serialPortInfo.hasProductIdentifier()){
                    qDebug() << "Product ID: " << serialPortInfo.productIdentifier();
                }
            }
        
        
            foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){
                if(serialPortInfo.hasVendorIdentifier() && serialPortInfo.hasProductIdentifier()){
                    if(serialPortInfo.vendorIdentifier() == arduino_uno_vendor_id){
                        if(serialPortInfo.productIdentifier() == arduino_uno_product_id){
                            mc_port_name = serialPortInfo.portName();
                            mc_is_available = true;
                        }
                    }
                }
            }
        
            if(mc_is_available){
                // open and configure the serialport
                mc->setPortName(mc_port_name);   //QString("COM8")
                mc->open(QIODevice::ReadWrite);
                mc->setBaudRate(QSerialPort::Baud9600);
                mc->setDataBits(QSerialPort::Data8);
                mc->setParity(QSerialPort::NoParity);
                mc->setStopBits(QSerialPort::OneStop);
                mc->setFlowControl(QSerialPort::NoFlowControl);
        
                connect(mc, SIGNAL(readyRead()), this, SLOT(updateReceivedData()));
            }else{
                // give error message if not available
                QMessageBox::warning(this, "Port error", "Couldn't find the Arduino!");
            }
        }
        
        MainWindow::~MainWindow()
        {
            delete ui;
            if(mc->isOpen()){
                mc->close();
            }
        }
        
        
        void MainWindow::updateReceivedData()
        {
            // qDebug("received data\n");
            // arduino->waitForReadyRead(100);
        
            inBuffer = mc->readAll();
            while (mc->waitForReadyRead(10))
                inBuffer += mc->readAll();
            qDebug() << inBuffer;
        
        

        please any help ;

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Hi,

        @Marco-Flad said in Qt Serial port Not Receve data until send data to mc.:

        // open and configure the serialport
        mc->setPortName(mc_port_name); //QString("COM8")
        mc->open(QIODevice::ReadWrite);
        mc->setBaudRate(QSerialPort::Baud9600);
        mc->setDataBits(QSerialPort::Data8);
        mc->setParity(QSerialPort::NoParity);
        mc->setStopBits(QSerialPort::OneStop);
        mc->setFlowControl(QSerialPort::NoFlowControl);

        Two things:

        • Do the complete setup before calling open
        • Check the return value of open, it might have failed and you don't check that case.

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

        M 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          @Marco-Flad said in Qt Serial port Not Receve data until send data to mc.:

          // open and configure the serialport
          mc->setPortName(mc_port_name); //QString("COM8")
          mc->open(QIODevice::ReadWrite);
          mc->setBaudRate(QSerialPort::Baud9600);
          mc->setDataBits(QSerialPort::Data8);
          mc->setParity(QSerialPort::NoParity);
          mc->setStopBits(QSerialPort::OneStop);
          mc->setFlowControl(QSerialPort::NoFlowControl);

          Two things:

          • Do the complete setup before calling open
          • Check the return value of open, it might have failed and you don't check that case.
          M Offline
          M Offline
          Marco Flad
          wrote on last edited by
          #5

          @SGaist
          i move open to down and checked if is isOpen() .
          Everything that can return Boolean returns a true state and without errors.
          the strange problem is
          if i send any number of messages from micro controller this messages stored in buffer and not appear until readyread() is emitted
          and readyread() not emitted until i send data to the micro controller i.e when i call arduino->write (" ");
          the hilighted is one message the three messages is sent from micro controller in different times but appears in debugger when i send data to micro controller .
          alt text

          aha_1980A 1 Reply Last reply
          0
          • M Marco Flad

            @SGaist
            i move open to down and checked if is isOpen() .
            Everything that can return Boolean returns a true state and without errors.
            the strange problem is
            if i send any number of messages from micro controller this messages stored in buffer and not appear until readyread() is emitted
            and readyread() not emitted until i send data to the micro controller i.e when i call arduino->write (" ");
            the hilighted is one message the three messages is sent from micro controller in different times but appears in debugger when i send data to micro controller .
            alt text

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #6

            Hi @Marco-Flad,

            my problem the readyrad() signal doesn't emitted until i send any data to micro controller

            May it be that your microcontroller is exactly programmed like that? It does not seem unusual to me.

            Anyway, you should first try the communication with a terminal program to ensure everything is working correctly before programming yourself.

            Afterwards, you should try and study the Terminal example, you can get it from the examples section in Qt Creator.

            And then you can come back to your own code.

            Regards

            Qt has to stay free or it will die.

            M 1 Reply Last reply
            0
            • aha_1980A aha_1980

              Hi @Marco-Flad,

              my problem the readyrad() signal doesn't emitted until i send any data to micro controller

              May it be that your microcontroller is exactly programmed like that? It does not seem unusual to me.

              Anyway, you should first try the communication with a terminal program to ensure everything is working correctly before programming yourself.

              Afterwards, you should try and study the Terminal example, you can get it from the examples section in Qt Creator.

              And then you can come back to your own code.

              Regards

              M Offline
              M Offline
              Marco Flad
              wrote on last edited by
              #7

              @aha_1980 said in Qt Serial port Not Receive data until send data to mc.:

              your

              Hi ,
              iam sorry but i try Terminal program isn't work but PuTTY work well and blockingslave serial example work very well also in send and recive so i think the only way to use thriding like blocking slave example .

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kuzulis
                Qt Champions 2020
                wrote on last edited by kuzulis
                #8

                Are you sure that you use Qt 5.14.0? Maybe you use Qt 5.13.1? Please check it again and again.

                PS: As I see that you use Qt 5.13.1 && MinGW, according to your another post (with mutex).

                M 1 Reply Last reply
                3
                • K kuzulis

                  Are you sure that you use Qt 5.14.0? Maybe you use Qt 5.13.1? Please check it again and again.

                  PS: As I see that you use Qt 5.13.1 && MinGW, according to your another post (with mutex).

                  M Offline
                  M Offline
                  Marco Flad
                  wrote on last edited by
                  #9

                  @kuzulis
                  hi ,
                  ya you are right iam using C:\Qt\5.13.1 i notice it after locking in setting
                  but in (Help about Qt creator ) Based on 5.14.0 and
                  alt text
                  and in Manage kit only 5.13.1 so ho to update version
                  f6f564ed-6251-477f-b7ce-d5a8383e68cd-image.png image url)
                  thank you ,

                  aha_1980A 1 Reply Last reply
                  0
                  • M Marco Flad

                    @kuzulis
                    hi ,
                    ya you are right iam using C:\Qt\5.13.1 i notice it after locking in setting
                    but in (Help about Qt creator ) Based on 5.14.0 and
                    alt text
                    and in Manage kit only 5.13.1 so ho to update version
                    f6f564ed-6251-477f-b7ce-d5a8383e68cd-image.png image url)
                    thank you ,

                    aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    Hi @Marco-Flad,

                    your Qt Creator is build with Qt 5.14, but your kit is using Qt 5.13 - that explains your problems.

                    You can update your installation with the MaintenanceTool in c:\Qt. I'd recommend to uninstall Qt 5.13.1 so you do not accidently use it again.

                    Regards

                    Qt has to stay free or it will die.

                    M 1 Reply Last reply
                    4
                    • aha_1980A aha_1980

                      Hi @Marco-Flad,

                      your Qt Creator is build with Qt 5.14, but your kit is using Qt 5.13 - that explains your problems.

                      You can update your installation with the MaintenanceTool in c:\Qt. I'd recommend to uninstall Qt 5.13.1 so you do not accidently use it again.

                      Regards

                      M Offline
                      M Offline
                      Marco Flad
                      wrote on last edited by
                      #11

                      @aha_1980 thanks Very match its all about version
                      @kuzulis thanks for your support
                      my pleasures.

                      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