Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for MCUs
  4. readyRead() signal is working strange
QtWS25 Last Chance

readyRead() signal is working strange

Scheduled Pinned Locked Moved Unsolved Qt for MCUs
qserialportreadyreadserial portrs485
14 Posts 3 Posters 2.5k Views
  • 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.
  • I Offline
    I Offline
    IRBaboon
    wrote on 18 Nov 2020, 20:43 last edited by
    #1

    Greetings!

    I have encountered a problem I cannot solve.
    I am using the QSerialPort device to read/write data from/to my hardware device.
    I am encountering problem just after sending a request to start my device's main sequence.
    After getting all information my device is sending near a 370 bytes to the serial port via a RS-485->transform device->USB and I am supposed to get the readyRead() signal so I will be able to parse the data. But I do not get the signal at all. Though after I send the second request - I get the readyRead() signal and begin the parsing procedure. And this situation repeats again and again.
    Can anyone help me with this?

    COM = new QSerialPort(this);
        foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
                ui->com_combobox->addItem(info.portName());
    
        echo_pix->scaled(ui->echo_label->size());
        ui->echo_label->setPixmap(*echo_pix);
        ui->echo_label->setScaledContents(true);
    
        setup_the_plot();
    
        connect(ui->com_button, SIGNAL(clicked(bool)), this, SLOT(connectCOM()));
        connect(ui->echo_button, SIGNAL(clicked(bool)), this, SLOT(getEcho()));
        connect(ui->getdata_button, SIGNAL(clicked(bool)), this, SLOT(getADC()));
        connect(ui->switch_button, SIGNAL(clicked(bool)), this, SLOT(setSwtich()));
        connect(ui->att_button, SIGNAL(clicked(bool)), this, SLOT(setAttenuation()));
        connect(ui->path_dial, SIGNAL(sliderReleased()), this, SLOT(selectPath()));
        connect(ui->antenna_dial, SIGNAL(sliderReleased()), this, SLOT(selectAnt()));
        connect(ui->att_slider, SIGNAL(valueChanged(int)), this, SLOT(selectAtt()));
        connect(ui->att_lineedit, SIGNAL(editingFinished()), this, SLOT(writeAtt()));
        connect(ui->setgenButton, SIGNAL(clicked(bool)), this, SLOT(generation_maintain()));
        connect(in_message, SIGNAL(returnPressed()), this, SLOT(through_filters_test()));
        connect(ui->clearGraph_button, SIGNAL(clicked(bool)), this, SLOT(clear_graph()));
        connect(timer_1, SIGNAL(timeout()), this, SLOT(send_accept()));
        connect(timer_3, SIGNAL(timeout()), this, SLOT(not_received()));
        connect(COM, SIGNAL(readyRead()), this, SLOT(readData()));
        connect(ad5932_send, SIGNAL(clicked(bool)), this, SLOT(ad5932_send_data()));
        connect(adf4360_send, SIGNAL(clicked(bool)), this, SLOT(adf4360_send_data()));
        connect(crystal_send, SIGNAL(clicked(bool)), this, SLOT(crystal_send_data()));
    

    This is from the constructor.

    void MainWindow::connectCOM(void)
    {
        if(COM->portName() != ui->com_combobox->currentText())
        {
            COM->close();
            COM->setPortName(ui->com_combobox->currentText());
        }
    
        COM->setBaudRate(QSerialPort::Baud115200);
        COM->setDataBits(QSerialPort::Data8);
        COM->setParity(QSerialPort::NoParity);
        COM->setStopBits(QSerialPort::OneStop);
        COM->setFlowControl(QSerialPort::NoFlowControl);
        //COM->setReadBufferSize(10);
        if(COM->open(QSerialPort::ReadWrite))
        {
            ui->comstate_label->setText("<FONT COLOR=#008000>Opened</FONT>");
            com_mode = 1;
            //ui->label->setStyleSheet()
        }
        else
        {
            COM->close();
            ui->comstate_label->setText("<FONT COLOR=red>Closed</FONT>");
            com_mode = 0;
        }
    }
    

    COM port open slot

    void MainWindow::readData(void)
    {
        char temp = 0;
        std_union temp_1;
        uint16_t len_effective = 0;
        long_std_union data_temp;
        data_temp.listd = 0;
        uint16_t window = 360;
        qDebug() << "hello...";
        ba.push_back(COM->readAll());
        qDebug() << ba.size();
    
        int idx = ba.indexOf(0x02, 0);
        if(idx >= 0)
        {
            if(idx > 0)
            {
                ba.remove(0,idx);
                idx = 0;
            }
            if(ba.size() > 5)
            {           // return
                temp_1.cstd[1] = ba[1];
                temp_1.cstd[0] = ba[2];
                if((temp_1.istd >= 6) || (temp_1.istd < 3000))
    
                if(ba.size() >= temp_1.istd)
                {
                    temp = ba[3];
                    qDebug() << "hello!";
                    if(temp == UART_ADDR)
                    {
                        len.istd = temp_1.istd;
                        for(int i = 0; i < len.istd; i++)
                        {
                            CRC ^= ba[i];
                        }
                        if(CRC == 0)
                        {
                            temp = ba[4];
                            QString string_temp_1(temp);
                            qDebug() << string_temp_1;
                            switch (temp)
                            {
                            case ECHO:
                                echo_pix->load("greendot.jpg");
                                echo_pix->scaled(ui->echo_label->size());
                                ui->echo_label->setPixmap(*echo_pix);
                                ui->echo_label->setScaledContents(true);
                                uart_command = 0;
                                break;
                            case ADC_CONT_1SEC:
                                qDebug() << data_check_box;
                                if(data_check_box == ON)
                                {
                                    len_effective = (len.istd - SERVICE_BITS_LEN)/2;
                                    qDebug() << "reading...";
                                    for (int i = 0; i < len_effective; i++)
                                    {
                                        data_temp.cstd[1] = ba[i*2 + 5];
                                        data_temp.cstd[0] = ba[i*2 + 6];
                                        ADC_DATA_BUFFER[i] = (((data_temp.istd[0])));//average_filter median_filter lowpass_filter
                                        adc_call_command_counter++;
                                        //fileStream << QString::number(ADC_DATA_BUFFER[i]);
                                    }
    
                                    Fourier.module = new double[adc_call_command_counter];
                                    Fourier.real = new double[adc_call_command_counter];
                                    Fourier.image = new double[adc_call_command_counter];
                                    Fourier_1.module = new double[adc_call_command_counter];
                                    Fourier_1.real = new double[adc_call_command_counter];
                                    Fourier_1.image = new double[adc_call_command_counter];
                                    Fourier = discrete_FourierTransform(ADC_DATA_BUFFER, zero, 1, adc_call_command_counter);
                                    Fourier.real[0] = 0;
                                    Fourier.image[0] = 0;
                                    Fourier.module[0] = 0;
                                    for(uint16_t i = window; i < adc_call_command_counter; i++)
                                    {
                                        Fourier.real[i] = 0;
                                        Fourier.image[i] = 0;
                                        Fourier.module[i] = 0;
                                    }
    
                                    Fourier_1 = discrete_FourierTransform(Fourier.real, Fourier.image, -1, adc_call_command_counter);
    
                                    clear_graph();
                                    paint_curve(adc_call_command_counter);
                                    //ui->data_lcdnumber->display(QString::number(adc_call_command_counter));
    
                                    free(Fourier.module);
                                    free(Fourier.real);
                                    free(Fourier.image);
                                    free(Fourier_1.module);
                                    free(Fourier_1.real);
                                    free(Fourier_1.image);
                                    READER_DATA.RAW_SIZE = 0;
                                    adc_call_command_counter = 0;
    
                                    ba.remove(0, temp_1.istd);
                                    timer_1->start();
                                }
                                break;
                            case GENERATION_CTRL:
                                echo_pix->load("greendot.jpg");
                                echo_pix->scaled(ui->echo_label->size());
                                ui->echo_label->setPixmap(*echo_pix);
                                ui->echo_label->setScaledContents(true);
                                uart_command = 2;
                                break;
                            case OUTPUT_SWITCH:
                                echo_pix->load("greendot.jpg");
                                echo_pix->scaled(ui->echo_label->size());
                                ui->echo_label->setPixmap(*echo_pix);
                                ui->echo_label->setScaledContents(true);
                                uart_command = 3;
                                break;
                            case SET_ATT:
                                echo_pix->load("greendot.jpg");
                                echo_pix->scaled(ui->echo_label->size());
                                ui->echo_label->setPixmap(*echo_pix);
                                ui->echo_label->setScaledContents(true);
                                uart_command = 4;
                                break;
                            case AMP_MANAGE:
                                echo_pix->load("greendot.jpg");
                                echo_pix->scaled(ui->echo_label->size());
                                ui->echo_label->setPixmap(*echo_pix);
                                ui->echo_label->setScaledContents(true);
                                uart_command = 5;
                                break;
                            case ADC_ECHO:
                                timer_1->stop();
                                ba.remove(0, temp_1.istd);
                                //COM->clear();
                                break;
                            default:
                                echo_pix->scaled(ui->echo_label->size(),
                                                 Qt::KeepAspectRatioByExpanding);
                                ui->echo_label->setPixmap(QPixmap("reddot.png"));
                                ui->echo_label->setScaledContents(true);
                                uart_command = 255;
                                //COM->clear();
                                timer_1->start();
                                break;
                            }
                            ba.clear();
                        }
                        else
                        {
                            ba.remove(0, temp_1.istd);
                        }
                    }
                    else
                    {
                        ba.remove(0, temp_1.istd);
                    }
                }
            }
            else {
                qDebug() << "error_len";
                ba.clear();
            }
        }
        else {
            qDebug() << "error";
            ba.clear();
        }
        CRC = 0;
    }
    

    This is my parser slot
    Thanks everyone in advance!!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 18 Nov 2020, 21:49 last edited by
      #2

      Hi,

      Which version of Qt are you using ?
      On which OS ?

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

      I 1 Reply Last reply 18 Nov 2020, 21:52
      0
      • S SGaist
        18 Nov 2020, 21:49

        Hi,

        Which version of Qt are you using ?
        On which OS ?

        I Offline
        I Offline
        IRBaboon
        wrote on 18 Nov 2020, 21:52 last edited by
        #3

        @SGaist hello!
        OS Windows 10
        Qt 5.15.1
        Creator 4.13.2

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Crawl.W
          wrote on 19 Nov 2020, 04:00 last edited by
          #4

          Firstly, you need to use packet capture software to see if any returned data is accepted.

          I 1 Reply Last reply 19 Nov 2020, 05:21
          0
          • C Crawl.W
            19 Nov 2020, 04:00

            Firstly, you need to use packet capture software to see if any returned data is accepted.

            I Offline
            I Offline
            IRBaboon
            wrote on 19 Nov 2020, 05:21 last edited by IRBaboon
            #5

            @Crawl-W good day!
            I have used terminal to check if data is accepted correctly.
            All data send by the device was successfully received.

            C 1 Reply Last reply 19 Nov 2020, 05:38
            0
            • I IRBaboon
              19 Nov 2020, 05:21

              @Crawl-W good day!
              I have used terminal to check if data is accepted correctly.
              All data send by the device was successfully received.

              C Offline
              C Offline
              Crawl.W
              wrote on 19 Nov 2020, 05:38 last edited by
              #6

              Ok,it is basically certain that your main thread is occupied. Reference to my topic. QSerialport did not emit readyRead () signal,but USB monitor data received.Only occasionally problem

              I 1 Reply Last reply 19 Nov 2020, 07:19
              0
              • C Crawl.W
                19 Nov 2020, 05:38

                Ok,it is basically certain that your main thread is occupied. Reference to my topic. QSerialport did not emit readyRead () signal,but USB monitor data received.Only occasionally problem

                I Offline
                I Offline
                IRBaboon
                wrote on 19 Nov 2020, 07:19 last edited by
                #7

                @Crawl-W hello!
                I have read all through your topic. Seems that problem is very similar but I do not get what can occupy the thread.
                My programm is working as a terminal in this mode and is suposed to just wait the bytes to be received...

                C 1 Reply Last reply 19 Nov 2020, 07:31
                0
                • I IRBaboon
                  19 Nov 2020, 07:19

                  @Crawl-W hello!
                  I have read all through your topic. Seems that problem is very similar but I do not get what can occupy the thread.
                  My programm is working as a terminal in this mode and is suposed to just wait the bytes to be received...

                  C Offline
                  C Offline
                  Crawl.W
                  wrote on 19 Nov 2020, 07:31 last edited by Crawl.W
                  #8

                  You need to make sure that your main thread is idle when the signal is triggered.
                  Firstly, exclude qt lib version bugs.
                  Then, peel off serial port read and write code, and you should decouple code.
                  In general, for such questions can only provide experience and possibilities. The rest is still have to rely on yourself.

                  I C 2 Replies Last reply 19 Nov 2020, 07:40
                  0
                  • C Crawl.W
                    19 Nov 2020, 07:31

                    You need to make sure that your main thread is idle when the signal is triggered.
                    Firstly, exclude qt lib version bugs.
                    Then, peel off serial port read and write code, and you should decouple code.
                    In general, for such questions can only provide experience and possibilities. The rest is still have to rely on yourself.

                    I Offline
                    I Offline
                    IRBaboon
                    wrote on 19 Nov 2020, 07:40 last edited by IRBaboon
                    #9
                    This post is deleted!
                    C 2 Replies Last reply 19 Nov 2020, 07:42
                    0
                    • I IRBaboon
                      19 Nov 2020, 07:40

                      This post is deleted!

                      C Offline
                      C Offline
                      Crawl.W
                      wrote on 19 Nov 2020, 07:42 last edited by
                      #10
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • C Crawl.W
                        19 Nov 2020, 07:31

                        You need to make sure that your main thread is idle when the signal is triggered.
                        Firstly, exclude qt lib version bugs.
                        Then, peel off serial port read and write code, and you should decouple code.
                        In general, for such questions can only provide experience and possibilities. The rest is still have to rely on yourself.

                        C Offline
                        C Offline
                        Crawl.W
                        wrote on 19 Nov 2020, 07:42 last edited by
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • I IRBaboon
                          19 Nov 2020, 07:40

                          This post is deleted!

                          C Offline
                          C Offline
                          Crawl.W
                          wrote on 19 Nov 2020, 09:15 last edited by
                          #12

                          You need solve it rather than evade it, especially when there is already a problem.

                          There is a Chinese idiom called 欲盖弥彰. But you can put the problem aside and solve it later.

                          1 Reply Last reply
                          0
                          • I Offline
                            I Offline
                            IRBaboon
                            wrote on 19 Nov 2020, 22:15 last edited by IRBaboon
                            #13

                            I have just tested a simple terminal with terminal 1.9b via com0com - it worked in both directions on my work, and....
                            It is working the same strange way on my personal PC! I can simply send bytes via my QT software and I cannot receive anything via it until I send a new parcel again.
                            So it is something on the PC...

                            C 1 Reply Last reply 24 Nov 2020, 06:51
                            0
                            • I IRBaboon
                              19 Nov 2020, 22:15

                              I have just tested a simple terminal with terminal 1.9b via com0com - it worked in both directions on my work, and....
                              It is working the same strange way on my personal PC! I can simply send bytes via my QT software and I cannot receive anything via it until I send a new parcel again.
                              So it is something on the PC...

                              C Offline
                              C Offline
                              Crawl.W
                              wrote on 24 Nov 2020, 06:51 last edited by
                              #14

                              @IRBaboon If your PC have no obvious lagging, my issue is an error direction. Here are some ideas you can try:

                              1. read help doc seriously or test one other poeple's credible demo on your devie, is it possible to call it incorrectly?(for serial device, It is difficult for others to run your demo)
                              2. try the lastest verion of QT
                              1 Reply Last reply
                              1

                              5/14

                              19 Nov 2020, 05:21

                              topic:navigator.unread, 9
                              • Login

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