Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSerial Port



  • Hi everyone,

    I have issues in using QSerial port. Actually, I have reading/writting data in my QT project using arduino. I have initialized my serial port in this way:

    serialport = new QSerialPort(this);
    serialport->setPortName("COM3");
    serialport->setBaudRate(QSerialPort::Baud19200);
    serialport->setDataBits(QSerialPort::Data8);
    serialport->setFlowControl(QSerialPort::NoFlowControl);
    serialport->setParity(QSerialPort::NoParity);
    serialport->setStopBits(QSerialPort::OneStop);
    qDebug()<<"Serial Port Opened"<<serialport->open(QSerialPort::ReadWrite);
    

    After reading/writing data from arduino at desired time, I want to stop it.
    I am stopping the serial port by using the command:

    serial->close();
    

    When I run my code for the first time, serial port doesn't stop. So, I stop my serial port forcefully through arduino's Serial Monitor. And then when I run my app again, it works alright. It start working perfectly 2nd time and ownwards. What I need to do, in order to close serial port in the first attempt.

    Waiting for guidance

    TIA,


  • Lifetime Qt Champion

    Hi,

    What do you mean exactly by "stop it" ?


  • Lifetime Qt Champion

    @Mar_60

    In your code, you open serialport, but you close serial.

    Might that be a problem?

    Otherwise provide more code. From the snippet, its not obvious.

    Regards


Log in to reply