Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved] Need help in QSerial Port in Qt5.1
Forum Updated to NodeBB v4.3 + New Features

[Solved] Need help in QSerial Port in Qt5.1

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 2 Posters 3.6k 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.
  • S Offline
    S Offline
    shajeen
    wrote on last edited by
    #1

    Hello I am Beginner in QT,
    Now I am using QSerial port for uart communication, to read the data which send from Hardware. I used below code for reading data.

    @rs232_ = new QSerialPort(this);
    rs232_->setPortName("/dev/ttyS0");
    rs232_->open(QIODevice::ReadOnly);
    rs232_->setBaudRate(2400,QSerialPort::AllDirections);
    rs232_->setDataBits(QSerialPort::Data8);
    rs232_->setStopBits(QSerialPort::OneStop);
    rs232_->setParity(QSerialPort::OddParity);
    rs232_->setFlowControl(QSerialPort::NoFlowControl);
    if(!rs232_->isOpen())
    {
    qDebug()<<"...Port ttyS0 Cannot Open..."<<endl;
    rs232_->flush();
    }
    connect(rs232_, SIGNAL(readyRead()), this, SLOT(process()));@

    @void MainWindow::process()
    {
    QByteArray lineLength = rs232_->readAll();
    QString temp = lineLength.toHex();
    qDebug()<<temp.size()<<endl;
    condata(temp); //binary conversion
    }@

    Problem is while reading it misses some data, and add ZERO 's in output
    Like this,
    fe 85 a 0 0 0 2b 96 0 5 2 0 0 0

    And the recived packages are in wrong order.
    for eg:
    order shoud be , first byte : 7 bit Must be 1 (10000000), then following bytes 2,3,4,5 will be read and displayed.
    what happens is,
    7 bit is readed as 1 and following bytes order are changed randomly.

    the size of data recives are not constant
    like this,
    Size 5
    Size 2
    Size 2
    Size 2
    Size 4
    Size 2
    Size 2
    Size 2
    For resolving this problem i used read(); readline(); readlinedata();but result was same.

    Also Tried in
    QExt serial port,
    Serial Port,
    And C Program for serail port.
    *
    Protocol Detail:*
    1StartBit+8Data Bit+1StopBit / 4800BAUD RATE/ ODD Parity
    5bytes in single package, 60 packages for 1 sec.

    Working on:
    Ubuntu 12.04, 32-bit,
    Qt 5.1

    is there any solution for this?__

    Shajeen Ahamed

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you also set the start bit ?

      You should store everything you received and once you have enough data parse it. readyRead will be emitted frequently but not at the same pace as the protocol. Don't forget to discard the first byte you received until you have a package start byte.

      Hope it helps

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

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

        ╋┏┓┏┓╋╋╋╋╋╋╋┏┓╋╋╋╋╋┏━━━┳━━━┓╋╋╋╋╋╋┏┓
        ┏┛┗┫┃╋╋╋╋╋╋╋┃┃╋╋╋╋╋┃┏━┓┃┏━┓┃╋╋╋╋╋┏┛┗┓
        ┗┓┏┫┗━┳━━┳━┓┃┃┏┳━━┓┃┗━━┫┃╋┗╋━━┳┳━┻┓┏┛
        ╋┃┃┃┏┓┃┏┓┃┏┓┫┗┛┫━━┫┗━━┓┃┃┏━┫┏┓┣┫━━┫┃
        ╋┃┗┫┃┃┃┏┓┃┃┃┃┏┓╋━━┃┃┗━┛┃┗┻━┃┏┓┃┣━━┃┗┓
        ╋┗━┻┛┗┻┛┗┻┛┗┻┛┗┻━━┛┗━━━┻━━━┻┛┗┻┻━━┻━┛

        .

        Shajeen Ahamed

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What are you trying to show me ?

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            shajeen
            wrote on last edited by
            #5

            Nothing

            Just a thank for Reply

            Shajeen Ahamed

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Ho ok :)

              You're welcome !

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

              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