Read Serial Data In QByteArray
-
every Time Serial Triggered Receive This Message 000011110000111100001111& but i receive it Like that in debug
when i Do qDebug() << inBuffer ; out side of ReadyRead(); i got only Last byte "&"
so how to got all Message in QByte array like that "000011110000111100001111&"
My code :void Widget::updateReceivedData() { inBuffer = arduino->readAll(); qDebug() << inBuffer ; //inBuffer = arduino->readLine(); //QByteArray datalog(arduino->readAll()); //QByteArray data ; // data.append(arduino->readAll()); //while (arduino->waitForReadyRead(10)) //inBuffer += arduino->readAll(); }
-
every Time Serial Triggered Receive This Message 000011110000111100001111& but i receive it Like that in debug
when i Do qDebug() << inBuffer ; out side of ReadyRead(); i got only Last byte "&"
so how to got all Message in QByte array like that "000011110000111100001111&"
My code :void Widget::updateReceivedData() { inBuffer = arduino->readAll(); qDebug() << inBuffer ; //inBuffer = arduino->readLine(); //QByteArray datalog(arduino->readAll()); //QByteArray data ; // data.append(arduino->readAll()); //while (arduino->waitForReadyRead(10)) //inBuffer += arduino->readAll(); }
@Marco-Flad your serial data arrives in chunks of one or several bytes, but seldom the whole answer in one block.
So you have to append the new data to your existing buffer until all data is received.
Regards
-
Hi,
Are you receiving null chars in your message ?
-
use readyRead() SIGNAL at the time of serial->open(QIODevice::ReadWrite)
connect(serial, SIGNAL(readyRead()),this,SLOT(readSerialData()),Qt::UniqueConnection);
where serial is an object QSerialPort *serial;
readSerialData() is user defined slot function make it in header file like
private slots:
void readSerialData();
and finally in readSerialData() function
static QString readResponseReply = "";
readResponseReply.append(serial->readAll());
qDebug()<<"readResponseReply";
try it in your source code -
use readyRead() SIGNAL at the time of serial->open(QIODevice::ReadWrite)
connect(serial, SIGNAL(readyRead()),this,SLOT(readSerialData()),Qt::UniqueConnection);
where serial is an object QSerialPort *serial;
readSerialData() is user defined slot function make it in header file like
private slots:
void readSerialData();
and finally in readSerialData() function
static QString readResponseReply = "";
readResponseReply.append(serial->readAll());
qDebug()<<"readResponseReply";
try it in your source code@vikas-dhumal Sorry but converting some binary data into a QString is completely wrong here. What @SGaist asked is correct - when there is a null byte in there, qDebug() will not print what you expect. Therefore I would use inBuffer.toHex() to output the data for debugging.
-
every Time Serial Triggered Receive This Message 000011110000111100001111& but i receive it Like that in debug
when i Do qDebug() << inBuffer ; out side of ReadyRead(); i got only Last byte "&"
so how to got all Message in QByte array like that "000011110000111100001111&"
My code :void Widget::updateReceivedData() { inBuffer = arduino->readAll(); qDebug() << inBuffer ; //inBuffer = arduino->readLine(); //QByteArray datalog(arduino->readAll()); //QByteArray data ; // data.append(arduino->readAll()); //while (arduino->waitForReadyRead(10)) //inBuffer += arduino->readAll(); }
@Marco-Flad your serial data arrives in chunks of one or several bytes, but seldom the whole answer in one block.
So you have to append the new data to your existing buffer until all data is received.
Regards
-
ok so instead of QString read it in QByteArray