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. how to read and write in serial port in RHEL platform?

how to read and write in serial port in RHEL platform?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 3.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.
  • N Offline
    N Offline
    Nimika
    wrote on last edited by
    #1

    I am writing a simple program :

    #include <QCoreApplication>
    #include <QSerialPort>
    #include <QSerialPortInfo>
    #include <QDebug>
    #include <string>
    QSerialPort serial;

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    serial.setPortName("COM4");
    serial.setBaudRate(QSerialPort::Baud115200);
    serial.setDataBits(QSerialPort::Data8);
    serial.setParity(QSerialPort::NoParity);
    serial.setStopBits(QSerialPort::OneStop);
    serial.setFlowControl(QSerialPort::HardwareControl);
    qDebug()<< serial.open(QIODevice::ReadWrite);
    QByteArray output ;
    QByteArray input;

    output = "name";
    serial.write(output);
    serial.waitForBytesWritten(10);
    serial.waitForReadyRead(1000);
    input = serial.readAll();
    qDebug() << input;
    serial.close();
    return a.exec();
    }
    As I want to display the input but I am not getting any diplayed item.
    But whenever I am using the qint64 byteswriiten = serial.write(output), byteswritten is giving the 5 in terminal if we display it.
    Kindly help me out as I am stuck here.
    I just want to check whether the data which I am writing in serialport is there or not?
    and then can I read the same data from the serialport?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Are you sure this is correct?
      serial.setPortName("COM4");
      On linux its normally called
      /dev/ttyS0
      /dev/ttyS1
      etc

      You can test with
      http://doc.qt.io/qt-5/qtserialport-terminal-example.html

      It shows which ports it can see.

      N 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        Are you sure this is correct?
        serial.setPortName("COM4");
        On linux its normally called
        /dev/ttyS0
        /dev/ttyS1
        etc

        You can test with
        http://doc.qt.io/qt-5/qtserialport-terminal-example.html

        It shows which ports it can see.

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

        @mrjj hey!
        Actually I am using some other port naming whose address is correct. But still its not working with read and write or may be not working with read only!!!! I don't know whats the matter?????

        mrjjM 1 Reply Last reply
        0
        • N Nimika

          @mrjj hey!
          Actually I am using some other port naming whose address is correct. But still its not working with read and write or may be not working with read only!!!! I don't know whats the matter?????

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

          @Nimika
          Well code looks fine - so in what way does it not work?

          Can u read anything at all?

          Without the actual code you are using , its impossible to give guesses.

          N 1 Reply Last reply
          0
          • mrjjM mrjj

            @Nimika
            Well code looks fine - so in what way does it not work?

            Can u read anything at all?

            Without the actual code you are using , its impossible to give guesses.

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

            @mrjj Except port name I gave you the code which I am running.
            There is no output at all in display. Thats why I am confused that evrythin gis correct so where I did any mistake (if any).
            Even when I am running any QT example program like CREADERSYNC or any other, still there is no output.
            So is there any problem in QT??
            As I have used different computers for different versions of Qt and still I am getting the same problem.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I highly doubt it has anything to do with Qt.
              Why dont you try minicom or other serial program and see if you can read anything.

              N 1 Reply Last reply
              0
              • mrjjM mrjj

                I highly doubt it has anything to do with Qt.
                Why dont you try minicom or other serial program and see if you can read anything.

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

                @mrjj
                yeah I have used other serial programs too but still no answer.
                :(

                mrjjM 1 Reply Last reply
                0
                • N Nimika

                  @mrjj
                  yeah I have used other serial programs too but still no answer.
                  :(

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

                  @Nimika
                  But then it means that your serial is simply not working or
                  what ever that should answer/send is not doing it.
                  If its not working with other serial program, it wont work with Qt either.

                  So you must find out what part is not working.

                  Does the other end even try to send something?`

                  http://www.cyberciti.biz/faq/find-out-linux-serial-ports-with-setserial/

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

                    Hi,

                    Maybe a silly question but: do you have anything connected on that port ? How should it answer ?

                    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
                    1
                    • SGaistS SGaist

                      Hi,

                      Maybe a silly question but: do you have anything connected on that port ? How should it answer ?

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

                      @SGaist
                      There is nothing else connected to that port.
                      I have mentioned you what I did...

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

                        Hello All,
                        My problem is resolved.
                        There is some timing mismatch thats all.
                        Thank you!

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

                          You mentioned what you coded not what you had connected to the serial port whether it is another computer or a device. If you did then sorry I didn't saw 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
                          1
                          • SGaistS SGaist

                            You mentioned what you coded not what you had connected to the serial port whether it is another computer or a device. If you did then sorry I didn't saw it.

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

                            @SGaist
                            It's ok if you have not noticed it that I was doing the connection in the same computer which is wrong.
                            Thank you!

                            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