Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-115205

QSerialPort does not properly set baud rate

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.2.11, 6.5.4, 6.6.1, 6.7.0 FF
    • 5.15.10, 6.5.1
    • Serial Port
    • None
    • Arch linux x64, Qt 5.15.10 (Arch linux packages)
    • Linux/X11
    • 5
    • 430a7464c (dev), 10a4b2acd (6.6), 42461955c (tqtc/lts-6.5), 72bbf89c7 (tqtc/lts-6.2)
    • Foundation Sprint 90, Foundation Sprint 91, Foundation Sprint 92, Foundation Sprint 93

    Description

      It appears that when a serial port is opened, the baud rate is set but it is not set at the correct moment. Assuming that you have a device with a baud rate of 115200, this baud rate is set so you can communicate with the device, e.g. using the code

       

          QSerialPort gspSerialPort;
          gspSerialPort.setBaudRate(115200);
          gspSerialPort.open(QIODevice::ReadWrite); 

      But unlike other programs, such as minicom, this is either not set persistently or using the same way the e.g. stty does it because upon opening, you receive a bunch of garbage data because the serial port is being opened at the wrong baud rate, so you receive garbage like:

      "\x87\xC9\x96\xD9\xB6\xD9\x87\xC9\x87\xD9\x96\xD9\x96\xC9\xB6\xD9\x96\xC9\xC7\xC9\x97\xD9\xB6\xD9\xB6\xC9\x96\xD9\x87\xC9\xEF\x87\xC9
      \x87\xC9\x96\xC9\xC7\xC9\x87\xC9\xC7\xC9\x16\xFA\x96\xD9\x87\xC9\x87\xC9\x87\xD9\xEF\x87\xC9\xC7\xC9\x87\xC9\x87\xD9\xEF\xFF\xFF\x16\
      xFA\x96\xC9\x96\xD9\x96\xC9\xC7\xC9\x96\xD9\xB6\xD9\x97\xD9\xC7\xC9\x96\xC9\xC7\xC9\x96\xD9\xC7\xC9\xFF\xEF\xC7\xC9\x96\xC9\xEF\xFF\x
      F7\xC7\xC9\x86\xD9\xC7\xC9\x87\xC9\xC7\xC9\x87\xD9\x87\xD9\xC7\xC9\x96\xD9\x97\xD9\xC7\xD9\x97\xD9\xB6\xD9\x96\xD9"
      "Hello wo"
      "rld fr"

      So whilst it does change to 115200, it does not start at 115200. This can be confirmed by checking with stty:

      stty -F /dev/ttyACM0  
      speed 9600 baud; line = 0;
      -brkint -imaxbel 

      If this is manually used to set the baud rate to 115200 with stty, then opening the port with Qt no longer gives a bunch of garbage at the start before giving correct output but fully gives the correct text. For comparison, the output with stty after having used minicom with a baud rate of 115200:

      stty -F /dev/ttyACM0  
      speed 115200 baud; line = 0;
      min = 1; time = 5;
      ignbrk -brkint -icrnl -imaxbel
      -opost -onlcr
      -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke 

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            ivan.solovev Ivan Solovev
            thedjnk Mr nK
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: