QextSerialPort missing data [solved]



  • 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();
    }
    @



  • 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



  • 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.



  • Need help anyone?



  • 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



  • 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!


  • Moderators

    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



  • Thanks koahing very much,

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



  • 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.



  • 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!



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

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



  • 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?



  • 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.



  • Hallo everybody,

    i solved this problem with the type visibility.


  • Moderators

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



  • 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, :-))).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.