Embedded_linux [SOLVED]: Why the Qt(4.8) serial port(qextserialport) readind data from device in 2 part?

Embedded_linux [SOLVED]: Why the Qt(4.8) serial port(qextserialport) readind data from device in 2 part?

Home Forums Embedded Linux Embedded_linux [SOLVED]: Why the Qt(4.8) serial port(qextserialport) readind data from device in 2 part?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #4332

    Anonymous

    QuestionQuestion

    this is my code : (I used qextserialport)

    SerialPort::SerialPort(QString port)
    {
        sp=new QextSerialPort;
        sp->setPortName(port);
        /*port->setBaudRate(BAUD9600);
        port->setFlowControl(FLOW_OFF);
        port->setParity(PAR_NONE);
        port->setDataBits(DATA_8);
        port->setStopBits(STOP_2);*/
        sp->setBaudRate(BAUD115200);
        sp->setDataBits(DATA_8);
        sp->setFlowControl(FLOW_OFF);
        sp->setParity(PAR_NONE);
        sp->setStopBits(STOP_1);
        sp->open(QIODevice::ReadWrite);
        connect(sp,SIGNAL(readyRead()),this,SLOT(ReadData()));
    
    }
    
    void SerialPort::ReadData()
    {
        QByteArray ba;
        ba.resize(512);
        ba=sp->readAll();
        emit DataRecieve(ba);
    }
    

    this code run on Ubuntu at first and show all the bytes which receive from device, but when I tested it in linux embedded device this code read data from serial device in 2 part. () there is no n in my bytes.
    I change the code to this code :

    void SerialPort::ReadData()
    {
        QByteArray ba;
        ba.resize(512);
        if(sp->bytesAvailable()>0 || sp->waitForReadyRead(20000))
        {
        qDebug()<<sp->bytesAvailable();
        ba=sp->readAll();
        qDebug()<<ba.toHex();
        emit DataRecieve(ba);
        }
    }
    

    but again my output is :

    4 "aa5524010400000000000000"   
    12 "000000000000000000002801"
    

    but it should be :

    "aa5524010400000000000000000000000000000000002801"
    

    My output size is maybe 48 bytes or 512 bytes

    #4333

    Anonymous

    Accepted AnswerAnswer

    It depends on serial port driver buffer. You can got readyRead() signal on one ready byte, for example.
    You should save received bytes to intermediate buffer and process it after all.

    Source: http://stackoverflow.com/questions/41543578/why-the-qt4-8-serial-portqextserialport-readind-data-from-device-in-2-part
    Author: Edward
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.