Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Serial Port configuration in RHEL
Forum Updated to NodeBB v4.3 + New Features

Serial Port configuration in RHEL

Scheduled Pinned Locked Moved Unsolved General and Desktop
40 Posts 6 Posters 15.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mrjjM mrjj

    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?

    N Offline
    N Offline
    Nimika
    wrote on last edited by
    #3

    @mrjj Hey!
    I am using a card having many RS 422 of my own to use COM ports. But I can't even open the system ports.
    Is something there to configure system inside qt or while installing it?
    Is there anything to write in git ? version control?

    mrjjM 1 Reply Last reply
    0
    • N Nimika

      @mrjj Hey!
      I am using a card having many RS 422 of my own to use COM ports. But I can't even open the system ports.
      Is something there to configure system inside qt or while installing it?
      Is there anything to write in git ? version control?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @Nimika
      Hi.
      ok. With 5.7 it should just work if you have
      QT += serialport in .pro file.

      -Is there anything to write inside version control or in kit option?
      No. Its just a c++ class.

      Did you try the terminal sample?

      N 1 Reply Last reply
      1
      • mrjjM mrjj

        @Nimika
        Hi.
        ok. With 5.7 it should just work if you have
        QT += serialport in .pro file.

        -Is there anything to write inside version control or in kit option?
        No. Its just a c++ class.

        Did you try the terminal sample?

        N Offline
        N Offline
        Nimika
        wrote on last edited by
        #5

        @mrjj
        Hello
        Thanks for reply.
        I have added it in my pro file but still can't open it.

        mrjjM 1 Reply Last reply
        0
        • N Nimika

          @mrjj
          Hello
          Thanks for reply.
          I have added it in my pro file but still can't open it.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #6

          @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?

          N 1 Reply Last reply
          1
          • mrjjM mrjj

            @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?

            N Offline
            N Offline
            Nimika
            wrote on last edited by
            #7

            @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"

            ``

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • N Offline
                N Offline
                Nimika
                wrote on last edited by
                #9

                how will I get to know wo is accessing that device?
                how can I add the user to the group which you have specified.

                jsulmJ 1 Reply Last reply
                0
                • N Nimika

                  how will I get to know wo is accessing that device?
                  how can I add the user to the group which you have specified.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  @Nimika The user using your application needs access right for /dev/ttyS0.
                  If you execute the command @SGaist provided you you will see who has access. Check which group is set for that device. Then add yourself to this group (see /etc/group file).

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  N 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @Nimika The user using your application needs access right for /dev/ttyS0.
                    If you execute the command @SGaist provided you you will see who has access. Check which group is set for that device. Then add yourself to this group (see /etc/group file).

                    N Offline
                    N Offline
                    Nimika
                    wrote on last edited by
                    #11

                    @jsulm Hey thanks!
                    I am getting this after writing the calling function ls -la /dev/ttyS0:
                    crw-rw----. 1 root dialout 4, 64 Oct 7 10:35 /dev/ttyS0

                    What does it mean?

                    jsulmJ 1 Reply Last reply
                    0
                    • N Nimika

                      @jsulm Hey thanks!
                      I am getting this after writing the calling function ls -la /dev/ttyS0:
                      crw-rw----. 1 root dialout 4, 64 Oct 7 10:35 /dev/ttyS0

                      What does it mean?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @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.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        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.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        N 1 Reply Last reply
                        2
                        • N Offline
                          N Offline
                          Nimika
                          wrote on last edited by
                          #14

                          Thankyou both of you.
                          Please tell me how to add my normal user to the dialout group?
                          What is dialout group?

                          mrjjM jsulmJ 2 Replies Last reply
                          1
                          • K Offline
                            K Offline
                            kuzulis
                            Qt Champions 2020
                            wrote on last edited by
                            #15

                            QIODevice::OpenMode mode = QIODevice::ReadOnly | QIODevice::Unbuffered;

                            Did you read documentation? QIODevice::Unbuffered it is unsupported mode.

                            N 1 Reply Last reply
                            1
                            • K kuzulis

                              QIODevice::OpenMode mode = QIODevice::ReadOnly | QIODevice::Unbuffered;

                              Did you read documentation? QIODevice::Unbuffered it is unsupported mode.

                              N Offline
                              N Offline
                              Nimika
                              wrote on last edited by
                              #16

                              @kuzulis Yeah I made it as comment.

                              1 Reply Last reply
                              0
                              • N Nimika

                                Thankyou both of you.
                                Please tell me how to add my normal user to the dialout group?
                                What is dialout group?

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by mrjj
                                #17

                                @Nimika

                                • 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

                                N 1 Reply Last reply
                                1
                                • N Nimika

                                  Thankyou both of you.
                                  Please tell me how to add my normal user to the dialout group?
                                  What is dialout group?

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #18

                                  @Nimika You really should learn how user/groups and access rights management is working on UNIX/Linux.

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  1
                                  • N Offline
                                    N Offline
                                    Nimika
                                    wrote on last edited by
                                    #19

                                    @jsulm Actually my system is Red Hat Enterprise Linux based so it is different to use its commands.

                                    1 Reply Last reply
                                    0
                                    • mrjjM mrjj

                                      @Nimika

                                      • 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

                                      N Offline
                                      N Offline
                                      Nimika
                                      wrote on last edited by
                                      #20

                                      @mrjj Thank you !! let me add it now and search whether it will work or not.....

                                      mrjjM 1 Reply Last reply
                                      0
                                      • N Nimika

                                        @mrjj Thank you !! let me add it now and search whether it will work or not.....

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by mrjj
                                        #21

                                        @Nimika
                                        Np. as far as I can see it's the same for Red Hat with ttySX access, so there is
                                        tons on google on the topic on allowing user X to read and write to /dev/ttSxxx
                                        stuff.
                                        http://ithelpblog.com/os/linux/bashandscripts/howto-add-user-to-group-on-linux-redhat-rhel-centos-fedora/

                                        1 Reply Last reply
                                        1
                                        • SGaistS SGaist

                                          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.

                                          N Offline
                                          N Offline
                                          Nimika
                                          wrote on last edited by
                                          #22

                                          @SGaist Can I use serial ports to any user other than root?

                                          mrjjM 1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved