Hi frnds i am new to qt and trying to read data from serial port in qt on rhel linux . The incomming data is 15 byte data and sent at every 1s from the sender device. When i am reading this data i get 7 byets some times 4bytes and so. But i should get the 15byte data.
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qextserialport.h"
#include <QTimer>
#include <QtNetwork>
char databuff[1024];
QextSerialPort *port;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
port = new QextSerialPort("ttyS0", QextSerialPort::EventDriven);
port->open(QIODevice::ReadWrite);
port->setBaudRate(BAUD9600);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
port->setQueryMode(QextSerialPort::EventDriven);
connect(port, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));
// QTimer *timer = new QTimer(this);
//connect(timer, SIGNAL(timeout()), this, SLOT(onDataAvailable()));
//timer->start(200);
}
void MainWindow::onDataAvailable()
{
port->read(databuff,15);
ui->lineEdit->setText(databuff);
}
i have also used timer but same problem persists. Pls suggest how to solve this problem. Thanking u all in advance
↧