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. Qextserialport not reading data fully

Qextserialport not reading data fully

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.2k 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.
  • C Offline
    C Offline
    chandradeo
    wrote on 6 Dec 2013, 07:18 last edited by
    #1

    Hi frnds i am new to qt and trying to read data from serial port in qt on rhel linux . The incomming data is 15 byte data and sent at every 1s from the sender device. When i am reading this data i get 7 byets some times 4bytes and so. But i should get the 15byte data.

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "qextserialport.h"
    #include <QTimer>
    #include <QtNetwork>

    char databuff[1024];
    QextSerialPort *port;
    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
    {

    ui->setupUi(this);
    port = new QextSerialPort("ttyS0", QextSerialPort::EventDriven);
    port->open(QIODevice::ReadWrite);
    port->setBaudRate(BAUD9600);
    port->setFlowControl(FLOW_OFF);
    port->setParity(PAR_NONE);
    port->setDataBits(DATA_8);
    port->setStopBits(STOP_1);
    port->setQueryMode(QextSerialPort::EventDriven);
    connect(port, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));

    // QTimer *timer = new QTimer(this);
    //connect(timer, SIGNAL(timeout()), this, SLOT(onDataAvailable()));
    //timer->start(200);
    }

    void MainWindow::onDataAvailable()
    {
    port->read(databuff,15);
    ui->lineEdit->setText(databuff);
    }@

    i have also used timer but same problem persists. Pls suggest how to solve this problem. Thanking u all in advance

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 6 Dec 2013, 07:54 last edited by
      #2

      the readyRead() signal should be emitted multiple times whenever new data is available.
      So in your onDataAvailable() slot jsut append the read data. It's not guaranteed that every time readyRead() is emitted all data is available.

      btw. in Qt5 there is already a serial port module available.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chandradeo
        wrote on 6 Dec 2013, 09:02 last edited by
        #3

        hi worx can u please explain a little bit more the line " So in your onDataAvailable() slot jsut append the read data". What exactly i have to do please explain.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chandradeo
          wrote on 6 Dec 2013, 09:02 last edited by
          #4

          [quote author="raven-worx" date="1386316484"]the readyRead() signal should be emitted multiple times whenever new data is available.
          So in your onDataAvailable() slot jsut append the read data. It's not guaranteed that every time readyRead() is emitted all data is available.

          btw. in Qt5 there is already a serial port module available.[/quote]

          hi worx can u please explain a little bit more the line “ So in your onDataAvailable() slot jsut append the read data”. What exactly i have to do please explain.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 6 Dec 2013, 09:03 last edited by
            #5

            something like this:
            @
            ui->lineEdit->setText( ui->lineEdit->text().append(databuff) );
            @
            Should result in the full data you expect at the end once all the 15byte data has been sent.

            Or this:
            @
            void MainWindow::onDataAvailable()
            {
            if( port->bytesAvailable() >= 15 )
            {
            port->read(databuff,15);
            ui->lineEdit->setText(databuff);
            }
            }
            @
            To ensure you read the data in 15-byte-steps only

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • C Offline
              C Offline
              chandradeo
              wrote on 6 Dec 2013, 10:49 last edited by
              #6

              [quote author="raven-worx" date="1386320632"]something like this:
              @
              ui->lineEdit->setText( ui->lineEdit->text().append(databuff) );
              @
              Should result in the full data you expect at the end once all the 15byte data has been sent.

              Or this:
              @

              Hi worx
              void MainWindow::onDataAvailable()
              {
              if( port->bytesAvailable() >= 15 )
              {
              port->read(databuff,15);
              ui->lineEdit->setText(databuff);
              }
              }
              @
              To ensure you read the data in 15-byte-steps only[/quote]

              Hi worx than u very much for ur reply . Now i am getting the correct data
              which is better than earlier.

              1 Reply Last reply
              0

              1/6

              6 Dec 2013, 07:18

              • Login

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