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. QSerialPort wont open connection

QSerialPort wont open connection

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 699 Views 1 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.
  • S Offline
    S Offline
    shokarta
    wrote on last edited by
    #1

    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?

    Pablo J. RoginaP 1 Reply Last reply
    0
    • S shokarta

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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #6

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

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kuzulis
        Qt Champions 2020
        wrote on last edited by
        #2

        @shokarta said in QSerialPort wont open connection:

        Busy: true
        so I see COM3 is fine

        Seriously?

        S 1 Reply Last reply
        1
        • S shokarta

          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?

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #3

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

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          S 1 Reply Last reply
          2
          • K kuzulis

            @shokarta said in QSerialPort wont open connection:

            Busy: true
            so I see COM3 is fine

            Seriously?

            S Offline
            S Offline
            shokarta
            wrote on last edited by
            #4
            This post is deleted!
            1 Reply Last reply
            0
            • Pablo J. RoginaP Pablo J. Rogina

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

              S Offline
              S Offline
              shokarta
              wrote on last edited by
              #5

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

              JonBJ 1 Reply Last reply
              0
              • S shokarta

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

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #6

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

                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