I've done some tests and I can say that readAll() hangs the application (reading never ends), size is always 0, bytes available behave strange... some examples:
First version of function is reading a fixed number of bytes. First in output is "bytes avalible: 0" then application takes a long break and print the rest (like it was waiting to receive 16k bytes, and then start reading)
void MainWindow::readyRead(){
qDebug() <<"bytes avalible: "<< in->bytesAvailable();
buf.append(in->read(50));
while (buf.size() >= 50){
qDebug() << buf.left(50).toHex() ;
buf = buf.mid(50);
}
}
void MainWindow::readyRead(){
static QByteArray buf;
qDebug() <<"bytes avalible: "<< in->bytesAvailable();
buf.append(in->read(50));
while (buf.size() >= 50){
qDebug() << buf.left(50).toHex() ;
buf = buf.mid(50);
}
}
To copy to clipboard, switch view to plain text mode
output
bytes avalible: 0
// LONG BREAK
"01000000000083797c790000000000000000000000000000000000000003ef160000000033fd7701de1e02f8019201ed0101"
bytes avalible: 16334
"000000000083797c790000000000000000000000000000000000000003ef160000000033fd7701de1e02f8019201ec010100"
bytes avalible: 16284
"0000000083797c790000000000000000000000000000000000000003ef160000000033fd7701de1e02f8019201ed01010000"
bytes avalible: 0
// LONG BREAK
"01000000000083797c790000000000000000000000000000000000000003ef160000000033fd7701de1e02f8019201ed0101"
bytes avalible: 16334
"000000000083797c790000000000000000000000000000000000000003ef160000000033fd7701de1e02f8019201ec010100"
bytes avalible: 16284
"0000000083797c790000000000000000000000000000000000000003ef160000000033fd7701de1e02f8019201ed01010000"
To copy to clipboard, switch view to plain text mode
After that I tried to use bytesAvailable() to read all bytes in buffer at once. The result was surprising. bytesAvalible started to return only 0 value
void MainWindow::readyRead(){
qDebug() <<"bytes avalible: "<< in->bytesAvailable();
buf.append(in->read(in->bytesAvailable()));
while (buf.size() >= 50){
qDebug() << buf.left(50).toHex() ;
buf = buf.mid(50);
}
}
void MainWindow::readyRead(){
static QByteArray buf;
qDebug() <<"bytes avalible: "<< in->bytesAvailable();
buf.append(in->read(in->bytesAvailable()));
while (buf.size() >= 50){
qDebug() << buf.left(50).toHex() ;
buf = buf.mid(50);
}
}
To copy to clipboard, switch view to plain text mode
output
bytes avalible: 0
bytes avalible: 0
bytes avalible: 0
(...)
bytes avalible: 0
bytes avalible: 0
bytes avalible: 0
(...)
To copy to clipboard, switch view to plain text mode
Changing read() to readAll() results in application hang.
void MainWindow::readyRead(){
qDebug() <<"bytes avalible: "<< in->bytesAvailable();
buf.append(in->readAll());
while (buf.size() >= 50){
qDebug() << buf.left(50).toHex() ;
buf = buf.mid(50);
}
}
void MainWindow::readyRead(){
static QByteArray buf;
qDebug() <<"bytes avalible: "<< in->bytesAvailable();
buf.append(in->readAll());
while (buf.size() >= 50){
qDebug() << buf.left(50).toHex() ;
buf = buf.mid(50);
}
}
To copy to clipboard, switch view to plain text mode
output
bytes avalible: 0
bytes avalible: 0
To copy to clipboard, switch view to plain text mode
The best way to read from this device seems to by reading a fixed number of bytes and then process it, but I can't wait for 16k blocks!
Bookmarks