[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);
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 0And 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.1is there any solution for this?__
-
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
-
╋┏┓┏┓╋╋╋╋╋╋╋┏┓╋╋╋╋╋┏━━━┳━━━┓╋╋╋╋╋╋┏┓
┏┛┗┫┃╋╋╋╋╋╋╋┃┃╋╋╋╋╋┃┏━┓┃┏━┓┃╋╋╋╋╋┏┛┗┓
┗┓┏┫┗━┳━━┳━┓┃┃┏┳━━┓┃┗━━┫┃╋┗╋━━┳┳━┻┓┏┛
╋┃┃┃┏┓┃┏┓┃┏┓┫┗┛┫━━┫┗━━┓┃┃┏━┫┏┓┣┫━━┫┃
╋┃┗┫┃┃┃┏┓┃┃┃┃┏┓╋━━┃┃┗━┛┃┗┻━┃┏┓┃┣━━┃┗┓
╋┗━┻┛┗┻┛┗┻┛┗┻┛┗┻━━┛┗━━━┻━━━┻┛┗┻┻━━┻━┛.
-
What are you trying to show me ?
-
Nothing
Just a thank for Reply
-
Ho ok :)
You're welcome !