[Solved] Need help in QSerial Port in Qt5.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);
    qDebug()<<"...Port ttyS0 Cannot Open..."<<endl;
    connect(rs232_, SIGNAL(readyRead()), this, SLOT(process()));@

    @void MainWindow::process()
    QByteArray lineLength = rs232_->readAll();
    QString temp = lineLength.toHex();
    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?__

  • Lifetime Qt Champion


    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

  • ╋┏┓┏┓╋╋╋╋╋╋╋┏┓╋╋╋╋╋┏━━━┳━━━┓╋╋╋╋╋╋┏┓


  • Lifetime Qt Champion

    What are you trying to show me ?

  • Nothing

    Just a thank for Reply

  • Lifetime Qt Champion

    Ho ok :)

    You're welcome !

Log in to reply

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