Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. QextSerialPort missing data [solved]
QtWS25 Last Chance

QextSerialPort missing data [solved]

Scheduled Pinned Locked Moved 3rd Party Software
16 Posts 6 Posters 17.9k 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.
  • S Offline
    S Offline
    simonCpp
    wrote on last edited by
    #1

    Hi all,

    I'm using QextSerial port to read data from RS-232 at 400hz rate, most of the time I got currected data but sometimes I got invalid data (missing lines from the packet).

    I checked the device with realTerm and the data is currect so it's not a hardware bug.

    what can cose this missing line error? some suggestions?
    Thanks.

    More info:

    The algo:
    If (start recording)

    1. clear buffer
    2. read data and sync on the packet header
    3. check sum
    4. save data to files
      if (stop recording)
    5. read data (clear buffer)

    My setup
    QT 4.7
    QextSerialPort 1.2.0
    Win xp sp3
    using sea-level (rs-232 to usb)

    Open port function:

    Source code
    @
    this->setState(STOP_RECORDING);
    port = new QextSerialPort(portName,QextSerialPort::EventDriven);
    if(port->open(QIODevice::ReadWrite )) {
    connect( port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    }
    else {
    return -1;
    }

    port->setBaudRate(BAUD691200);
    port->setDataBits(DATA_8);
    port->setParity(PAR_NONE);
    port->setStopBits(STOP_2);
    port->setFlowControl(FLOW_OFF);
    port->setRts( true );
    port->setDtr( true );
    
    connect(&timer, SIGNAL(timeout()), this, SLOT(procTimerOut()));
    this->timer.setInterval(50);
    return 0;
    

    @

    Reading from port:
    @

    #define PACKET_SIZE 40

    void Driver::onReadyRead()
    {/* Read data from port */
    if (this->state() == STOP_RECORDING) {
    this->port->read(port->bytesAvailable());
    return;
    }

    if (this->rxBuffer.isEmpty()) {
        this->timer.start();
    }
    QByteArray data = this->port->read(port->bytesAvailable());
    this->rxBuffer.append(data);
    

    }
    void Driver::procTimerOut()
    {
    this->timer.stop();
    /* Print raw data to file */
    files_data.rawData.write(rxBuffer.toHex());
    if (!this->last_line.isEmpty()){
    rxBuffer.prepend(this->last_line);
    }
    if (rxBuffer.size() < PACKET_SIZE) {
    qDebug("buffer is small [%d]",rxBuffer.size());
    return;
    }
    if (this->sync(rxBuffer) != SUCCESS) {
    emit actionDone(EINVAL,"Cannot sync on packet");
    return;
    }

    while (rxBuffer.size() > PACKET_SIZE) {
        const QByteArray sample = rxBuffer.mid(0, PACKET_SIZE);
        rxBuffer.remove(0, PACKET_SIZE);
        if (this->addSample(sample) == INVALID_CHECKSUM)  {
                QString errMsg = this->portID + ": Invalid checksum at ["
                                 + QString::number(this->sampleCounter) + "]\n"
                                 + QString(sample.toHex());
                emit actionDone(INVALID_LINE,errMsg);
                rxBuffer.clear();
                return;
            }
        }
    }
    if (!rxBuffer.isEmpty()) {
        this->last_line = rxBuffer;   //read all data that left
        rxBuffer.clear();             //remove all data that left
    }
    else {
        this->last_line.clear();
    }
    

    }
    int Driver::sync(QByteArray &rxBuffer)
    {
    if (!rxBuffer.startsWith(this->key)){//Note: Sync on packet
    int prefix_offset = rxBuffer.indexOf(this->key);
    if (prefix_offset == -1){
    return EINVAL;
    }
    rxBuffer.remove(0,prefix_offset);
    if (!rxBuffer.startsWith(this->key)) {
    return EINVAL;
    }
    }
    return SUCCESS;
    }
    inline int Driver::addSample(const QByteArray & sample)
    {
    const struct packet *pkt;
    pkt = (const struct packet *)sample.constData();
    int checksum_bytes = sizeof(struct packet) - sizeof(pkt->checksum);
    u16 crc = checksum((const unsigned char *)pkt, checksum_bytes);
    if ( crc != pkt->checksum ) {
    return INVALID_CHECKSUM;
    }
    this->print_analyzed_sample(pkt);
    this->sampleCounter++;
    return SUCCESS;
    }
    }

    void Driver::startRecording()
    {
    this->prepareForRecord();
    this->setState(START_RECORDING);
    }
    void Driver::stopRecording()
    {
    this->setState(STOP_RECORDING);
    this->closeFiles();
    }

    void Driver::prepareForRecord()
    {
    this->genetate_output_Files(); //creat output files, and open to write data
    //reset data
    QByteArray buf;
    do {
    buf = port->readAll();
    } while (buf.size() > 0);
    this->rxBuffer.clear();
    }
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Hello,

      • Maybe you can give a try to QextSerialPort::Polling mode with a QTimer in order to see whether this issue still exists.

      • If you are using Qt SDK which does not contains a qwineventnotifier_p.h under the "include/QtCore/private" directory, QextWinEventNotifier will be used. If so, you can disable this by coping qwineventnofifier_p.h form src\corelib\kernel to that directory.

      Debao

      1 Reply Last reply
      0
      • S Offline
        S Offline
        simonCpp
        wrote on last edited by
        #3

        Hello Debao,
        Thanks for your replay.

        I tried to use the QextSerialPort::Polling mode with a QTimer before and it still miss data.

        About the qwineventnotifier_p.h file, I do have it at the “include/QtCore/private” directory.

        I got lack of understanding about what can cause this issue.
        Need help.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          simonCpp
          wrote on last edited by
          #4

          Need help anyone?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dbzhang800
            wrote on last edited by
            #5

            Hi,

            I have submitted a bug several day ago, but seems that others do not come with the similar problem.

            http://code.google.com/p/qextserialport/issues/detail?id=121

            So I do not how to do with this.

            However, I found a similar issue at stackoverflow which has been solved.

            http://stackoverflow.com/questions/9713656/qextserialport-drops-data-on-windows-what-can-i-do-about-it

            You can give a try to it.

            Debao

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Dantcho
              wrote on last edited by
              #6

              Hi all,

              want to use RS232 interface in QtCreator under windows at first,
              but i can not find a appropriate library.

              Do anybody have some information obout this?

              Thanks!

              1 Reply Last reply
              0
              • K Offline
                K Offline
                koahnig
                wrote on last edited by
                #7

                welcome to devnet

                There are at least two different Qt-based implementations available. There have been already a number of threads concerning the topic. One of the implementations or also both are mentioned in following threads with following tags:
                "QExtSerialPort":http://qt-project.org/search/tag/qextserialport
                "QSerialDevice":http://qt-project.org/search/tag/qserialdevice
                [edit]
                A good start might be "this overview":http://qt-project.org/forums/viewthread/16949

                Vote the answer(s) that helped you to solve your issue(s)

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Dantcho
                  wrote on last edited by
                  #8

                  Thanks koahing very much,

                  for the information, I knowed about "QExtSerialPort", but the QSerialDevice can be the right for my project.

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

                    2 Dantcho

                    bq. but the QSerialDevice can be the right for my project

                    Instead of QSerialDevice - use "QtSerialPort":http://qt-project.org/wiki/QtSerialPort.
                    QSerialDevice is no longer growing (develop is freezing). His code was used as the basis QtSerialPort. Now QtSerialPort is a child.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Dantcho
                      wrote on last edited by
                      #10

                      Hi all,

                      I have to work with serial port and need to to install it on my computer.
                      What i have to do to install it?

                      I download this:
                      "qtplayground-qtserialport"

                      from here:
                      http://qt-project.org/wiki/QtSerialPort

                      but I am a little confuse because the installing guide is for linux not for windows.
                      How to install qt serial port on windows?

                      Thanks!

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

                        What an embarrassment? Where does it say that only for Linux?

                        Read "it":http://qt-project.org/wiki/QtSerialPort#b55bbb687c599634cc785869b9167639 again

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          Dantcho
                          wrote on last edited by
                          #12

                          Hi everybody,

                          i develop a programm and i want my widget do not be moved by the mouse(press and drag), the widget must stay always on the same position.
                          How can i do this?

                          Thanks?

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            Dantcho
                            wrote on last edited by
                            #13

                            Hi everybody,

                            I createt tree windows with the QtDesigner and from windows one of them start the another windows,
                            from windows one I have connection to the another windows (include the header files), so I include the the header file from the windows one to the another windows to have connection from every window to the window one, but wenn I declare filetype from windows one I get the following error.
                            "Fehler:ISO C++ forbids declaration of 'Com_Net' with no type"

                            this is a C++ error, but I include the header files :-(((.

                            Wath cann I do to solve this problem.

                            Here is the header file from the another windows.

                            @#ifndef DICS_H
                            #define DICS_H

                            #include <QWidget>
                            #include <QSizePolicy>
                            #include <QMoveEvent>

                            #include "com_net.h" bq. here include the header files from the windows one
                            #include "ui_com_net.h"

                            namespace Ui {
                            class DICS;
                            }

                            class DICS : public QWidget
                            {
                            Q_OBJECT

                            public:
                            explicit DICS(QWidget *parent = 0);
                            ~DICS();

                            private slots:
                            void on_External_Button_clicked();
                            void on_Internal_Button_clicked();
                            void on_PABX_Button_clicked();
                            void on_PAS_Button_clicked();

                            private:
                            Ui::DICS *ui;
                            Com_Net *active_com_net; bq. and here is the pointer declaration from windows one.
                            virtual void moveEvent(QMoveEvent *event);
                            };

                            #endif // DICS_H@

                            Thanks very much, for the help.

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              Dantcho
                              wrote on last edited by
                              #14

                              Hallo everybody,

                              i solved this problem with the type visibility.

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mlong
                                wrote on last edited by
                                #15

                                Be sure and edit your original post title to add [Solved]. Thanks!

                                Software Engineer
                                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  Dantcho
                                  wrote on last edited by
                                  #16

                                  Dear community,

                                  I work with the "qextserialport-1.2beta2" and all work well, but I have one problem, I want to send in binary mode, ones I can set is "port->setTextModeEnabled(false);" but the serial port stil interpret the data "o" like a null terminator and so cut the string after the every "0".
                                  my question is it possible to send by "qextserialport" binary mode, or I have to look for a another way.

                                  thanks for the answer, :-))).

                                  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