Serial Port configuration in RHEL
-
How to configure serial port in Qt 5.7.0 version?
First of all I have installed Qt5.2.0 which was also not working so I downloaded the latest version thinking it might work but I am getting the same problem.
I am writing the same code which is there on web too but still not getting any solution. My code again and again showing Device not open while I am setting the port inside it.
Kindly help me out.
Is there anything to write inside version control or in kit option? -
Hi
As far as I know - you just use the class. ( in Qt5.7)
Please try the terminal sample and see if it will open port
http://doc.qt.io/qt-5/qtserialport-terminal-example.html
Its available to just open and run in creator.Do you have a real comport on the machine or are you using SERIAL over USB plug?
-
-
-
@Nimika said in Serial Port configuration in RHEL:
still can't open it.
Well did u try the Terminal sample and try it there?
Can it list and see your ports? -
@mrjj yeah its working but not showing any serial port which I have installed using my card.
This is my program and its output----#include <stdio.h> #include <QObject> #include <QtSerialPort/QSerialPort> #include <QSerialPortInfo> #include <string.h> #include <QTextStream> #include <QCoreApplication> #include <QStringList> #include <iostream> #include <QDebug> using namespace std; QT_USE_NAMESPACE int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // Example use QSerialPortInfo foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { qDebug() << "Name : " << info.portName(); qDebug() << "Description : " << info.description(); qDebug() << "Manufacturer: " << info.manufacturer(); // Example use QSerialPort QSerialPort serial; serial.setPortName("ttyM0"); qDebug() << "Name:" << serial.portName(); //serial.setPort(info); QIODevice::OpenMode mode = QIODevice::ReadOnly | QIODevice::Unbuffered; if(serial.open(mode)) qDebug() << "port connected"; if (serial.isOpen() && serial.isWritable()) { qDebug() << "Serial is open"; serial.close(); } return a.exec(); } }
output is:
Name : "ttyS0"
Description : ""
Manufacturer: ""
Name: "ttyM0"``
-
Hi and welcome to devnet,
Does your user have the rights to access that device ?
Call
ls -la /dev/ttyS0
to see who can access it.Your user is likely not in the group that can access the serial port. If that's indeed the case, add your user to that group and logout/login. You should then be able to access the device.
-
-
@Nimika That means that user root and group dialout have read/write access, nobody else have any access.
So you either start your app as root, or (much better) add the user you're using (hopefully not root) to the group dialout. -
NEVER EVER use root like that. All the more when developing. It's bad practice and doing so you're opening a gaping security hole.
Add your normal user to the
dialout
group and be done with it. -
QIODevice::OpenMode mode = QIODevice::ReadOnly | QIODevice::Unbuffered;
Did you read documentation? QIODevice::Unbuffered it is unsupported mode.
-
-
Please tell me how to add my normal user to the dialout group?
sudo usermod -a -G dialout theuser -
What is dialout group?
Its a predefined group found in many distros.
From old times it was used to allowed modems
to make connection etc. ( ie allow the user to connect to the internet :)
So often the system has this group and any user in it, have access to /dev/ttySX
-