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

  • 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);
    QByteArray output ;
    QByteArray input;

    output = "name";
    input = serial.readAll();
    qDebug() << input;
    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?

  • Qt Champions 2017

    Are you sure this is correct?
    On linux its normally called

    You can test with

    It shows which ports it can see.

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

  • Qt Champions 2017

    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.

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

  • Qt Champions 2017

    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.

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

  • Qt Champions 2017

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

  • Lifetime Qt Champion


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

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

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

  • Lifetime Qt Champion

    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.

  • @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!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.