qextserial port in qt5.7.0
-
hi@aha_1980 Yes indeed qtserial is already exists in qt5
But here I face an issue while calling the QSerial Header files with QT Creator Editor . My QT creator Doesn't includes the QSerial Header files
so that's why I did install qtserial port library manually. but now i got the header files in qt creator Editor with installing this command in terminal
$ sudo apt-get install libqt5serialport5-devis that ok correct me if i am wrong
Thanks & Regards
vivekyuvan -
hi@aha_1980 Yes indeed qtserial is already exists in qt5
But here I face an issue while calling the QSerial Header files with QT Creator Editor . My QT creator Doesn't includes the QSerial Header files
so that's why I did install qtserial port library manually. but now i got the header files in qt creator Editor with installing this command in terminal
$ sudo apt-get install libqt5serialport5-devis that ok correct me if i am wrong
Thanks & Regards
vivekyuvan$ sudo apt-get install libqt5serialport5-dev
that looks good, and should work.
Afterwards, you need to add
QT += serialport
in your.pro
file, as stated in the documentation -
@aha_1980 Thanks Now i am going to build my application hope it will build successfully.
-
$ sudo apt-get install libqt5serialport5-dev
that looks good, and should work.
Afterwards, you need to add
QT += serialport
in your.pro
file, as stated in the documentation@aha_1980 My code build and compiled successfully but my com port /dev/ttyUSB0 open was unsuccessful
Here is code snippet
void MainWindow::SerialPortInit() { DataAcquisitionPort = new QserialPort(); DataAcquisitionPort->setPortName("/dev/ttyUSB0"); DataAcquisitionPort->setBaudRate(QSerialPort::Baud115200); DataAcquisitionPort->setFlowControl(QSerialPort::NoFlowControl); DataAcquisitionPort->setDataBits(QSerialPort::Data8); DataAcquisitionPort->setParity(QSerialPort::NoParity); DataAcquisitionPort->setStopBits(QSerialPort::OneStop); qDebug() << "PORT Initialize completed"; bool res = false; res = DataAcquisitionPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered | QIODevice::Append | QIODevice::Text); connect(DataAcquisitionPort, SIGNAL(readyRead()), this, SLOT(Get_Data_from_Serial_port())); if(res) { qDebug() << "TRYING TO OPEN PORT" } else { qDebug("PROTOCOL PORT OPEN FAILED"); } }
this code cant open my port it always "protocol port open failed "
Help me out to resolve this issue
Thanks
-
@aha_1980 My code build and compiled successfully but my com port /dev/ttyUSB0 open was unsuccessful
Here is code snippet
void MainWindow::SerialPortInit() { DataAcquisitionPort = new QserialPort(); DataAcquisitionPort->setPortName("/dev/ttyUSB0"); DataAcquisitionPort->setBaudRate(QSerialPort::Baud115200); DataAcquisitionPort->setFlowControl(QSerialPort::NoFlowControl); DataAcquisitionPort->setDataBits(QSerialPort::Data8); DataAcquisitionPort->setParity(QSerialPort::NoParity); DataAcquisitionPort->setStopBits(QSerialPort::OneStop); qDebug() << "PORT Initialize completed"; bool res = false; res = DataAcquisitionPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered | QIODevice::Append | QIODevice::Text); connect(DataAcquisitionPort, SIGNAL(readyRead()), this, SLOT(Get_Data_from_Serial_port())); if(res) { qDebug() << "TRYING TO OPEN PORT" } else { qDebug("PROTOCOL PORT OPEN FAILED"); } }
this code cant open my port it always "protocol port open failed "
Help me out to resolve this issue
Thanks
@vivekyuvan said in qextserial port in qt5.7.0:
Hi, your code looks good so far, however this line:
bool res = false;
res = DataAcquisitionPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered | QIODevice::Append | QIODevice::Text);should be simplified to:
bool res = DataAcquisitionPort->open(QIODevice::ReadWrite);
I think open fails because you don't have the needed access rights.
Please send the output of
ls -l /dev/ttyUSB0
to verify.Usually the solution is to add your username to the group
dialout
Regards.
PS: It does not hurt to write "Please help me to solve this issue" ;)
-
@aha_1980 I have changed the line as like your simplified line. and again i got same error
vivek@vivek-Veriton-Series:~$ ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 Jul 28 13:25 /dev/ttyUSB0I have verified ttyUSB0 in terminal its looking fine
and i didn't understand the line " Usually the solution is to add your username to the group dialout
"
can you please show me how to add username to group dialout ?
-
@aha_1980 I have changed the line as like your simplified line. and again i got same error
vivek@vivek-Veriton-Series:~$ ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 Jul 28 13:25 /dev/ttyUSB0I have verified ttyUSB0 in terminal its looking fine
and i didn't understand the line " Usually the solution is to add your username to the group dialout
"
can you please show me how to add username to group dialout ?
Usually the solution is to add your username to the group dialout
In the terminal, input the following command:
sudo adduser vivek dialout
After that log out and in again or reboot the computer. Then it should work.
Regards
-
hi@aha_1980 thanks for reply. I have an another issue in my code that is " I can't get UART RAW data continuously " My code compiled successfully and when I run application it throws an error
ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h, line 464 The program has unexpectedly finished.
Serial port Initialize function
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 = false; // res = DataAcquisitionPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered | QIODevice::Append | QIODevice::Text); // To open the DataAcquisitionPort 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"); } }
this function for protocol raw data frame
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 } }
And this function for split the raw data and separate the into 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); }
In my previous version QT4.8.7 with qextserial library my application runs without issue but here i am facing this issue "The program has unexpectedly finished." and i cant get continuous UART Data . I don know what am missing please help me to resolve this issue
Thanks and Regard
vivekyuvan -
hi@aha_1980 thanks for reply. I have an another issue in my code that is " I can't get UART RAW data continuously " My code compiled successfully and when I run application it throws an error
ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h, line 464 The program has unexpectedly finished.
Serial port Initialize function
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 = false; // res = DataAcquisitionPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered | QIODevice::Append | QIODevice::Text); // To open the DataAcquisitionPort 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"); } }
this function for protocol raw data frame
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 } }
And this function for split the raw data and separate the into 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); }
In my previous version QT4.8.7 with qextserial library my application runs without issue but here i am facing this issue "The program has unexpectedly finished." and i cant get continuous UART Data . I don know what am missing please help me to resolve this issue
Thanks and Regard
vivekyuvanHi @vivekyuvan said in qextserial port in qt5.7.0:
"The program has unexpectedly finished."
A typical case for using the debugger. Start a debugging session, on the crash you get a stack trace. Then inspect the different functions in the stack trace until you find the guilty one.
if( (Data.at(pos-1) == '0'
This already looks like a candidate when pos == 0.
-
Another thing I noticed: You are using signals&slots together with sleeping functions.
That is wrong - stop doing it, you putting yourself into trouble.