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 Buffer Problems
QtWS25 Last Chance

QSerialPort Buffer Problems

Scheduled Pinned Locked Moved General and Desktop
serial portbufferqserialportoverflow
19 Posts 4 Posters 15.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.
  • J Offline
    J Offline
    Jeroen3
    wrote on 7 Jul 2015, 08:06 last edited by
    #8

    What does this return?:
    http://doc.qt.io/qt-5/qserialport.html#error-prop

    Or connect the signal http://doc.qt.io/qt-5/qserialport.html#error-1

    1 Reply Last reply
    0
    • M Offline
      M Offline
      metty
      wrote on 7 Jul 2015, 12:41 last edited by
      #9

      The error-methode returns always "0", in both cases.

      So I comanded three other different USB-Serial converters. I hope that I will see a difference. Somtimes my windows is also crashing. With this driver is anything wrong I think. I currently use this one: link

      For the three connections I created three different QSerialPort-Objects, and manage them all separate. But I have the problem also, when I use only one Serialconnection.

      The only time, that I read the Port ist in the "serialRecieved" Slot who is connected to the "readyRead".
      Hmm.. now I have an idea:
      I have also in the serialRecieved, all the parsing algorithms in there. And if it is a big package it can take mabye longer. What happens, when the slot ("serialRecieved") is not jet finisched, and a new signal from "readyRead" is coming. Does he start again, or does he wait, until the oldone is done? Mabye I have conflicts there.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jeroen3
        wrote on 7 Jul 2015, 14:34 last edited by Jeroen3 7 Jul 2015, 14:35
        #10

        The qt architecture is Asynchronous, but it secretly isn't.
        The main returns a.exec(), and that is where you're event loop is handled, and where your application sleeps when there is nothing interesting happening. The actual serial port implementation might not be in your thread though.
        It is impossible to have your serialRecieved() run twice without you implementing threading.

        The adapter linked most likely works on a Prolific USB-UART, those never worked reliably for me.
        I'd recommend you either get Silabs or FTDI converter chips. Such as FTDI Chipi-X.

        Meanwhile, HHD has a "free" serial port monitor. That might help determine the location of the problem.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          metty
          wrote on 8 Jul 2015, 14:35 last edited by
          #11

          Hello again! So I learnt something more about QT :)... I tried the new converters:
          With this one from Exsys my Problem is still there but a lot better. As I saw it has also a FTDI chip in there.
          This one from Moxa workt also better and with the Maxxtro, the driver does not work properly on my computer. I saw that FTDI Chipi-X is also very cheap. I will try this one too next monday.

          So thank you for your help until now, Jeroen3 and Rondog! It was helpful! Hope that I will find the solution soon...

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kuzulis
            Qt Champions 2020
            wrote on 8 Jul 2015, 18:10 last edited by kuzulis 7 Aug 2015, 18:13
            #12

            Most likelly, a problem is in your code. QSerialPort doesn't lose data, especially on lowest 9600 baud (as I can see from your video).

            UPD: Maybe you do wrong QByteArray <-> QString conversion.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jeroen3
              wrote on 9 Jul 2015, 07:05 last edited by
              #13

              Qt cannot keep up if you want to plot full speed 9600 baud to a multiline QTextEdit.
              Neither can C# or VC++. There is severe lag in Windows' GUI implementation somewhere.

              QSerialPort does lose data if the above is occurring and the buffer is not unlimited.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kuzulis
                Qt Champions 2020
                wrote on 9 Jul 2015, 08:02 last edited by kuzulis 7 Sept 2015, 08:03
                #14

                QSerialPort does lose data if the above is occurring and the buffer is not unlimited.

                No. This may happens only in case when event-loop is freezes (depends on wrong application design and by others reasons, e.g. QTBUG-34946). In this case QSerialPort does not read data which collected in FIFO of driver timely, and the FIFO can be overflowed.

                Common recommendations:

                • for Qt < 5.5 it is enough to move QSerialPort to the separate thread, to exclude an event-loop freezing (strongly recommended with a high streaming).
                • for Qt >= 5.5 this do not need to do (but, also can be moved to the separate thread too).
                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Jeroen3
                  wrote on 9 Jul 2015, 14:13 last edited by
                  #15

                  Obviously if you thread the QSerialPort doing gui stuff does not lock up the QSerialPort containing thread. However, you're still producing faster than the gui can consume.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    metty
                    wrote on 13 Jul 2015, 08:53 last edited by
                    #16

                    Actually I use the baudrate 115200 and I have around 50 strings like above in a second. Now after recieving the data, I put it firstly in the database, then I plot them with qcustomplot. I used QT 5.4. Now I updated to 5.5 and the problem is still there. I saw, that when I start the program, all seems to work. But after a while the errors become more and more. Also when I drag and drop the mainwindow, there is always coming an error. I will try to make a thead for this. This make sens to me.

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kuzulis
                      Qt Champions 2020
                      wrote on 13 Jul 2015, 09:22 last edited by kuzulis
                      #17

                      It means what are you doing something wrong. Somewhere you something blocks Qt event-loop.

                      Also when I drag and drop the mainwindow, there is always coming an error.

                      This should not be in Qt 5.5, check your code again and again.

                      PS: We here do not play in telepathists and predictors. If you want to get help, you should provide the minimal and simple example which reproduces an issue. E.g. try it with the com0com driver at first..

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        Jeroen3
                        wrote on 13 Jul 2015, 10:47 last edited by Jeroen3
                        #18

                        Replace the SerialPort with a TCPSocket. They both use QIOdevice api.
                        Then you can determine if the problem exists in the qt buffering, your display class ,or the hardware.
                        Here is an example to tunnel COM to TCP for windows https://github.com/Jeroen6/MultiTerminal/tree/master/driver.

                        You can easily spy on a TCP localhost socket with wireshark.

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          metty
                          wrote on 13 Jul 2015, 13:53 last edited by
                          #19

                          I am sorry about my last post. I made a stupid error. I updatet to QT5.5, but I haven't reconfigurated the project, so I was still using QT5.4.
                          Now I tried also the Chipi-X10 USB-RS converters. I have to say, they work a lot better. I have now for all three ports, this converter. With the others, a lot of times I had to unplug and replug the connectors to get dem work. So there is something strange. The Chipi worked really good until now, thank you jeroen3, this will save a lot of time.
                          After building the programm with QT5.5, the programm also work a lot better. I saw that the qcustemplot keeps plotting while I drag and drop the window. I have sometimes errors but now only sporadic. For example when I resize the window very fast, I can provoke it. But in general the errorrate is about one or two percent, and with that I can live.

                          PS: We here do not play in telepathists and predictors. If you want to get help, you should provide the minimal and simple example....

                          My problem was, that with the minimal simple example all seems to working. This communication problem I had only, wenn all the data was coming and when I was plotting someting in the same time. And I checked my code a lot of times. The problem is, my knowhow about QT and generell about programming with PCs is not very big. So I think there is something I do not know. So when I check my code a hundet times more, I will not find an error.

                          I made also an easy experiment to isolate the error:
                          My I slowed up the replot, so that I plot only every tenth time, but ten points at the same time. Like this I can see, that this error, comes only when the window is plotting. The error comes more, the more points he has to plot on the screen. So if I make fullscreen, and I set up the scale so that I have the maximum of points in the axis, the error comes every time again.
                          So QT has an influence to this problem. I think there is an overflow in some buffer, beause the program is to slow to read it or that he overwrites any part for some other reasons. But anyway.. For me I will pay attention now to not overcharge my comuter :)
                          Thank you for all help!

                          1 Reply Last reply
                          0

                          17/19

                          13 Jul 2015, 09:22

                          • Login

                          • Login or register to search.
                          17 out of 19
                          • First post
                            17/19
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved