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 - Auto Baud Rate Detection
Forum Updated to NodeBB v4.3 + New Features

QSerialPort - Auto Baud Rate Detection

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.9k Views
  • 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.
  • webzoidW Offline
    webzoidW Offline
    webzoid
    wrote on last edited by
    #1

    Could anyone please suggest any strategies for QSerialPort automatic baud rate detection? All sensors I communicate with via the serial port use either an ASCII text or ASCII hex protocol.

    Would it be valid to read a buffer of say 10 characters and check to see whether ALL characters fall within the standard ASCII range? Could there be issues with doing things this way? In my experience, incorrect baud rates usually lead to spurious characters being receive which are way beyond the ASCII range.

    Is there anything which could be done with timing of received characters using QSerialPort which would be more accurate?

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

      It is not an simple issue (IMHO), because in addition of different baud rates, the remote sensor can communicate with the different parity settings too. So, you need to pass both properties: as a bauds and as a parities to parse an each of received package to validity.

      Maybe your sensor should send a some (SYNC) patterns, which are sensitive to the framing && parity errors. I meant, which will be corrupted when a baud rate or a parity is wrong on 100%.

      1 Reply Last reply
      2
      • webzoidW Offline
        webzoidW Offline
        webzoid
        wrote on last edited by
        #3

        @kuzulis Thanks for your reply. A lot of the sensors used with the application will be GPS (or NMEA outputting) sensors so I can already assume what information will be output (ASCII text).

        The other sensors I interface with just produce ASCII hex strings - similar to NMEA but with more hex-wrapped data. Either way, it wouldn't be possible to modify any hardware to include any additional sync patterns but ALL sensors already output a '$' sync character.

        Parity is a good observation. I guess there would be a possibility to include baud-rate tests with parity on/off.

        Would the QSerialPort::error() function not give anything meaningful upon incorrect baud-rate/parity/stop/start bits?

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

          @webzoid said in QSerialPort - Auto Baud Rate Detection:

          Would the QSerialPort::error() function not give anything meaningful upon incorrect baud-rate/parity/stop/start bits?

          Previously, there (in QSP) we tried to implement the Frame/Parity errors. But a problem is that it is too complicates a code, besides, it does not work on all devices (because some chips, drivers, platforms and so on, just does not implements internally a functionality to detecting of this errors) or it works differently. So, now these errors is deprecated and are not implemented at all.

          1 Reply Last reply
          2
          • R Offline
            R Offline
            Rondog
            wrote on last edited by
            #5

            My approach would be to send a command and simply look for an expected response and if you don't get an expected response the baud rate is wrong (may be other reasons too). The sequence to find the baud rate would be to start at the lowest and work up to the highest until you get an expected response to a specific command. To be efficient (because this process is slow) store any found baud rate so that the next time the program runs it defaults to what was used last time (where 'Auto' would be the default if no previous setting exists).

            The hardware and low level drivers of the OS should handle things like framing or parity errors (?). I don't know if the data is available to inspect if you get this kind of error.

            I don't think it is necessary to send special sequences or bit patterns. It depends on the situation I suppose.

            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