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. QtSerialPort and CPU usage
Forum Updated to NodeBB v4.3 + New Features

QtSerialPort and CPU usage

Scheduled Pinned Locked Moved General and Desktop
18 Posts 4 Posters 9.5k 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.
  • D Offline
    D Offline
    DerManu
    wrote on last edited by
    #5

    1.) run in debug mode and stop execution a few times. Usually you land in the problematic section when having problems like these. (You'll need the debug version of your serial library to find the problem inside it though).

    2.) profile your application with valgrind and find out where the CPU-eater is.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dolbyz
      wrote on last edited by
      #6

      I'll check do I have other usb to serial bridge-cables(on monday when I get back to work). I have only a laptop and it does not have any "native" serial ports.

      My program is really simple. It has only the mainwindow-class which contains all the code. I don't have there anything that could cause this cpu usage. I yesterday added debug prints to all slots (and other methods) in my program + I added prints also to QtSerialPort (all methods and to all while-loops). No prints were coming when cpu usage was 100%.

      I'm using windows so I can't use valgrind. I'll have to check it with debugger, but I would need debug versions of the windows dll's used in serial port connections?

      I'm actually developing something in embedded device with c which uses serial port. Purpose of this Qt application was just to send few "hardcoded" messages (at least for now) to check the functionality and response messages.

      Thanks for the advices.

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

        QByteArray may not be zero terminated - forget this.

        Some ideas, try harder to figure out where actually the cpu time is consumed. We can only see the code you've applied but in my opinion you should look into the send signal and (more possible) the receive slot. Try to remove the lines from the above code until it stops hanging. Maybe it is hanging in some procedure you don't have the code for and you don't see the while loop where it is cycling. You may also look into the rest of your code, sometimes someone programs a recursive statement unintended especially when you filled up everything into a single class.

        good look!

        This, Jen, is the internet.

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

          2Dolbyz,

          Previously had a similar problem with the CPU load, using the USB / Serial converter chip Prolific. The problem was that in a false fire notifier QWinEventNotifier at data receiving. Presumably the reason is the driver, although it is difficult to say. Previously, I seems to be fixed this problem, though .. I try will check again.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dolbyz
            wrote on last edited by
            #9

            My colleague found another usb-to-serial cable (USB-SERIAL CH340 wch.cn). It works perfectly.

            When I debugged with the old cable it seemed to loop in qevendispatcher_win.cpp:770 for loop. With the old cable I got from two to eight readyRead-signals (message length about 16 bytes). With this "new" cable, just single signal with whole data.

            Thanks for your help.

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

              Please try to fix the code in the source code library QtSerialPort to test, as described "here":https://bugreports.qt-project.org/browse/QTPLAYGROUND-2 and take there is an example of an "attached":https://bugreports.qt-project.org/secure/attachment/28890/TestSerial.zip for testing.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Dolbyz
                wrote on last edited by
                #11

                I tried this fix. The problem still occurs. I used my own code for testing.

                For second try I put debug print to that event-function. I guess it was called "few" times, because then qt creator jammed too :)

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

                  Bad bad bad. I do not have ideas how to fix it.

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

                    UPD: Please try repeat test with new test tool "CpuUsageTester":https://bugreports.qt-project.org/secure/attachment/28899/CpuUsageTester.zip

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Dolbyz
                      wrote on last edited by
                      #14

                      It works exactly same way with this test application.

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

                        Clear, thx

                        So, most likely a problem in the drivers.

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

                          2 Dolbyz,

                          Please check CPU load with a new concept from "here":https://codereview.qt-project.org/#change,32186

                          PS: If you have free time.

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            Dolbyz
                            wrote on last edited by
                            #17

                            I'll try to test during this week.

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              Dolbyz
                              wrote on last edited by
                              #18

                              With this version I could not reproduce the 100% CPU usage-bug.

                              At least previously it happened almost immediately. Now I tried for some time, but no issues.

                              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