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 cannot open rfcomm socket

QSerialPort cannot open rfcomm socket

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 3.4k 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.
  • R Offline
    R Offline
    radoslav006
    wrote on last edited by
    #1

    Hi,
    I try to open rfcomm socket (bluetooth -> serial port), but QSerialPort library cannot open it. QSerialPort::open() returns false and QSerialPort::errorString() returns "Unknown Error" (error code 0). But when I open this socket by GtkTerm 0.99.7-rc1 everything works ok.
    I use Qt 5.3.1 (GCC 4.6.1, 64 bit) on Ubuntu 14.04 64 bit
    There is my piece of code that I use to connect to my socket:
    @
    serialPort->setPortName(ui->comboBoxPorts->currentText()); //"rfcomm0"
    serialPort->setBaudRate(ui->lineEditBaud->text().toInt()); //250000
    serialPort->setDataBits(QSerialPort::Data8);
    serialPort->setParity(QSerialPort::NoParity);
    serialPort->setStopBits(QSerialPort::OneStop);
    serialPort->setFlowControl(QSerialPort::NoFlowControl);

    if (!serialPort->open(QIODevice::ReadWrite)) {
        qDebug() << "Error: " << serialPort->error(); //returns 0
        ui->labelStatus->setText("Error: " + serialPort->errorString()); //returns "Unknown error"
        return;
    }
    

    @
    Have you any idea what may be wrong?
    Thanks in advance,
    Radek

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      What does QSerialPortInfo::availablePorts() report? Is rfcomm0 a valid serial port according to it?

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      0
      • R Offline
        R Offline
        radoslav006
        wrote on last edited by
        #3

        Thanks for reply.
        QSerialPortInfo::availablePorts() detect the "rfcomm0" correctly. QSerialPortInfo::isValid() returns true.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          NetZwerg
          wrote on last edited by
          #4

          Are you using the same serial port settings in GtkTerm?

          Try using different settings, i.e. Baud9600, ...
          Is it possible to only open for read-only or write-only?

          1 Reply Last reply
          0
          • R Offline
            R Offline
            radoslav006
            wrote on last edited by
            #5

            Thanks for help. It's working on standard baud rates (9600, 115200, 230400...). QSerialPort accepts only standard baud rates??

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NetZwerg
              wrote on last edited by
              #6

              Actually it does accept all.

              I did find a huge mistake your up to. You have to first open the port then apply the settings. Otherwise the settings will be applied to "default" on open. Try:

              @serialPort->setPortName(...)
              if(serialPort->open(QIODevice::ReadWrite))
              {
                serialPort->setBaudRate(ui->lineEditBaud->text().toInt()); //250000
                serialPort->setDataBits(QSerialPort::Data8);
                serialPort->setParity(QSerialPort::NoParity);
                serialPort->setStopBits(QSerialPort::OneStop);
                serialPort->setFlowControl(QSerialPort::NoFlowControl);
              }@
              
              1 Reply Last reply
              0
              • R Offline
                R Offline
                radoslav006
                wrote on last edited by
                #7

                Thanks a lot. I have one another question about sockets. I don't understand why I get opening error "Device or resocues is busy" (error code 2) while QSerialPort::isBusy() returns "false" and QSerialPort::isOpen() returns "false". This occur when I open rfcomm0 port with GtkTerm, close it and then try to open it with my aplication. Is there any way to reset socket?

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  NetZwerg
                  wrote on last edited by
                  #8

                  QSerialPort::isOpen():
                  Returns true if the device is open; otherwise returns false. A device is open if it can be read from and/or written to.

                  This means if your application did open the port and is readable/writable isOpen() returns true.

                  QSerialPortInfo::isBusy():
                  Not sure about this, if this really returns true if the port is still locked by another application.

                  QSerialPort::open()
                  This returns true if the port cannot be opened and false if not. So if you cannot open it, it probably is still locked.

                  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