Open Serial Port



  • Hi !

    To open serial port, we just need this ligne ? :

    port = new QSerialPort();
    port->open(QIODevice::ReadWrite);
    

    when i execute, i have an error :

    QIODevice::write (QSerialPort): device not open

    ps : ( i have config port like this : )

    SerialPort::SerialPort(QWidget *parent):
        QDialog(parent)
    {
    
       port = new QSerialPort();
       port->setPortName("portname");
       port->setBaudRate(QSerialPort::Baud115200);
       port->setParity(QSerialPort::NoParity);
       port->setDataBits(QSerialPort::Data8);
       port->setStopBits(QSerialPort::OneStop);
    
       //bool a = port->open(QIODevice::ReadWrite);
       //cout<< "le port est ouveret ?  " << a << endl;
    
    }```
    cout send me : a = 0 if i execute last 2 ligne ... and i see in documentation if port open is successful, so it's return false ...


  • You need to set a right device name (aka port name) before opening.


  • Lifetime Qt Champion

    Hi
    just as a note.
    This example is very good for testing out serialport
    https://doc.qt.io/qt-5/qtserialport-terminal-example.html



  • Yes i have see that befor your answer ^^ its COM3 and not portname When i setPortName
    ty !


Log in to reply
 

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