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

QSerialPort wont open connection



  • Hello all,

    from the documentation of the device i know the port im looking for is COM3, also I know all the settings to be made (BaudRate, DataBits, Parity etc).

    So first I tried to check if the COM3 realy exists, so i tried:

    void LED::getSerial()
    {
        qDebug() << "start";
        const auto infos = QSerialPortInfo::availablePorts();
        qDebug() << "Amount of COM Ports:" << infos.count();
        for (const QSerialPortInfo &info : infos) {
            qDebug() << "Port:" << info.portName() << "// Location:"  << info.systemLocation() << "// Manufacturer:"  << info.manufacturer() << "// Serial number:"  << info.serialNumber() << "// Vendor Identifier:"  << (info.hasVendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : QString()) << "// Product Identifier:"  << (info.hasProductIdentifier() ? QString::number(info.productIdentifier(), 16) : QString()) << "// Busy:" << info.isBusy();
        }
        qDebug() << "end";
    }
    

    which gave me:

    Debug: start
    Debug: Amount of COM Ports: 3
    Debug: Port: "COM1" // Location: "\\\\.\\COM1" // Manufacturer: "(Standardn� typy port�)" // Serial number: "" // Vendor Identifier: "" // Product Identifier: "" // Busy: false
    Debug: Port: "COM3" // Location: "\\\\.\\COM3" // Manufacturer: "(Standardn� typy port�)" // Serial number: "" // Vendor Identifier: "" // Product Identifier: "" // Busy: true
    Debug: Port: "COM14" // Location: "\\\\.\\COM14" // Manufacturer: "(Standardn� typy port�)" // Serial number: "" // Vendor Identifier: "" // Product Identifier: "" // Busy: false
    Debug: end
    

    so I see COM3 is fine, so I tried to open with:

    #include <QSerialPort>
    #include <QSerialPortInfo>
    #include <QDataStream>
    #include <QtSerialPort/QSerialPort>
    
    void LED::testConn()
    {
        QSerialPort m_serial;
        m_serial.setPortName("COM3");
        if (!m_serial.open(QIODevice::ReadWrite)) {
            qDebug() << "Can not open the" << m_port << "port";
        } else {
            qDebug() << "COM port opened";
        }
     
        if (!m_serial.setBaudRate(QSerialPort::Baud9600))
            qDebug() << "Could not set baud rate";
        if (!m_serial.setDataBits(QSerialPort::Data8))
            qDebug() << "Could not set data bits number";
        if (!m_serial.setParity(QSerialPort::NoParity))
            qDebug() << "Could not set parity check option";
        if (!m_serial.setStopBits(QSerialPort::OneStop))
            qDebug() << "Could not set stop bits";
    //    if (!m_serial.setFlowControl(QSerialPort::NoFlowControl))
    //        qDebug() << "Could not set flow control mode";
    }
    

    and i only have the result:

    Debug: Can not open the "COM3" port
    

    what do I do wrong?
    Is there anything I can debug why it wont open connection?



  • @shokarta said in QSerialPort wont open connection:

    Is there a way to print an errornote why it wont connect?

    Did you look at the doc page before asking this, searching for error? How did you find QSerialPort::SerialPortError error() const worked for you?


  • Qt Champions 2020

    @shokarta said in QSerialPort wont open connection:

    Busy: true
    so I see COM3 is fine

    Seriously?



  • @shokarta said in QSerialPort wont open connection:

    Busy: true

    When you enumerate the ports, it looks like your COM3 port is already in use somewhere else...
    Are you sure no other application is using it?



  • This post is deleted!


  • @Pablo-J-Rogina said in QSerialPort wont open connection:

    @shokarta said in QSerialPort wont open connection:

    Busy: true

    When you enumerate the ports, it looks like your COM3 port is already in use somewhere else...
    Are you sure no other application is using it?

    its the LED light on tablet device, its always busy. its probably run on some service app from microsoft which is not able to be stopped.
    Are we surtain that because of this it can not be connected?

    Is there a way to print an errornote why it wont connect?



  • @shokarta said in QSerialPort wont open connection:

    Is there a way to print an errornote why it wont connect?

    Did you look at the doc page before asking this, searching for error? How did you find QSerialPort::SerialPortError error() const worked for you?


Log in to reply