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. opening of serial port

opening of serial port

Scheduled Pinned Locked Moved General and Desktop
17 Posts 4 Posters 3.9k Views
  • 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.
  • N Offline
    N Offline
    Nimika
    wrote on last edited by
    #1

    how to open the serial port outside Qt?
    I have written my code in qt, it is opening but whenver I am writing or reading in that port its showing device not open.
    Is there any solution??
    I am using MOXA card for serial communication.

    jsulmJ 1 Reply Last reply
    0
    • N Nimika

      how to open the serial port outside Qt?
      I have written my code in qt, it is opening but whenver I am writing or reading in that port its showing device not open.
      Is there any solution??
      I am using MOXA card for serial communication.

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

      @Nimika "it is opening but whenver I am writing or reading in that port its showing device not open" - are you sure you opened the port? Did you check it like this:

      qDebug() << serial.open(QIODevice::ReadWrite);
      

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

      N 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Nimika "it is opening but whenver I am writing or reading in that port its showing device not open" - are you sure you opened the port? Did you check it like this:

        qDebug() << serial.open(QIODevice::ReadWrite);
        
        N Offline
        N Offline
        Nimika
        wrote on last edited by VRonin
        #3

        @jsulm
        i just checked it and it is showing false.
        I wrote this program.

        #include <QCoreApplication>
        #include <QSerialPort>
        #include <QDebug>
        
        QSerialPort serial;
        int main(int argc, char *argv[])
        {
            QCoreApplication a(argc, argv);
            serial.setPortName("ttyM");
            serial.setBaudRate(QSerialPort::Baud115200);
            serial.setDataBits(QSerialPort::Data8);
            serial.setStopBits(QSerialPort::OneStop);
            serial.setParity(QSerialPort::NoParity);
            serial.setFlowControl(QSerialPort::NoFlowControl);
           serial.open(QIODevice::ReadWrite);
           qDebug() << "port connected";
           qDebug() << serial.open(QIODevice::ReadWrite);
           serial.write("hello");
        QByteArray bb = serial.readAll();
        qDebug() << bb ;
           serial.close();
            return a.exec();
        }
        
        1 Reply Last reply
        0
        • N Offline
          N Offline
          Nimika
          wrote on last edited by
          #4

          @jsulm
          where am I lacking I don't understand.
          Or maybe this is the problem in MOXA port.

          jsulmJ 2 Replies Last reply
          0
          • N Nimika

            @jsulm
            where am I lacking I don't understand.
            Or maybe this is the problem in MOXA port.

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

            @Nimika
            That's wrong:

            serial.open(QIODevice::ReadWrite);
            qDebug() << "port connected";
            qDebug() << serial.open(QIODevice::ReadWrite);
            

            do it like this (do not call open twice!):

            qDebug() << "port connected";
            qDebug() << serial.open(QIODevice::ReadWrite);
            

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

            1 Reply Last reply
            1
            • N Nimika

              @jsulm
              where am I lacking I don't understand.
              Or maybe this is the problem in MOXA port.

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

              @Nimika If it still not able to open the connection then check all the connection parameters you're specifying.

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

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

                Ok but still it is not working when I am using the single open function.

                mrjjM 1 Reply Last reply
                0
                • N Nimika

                  Ok but still it is not working when I am using the single open function.

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

                  @Nimika
                  Hi are you 100% sure about portname ?
                  serial.setPortName("ttyM");
                  I would expect a number ttyM0

                  N 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @Nimika
                    Hi are you 100% sure about portname ?
                    serial.setPortName("ttyM");
                    I would expect a number ttyM0

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

                    @mrjj
                    Oh sorry by mistake I have written that but I am using ttyM0 only.

                    mrjjM 1 Reply Last reply
                    1
                    • N Nimika

                      @mrjj
                      Oh sorry by mistake I have written that but I am using ttyM0 only.

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

                      @Nimika
                      Ok. Just checking.

                      Did you try with minicom or any other serial programs if it will open it ?

                      N 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @Nimika
                        Ok. Just checking.

                        Did you try with minicom or any other serial programs if it will open it ?

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

                        @mrjj
                        Its not working with any case.

                        mrjjM 1 Reply Last reply
                        0
                        • N Nimika

                          @mrjj
                          Its not working with any case.

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

                          @Nimika

                          Well if minicom or friends dont like it either, my guess would be

                          Its brand new, you never gave anyone (user) permissions to ttyMX

                          its a monday one and broken :)

                          1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @Nimika If it still not able to open the connection then check all the connection parameters you're specifying.

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

                            @jsulm
                            Well I have checked all the specifications still let me check it again.

                            @mrjj
                            What do you mean by "monday one and broken"??
                            Please clarify it thank you.

                            jsulmJ 1 Reply Last reply
                            0
                            • N Nimika

                              @jsulm
                              Well I have checked all the specifications still let me check it again.

                              @mrjj
                              What do you mean by "monday one and broken"??
                              Please clarify it thank you.

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

                              @Nimika "made on Monday" :-)
                              Usually people are not fully operable on Monday after weekend and do more mistakes and produce more broken products :-)

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

                              N 1 Reply Last reply
                              1
                              • jsulmJ jsulm

                                @Nimika "made on Monday" :-)
                                Usually people are not fully operable on Monday after weekend and do more mistakes and produce more broken products :-)

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

                                @jsulm
                                Lol!
                                but I think I am nowhere lacking in this regard.

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

                                  Hi,

                                  Looks like you're on linux, wouldn't that be /dev/ttyM0 ?

                                  One other thing: do you have the rights to access the serial port ?

                                  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
                                  1
                                  • N Offline
                                    N Offline
                                    Nimika
                                    wrote on last edited by
                                    #17

                                    Hello all thank you for your replies.
                                    I sorted out my problem, its there in installation.
                                    Now all ports are working fine.

                                    @SGaist
                                    Yeah I have used /dev/ttyM0 only.
                                    Thank you!

                                    1 Reply Last reply
                                    1

                                    • Login

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