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 and baudrate settings

QSerialPort and baudrate settings

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

    Under Windows 7, Qt 5.3 I have problems to set the baudrate of a QSerialPort:

    @QSerialPort *serial = new QSerialPort(this);
    serial->open(QIODevice::ReadWrite);
    serial->setBaudRate(115200);@

    setBaudRate returns true, but on some machines the baudrate is not actually set. I need to open/close the port with an external serial terminal (like RealTerm) with the desired baudrate in order to get it works.
    I tried to set the baudrate before opening the port with no chance.

    On other computers (same o.s., same Qt version, same USB/RS232 converter) it works fine.

    I cannot understand where is the mistake.
    Anyway, do you know any workaround to BE SURE the baudrate is really set? I'm puzzling over using Windows API or even launch a command-line terminal with QProcess....

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The only thing I can think of would be different driver version between computers. Did you by any chance look at that ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • F Offline
        F Offline
        franku
        wrote on last edited by
        #3

        Did you try swapping line 2. and 3. from the above?

        This, Jen, is the internet.

        1 Reply Last reply
        0
        • _ Offline
          _ Offline
          _Mark_
          wrote on last edited by
          #4

          Yes, I said:

          bq. I tried to set the baudrate before opening the port with no chance.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @ franku, a QSerialPort needs to be opened first, then you do the settings.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • _ Offline
              _ Offline
              _Mark_
              wrote on last edited by
              #6

              According to the documentation, there's no need to open the port first:

              bq. If the setting is set before opening the port, the actual serial port setting is done automatically in the QSerialPort::open() method right after that the opening of the port succeeds.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                This page seem to have changed with time.

                Anyway thanks for pointing it out.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  franku
                  wrote on last edited by
                  #8

                  Thanks for the comment. I was working with QExtSerialPort sometime ago and I remember a similar problem before QSerialPort was introduced in a Qt distribution. So maybe I have mixed things up.
                  You could also try to set the baudrate to i.e. 9600 first and then back to 150kBd again in order to change any underlying variable. But this still wouldn't explain why it works on some PCs and not on others.
                  On the other hand it may help to debug down to the win32 code of QSerialPort on a system that works and on another that doesn't. Maybe this could help you discover why true ist returned from the software and nothing happens on the hardware.

                  This, Jen, is the internet.

                  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