Hi Friends
I have qtserial port library in my application. my application was previously wriiten in qt4.8.7 with qextserial library.
Now I did upgrade my application code from qextserial to qserial port library and qt 4.8.7 to qt 5.7.0
The problem that I faced here is
ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h, line 464
ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h, line 464
To copy to clipboard, switch view to plain text mode
So This code works without issue in previous version qt4.8.7 with qextserial port library
Now I got the error ASSERT : "unit(i) < unint(sisze())
Help me out to resolve this issue
My code is here
My serial port initialize function is here
void MainWindow::SerialPortInit()
{
DataAcquisitionPort = new QSerialPort();
DataAcquisitionPort->setPortName("/dev/ttyUSB0");
DataAcquisitionPort->setBaudRate(QSerialPort::Baud115200);
DataAcquisitionPort->setFlowControl(QSerialPort::NoFlowControl); // To set the flow control to none
DataAcquisitionPort->setDataBits(QSerialPort::Data8);
DataAcquisitionPort->setParity(QSerialPort::NoParity);
DataAcquisitionPort->setStopBits(QSerialPort::OneStop);
qDebug() << "PORT Initialize completed";
bool res
= DataAcquisitionPort
->open
(QIODevice::ReadWrite);
connect(DataAcquisitionPort, SIGNAL(readyRead()), this, SLOT(Get_Data_from_Serial_port()));
if(res)
{
qDebug() << "TRYING TO OPEN PORT";
const char data[] = "PROTOCOL PORT OPEN SUCCESS";
qDebug() << data;
DataAcquisitionPort->write(data, sizeof(data));
const char Protocol_init_data_1[] = { 0x80};
const char Protocol_init_data_2[] = { 0x04 };
const char Protocol_init_data_3[] = { 0x00 };
const char Protocol_init_data_4[] = { 0x80 };
const char Protocol_init_data_5[] = { 0x02 };
const char Protocol_init_data_6[] = { 0x00 };
DataAcquisitionPort->write(Protocol_init_data_1, sizeof(Protocol_init_data_1));
// Sleeper::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_2, sizeof(Protocol_init_data_2));
// Sleeper::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_3, sizeof(Protocol_init_data_3));
//Sleeper::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_4, sizeof(Protocol_init_data_4));
//Sleeper::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_5, sizeof(Protocol_init_data_5));
//Sleeper::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_6, sizeof(Protocol_init_data_6));
qDebug() << "PROTOCOL OPEN SUCCESS";
}
else
{
qDebug("PROTOCOL PORT OPEN FAILED");
}
}
void MainWindow::SerialPortInit()
{
DataAcquisitionPort = new QSerialPort();
DataAcquisitionPort->setPortName("/dev/ttyUSB0");
DataAcquisitionPort->setBaudRate(QSerialPort::Baud115200);
DataAcquisitionPort->setFlowControl(QSerialPort::NoFlowControl); // To set the flow control to none
DataAcquisitionPort->setDataBits(QSerialPort::Data8);
DataAcquisitionPort->setParity(QSerialPort::NoParity);
DataAcquisitionPort->setStopBits(QSerialPort::OneStop);
qDebug() << "PORT Initialize completed";
bool res = DataAcquisitionPort->open(QIODevice::ReadWrite);
connect(DataAcquisitionPort, SIGNAL(readyRead()), this, SLOT(Get_Data_from_Serial_port()));
if(res)
{
qDebug() << "TRYING TO OPEN PORT";
const char data[] = "PROTOCOL PORT OPEN SUCCESS";
qDebug() << data;
DataAcquisitionPort->write(data, sizeof(data));
const char Protocol_init_data_1[] = { 0x80};
const char Protocol_init_data_2[] = { 0x04 };
const char Protocol_init_data_3[] = { 0x00 };
const char Protocol_init_data_4[] = { 0x80 };
const char Protocol_init_data_5[] = { 0x02 };
const char Protocol_init_data_6[] = { 0x00 };
DataAcquisitionPort->write(Protocol_init_data_1, sizeof(Protocol_init_data_1));
// Sleeper::msleep(100);
QThread::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_2, sizeof(Protocol_init_data_2));
// Sleeper::msleep(100);
QThread::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_3, sizeof(Protocol_init_data_3));
//Sleeper::msleep(100);
QThread::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_4, sizeof(Protocol_init_data_4));
//Sleeper::msleep(100);
QThread::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_5, sizeof(Protocol_init_data_5));
//Sleeper::msleep(100);
QThread::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_6, sizeof(Protocol_init_data_6));
qDebug() << "PROTOCOL OPEN SUCCESS";
}
else
{
qDebug("PROTOCOL PORT OPEN FAILED");
}
}
To copy to clipboard, switch view to plain text mode
And this function for check whether the valid data arrived or not
void MainWindow::Get_Data_from_Serial_port()
{
Protocol_Raw_Data = DataAcquisitionPort->readAll().toHex(); // Get the data and convert it to Hex fornat
qDebug() << Protocol_Raw_Data;
if((Protocol_Raw_Data.startsWith("02")) && (Protocol_Raw_Data.endsWith("03"))) // To check for the Complete Frame
{
P1.append(Protocol_Raw_Data);
Protocol_Data_Organize(P1);
P1.clear();
}
else
{
P1.append(Protocol_Raw_Data); // If the frame is not completed, then append the data to Pi array
}
}
void MainWindow::Get_Data_from_Serial_port()
{
QByteArray Protocol_Raw_Data;
Protocol_Raw_Data = DataAcquisitionPort->readAll().toHex(); // Get the data and convert it to Hex fornat
qDebug() << Protocol_Raw_Data;
if((Protocol_Raw_Data.startsWith("02")) && (Protocol_Raw_Data.endsWith("03"))) // To check for the Complete Frame
{
P1.append(Protocol_Raw_Data);
Protocol_Data_Organize(P1);
P1.clear();
}
else
{
P1.append(Protocol_Raw_Data); // If the frame is not completed, then append the data to Pi array
}
}
To copy to clipboard, switch view to plain text mode
And his function for organize the raw data and separate the raw into a single frame
void MainWindow
::Protocol_Data_Organize(QByteArray Data
) {
QList <QByteArray> Data_Frame;
for(int pos = 0; pos < Data.size(); pos++)
{
if( (Data.at(pos-1) == '0' && Data.at(pos) == '3' && Data.at(pos+1) == '0' && Data.at(pos+2) == '2') || ((Data.at(pos) == '3') && pos == (Data.size()-1)) )
{
Data.insert((pos+1), ';'); // Inserting a Splitter between the individual data frames
}
}
Data_Frame << Data.split(';'); // Splits the Whole data frame into separate individual data frame and stores it in the List
Protocol_Data_split(Data_Frame);
}
void MainWindow::Protocol_Data_Organize(QByteArray Data)
{
QList <QByteArray> Data_Frame;
for(int pos = 0; pos < Data.size(); pos++)
{
if( (Data.at(pos-1) == '0' && Data.at(pos) == '3' && Data.at(pos+1) == '0' && Data.at(pos+2) == '2') || ((Data.at(pos) == '3') && pos == (Data.size()-1)) )
{
Data.insert((pos+1), ';'); // Inserting a Splitter between the individual data frames
}
}
Data_Frame << Data.split(';'); // Splits the Whole data frame into separate individual data frame and stores it in the List
Protocol_Data_split(Data_Frame);
}
To copy to clipboard, switch view to plain text mode
My application code Build and compiled successfully but when i run the code application closed unexpectedly
ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h, line 464
The program has unexpectedly finished.
ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h, line 464
The program has unexpectedly finished.
To copy to clipboard, switch view to plain text mode
Bookmarks