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. Turning off power to a running QSerialPort
Forum Update on Monday, May 27th 2025

Turning off power to a running QSerialPort

Scheduled Pinned Locked Moved Unsolved General and Desktop
qserialportsegfaultasynchronous
14 Posts 6 Posters 3.5k 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.
  • S sykac

    @mrdebug By power off I mean literally switching off electricity.

    @JKSH 1. The main device has a USB hub. To this hub there are 6 ports connected.
    2. I don't have answer to this question. I don't know when the application crashes exactly, I'm just sure it's because of the serial communication and I'm trying to find out what could be a problem for QSerialPort.

    I'm sorry for this abstract question but I have troubles understanding the problem myself.

    JKSHJ Offline
    JKSHJ Offline
    JKSH
    Moderators
    wrote on last edited by
    #5

    @sykac said in Turning off power to a running QSerialPort:

    1. The main device has a USB hub. To this hub there are 6 ports connected.

    Is the hub externally powered? If not, there's a small chance you might get a power overload.

    P.S. Earlier you mentioned "there is one main device connected to the PC with a usb cable (1 COM port)". Note that a USB hub only has USB ports -- it has no COM ports.

               2. I don't have answer to this question. I don't know when the application crashes exactly, I'm just sure it's because of the serial communication and I'm trying to find out what could be a problem for QSerialPort. 
    

    I'm sorry for this abstract question but I have troubles understanding the problem myself.

    Unfortunately, I can't do much with such a vague description.

    You need to spend time troubleshooting. For example:

    • See if you can gradually remove code from other parts of your application and still cause the crash.
    • See if the crashes occur when you only have 1 instead of 6 serial devices.
    • See if a different hub causes the crashes.
    • See if a dedicated multi-serial-port hub causes the crashes: https://www.moxa.com/product/UPort_1610-8.htm

    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

    1 Reply Last reply
    2
    • mrdebugM Offline
      mrdebugM Offline
      mrdebug
      wrote on last edited by
      #6

      If you unplug the device when the serial port is open it is normal to have a crash.
      It is similar to remove an usb pen drive when you are working on a file.
      The os could have a problem with device handle, for example it can assign a diferent description to the device when you replug it.

      Need programmers to hire?
      www.labcsp.com
      www.denisgottardello.it
      GMT+1
      Skype: mrdebug

      1 Reply Last reply
      1
      • J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #7

        you might be doing something wrong in your threads.

        I have an application that is running a QSerialPort in a thread, with constant data polling, and if I unplug the usb/COM-Port dongle

        I get simply an

        QModbusDevice::Error(ConnectionError) "Resource error."

        to what I react to.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        2
        • aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #8

          Just to add my experience to @mrdebug and @J-Hilk:

          I sometimes have problems with electrical arcs in our devices. If a computer is connected through USB (with FTDI USB-serial converter), anything can happen: often I'm unable to close and re-open the serial port. It seems this is dependend on the device driver.

          In most cases it helps to disconnect and reconnect the USB cable, but I also remember cases where a PC reboot was needed.

          Qt has to stay free or it will die.

          S 1 Reply Last reply
          0
          • M Offline
            M Offline
            MrShawn
            wrote on last edited by
            #9

            Make sure you don't have any dangling pointers. Usually my programs are crashing when I do something stupid with a pointer. If you have multiple threads you are likely doing things with pointers somewhere, and you may not have been as careful as you think you were. I'd run in debug mode and see if any insight is provided.

            1 Reply Last reply
            0
            • aha_1980A aha_1980

              Just to add my experience to @mrdebug and @J-Hilk:

              I sometimes have problems with electrical arcs in our devices. If a computer is connected through USB (with FTDI USB-serial converter), anything can happen: often I'm unable to close and re-open the serial port. It seems this is dependend on the device driver.

              In most cases it helps to disconnect and reconnect the USB cable, but I also remember cases where a PC reboot was needed.

              S Offline
              S Offline
              sykac
              wrote on last edited by
              #10

              @aha_1980 That's my case, some of my devices are using ftdi usb-serial converter. What exactly do you mean device drivers? I just manually downloaded ftdi drivers from the official web. I thought I couldn't do anything wrong with that, I just downloaded and installed the driver.

              So you are saying it is not solveable? It just happens with this kind of HW?

              J.HilkJ JKSHJ 2 Replies Last reply
              0
              • S sykac

                @aha_1980 That's my case, some of my devices are using ftdi usb-serial converter. What exactly do you mean device drivers? I just manually downloaded ftdi drivers from the official web. I thought I couldn't do anything wrong with that, I just downloaded and installed the driver.

                So you are saying it is not solveable? It just happens with this kind of HW?

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #11

                @sykac where does your program actually crash!? Have you run your program with the debugger attached yet? If yes, what does the stacktrace say?


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                1
                • S sykac

                  @aha_1980 That's my case, some of my devices are using ftdi usb-serial converter. What exactly do you mean device drivers? I just manually downloaded ftdi drivers from the official web. I thought I couldn't do anything wrong with that, I just downloaded and installed the driver.

                  So you are saying it is not solveable? It just happens with this kind of HW?

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #12

                  @sykac said in Turning off power to a running QSerialPort:

                  So you are saying it is not solveable?

                  Before you can solve it, you must first track down the cause of the crash.

                  You need to spend time troubleshooting. For example:

                  • See if you can gradually remove code from other parts of your application and still cause the crash.
                  • See if the crashes occur when you only have 1 instead of 6 serial devices.
                  • See if a different hub causes the crashes.
                  • See if a dedicated multi-serial-port hub causes the crashes: https://www.moxa.com/product/UPort_1610-8.htm

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  2
                  • S Offline
                    S Offline
                    sykac
                    wrote on last edited by sykac
                    #13

                    @J-Hilk @JKSH So it seems there is more problems in my serial communication. One problem starts probably in the hardware. The COM port of the device disconnects from the PC (I don't why, it could be some driver/firmware issue), QSerialPort emits error "The attached device is not functioning.". Then the application closes the serial port and tries to reopen it. It opens succesfully but when waitForReadyRead(3000) is called after that, the thread hangs forever. It doesn't crash, just hangs.

                    It is weird as in the Device Manager I cannot see the COM port anymore, although the QSerialPort opens succesfully.

                    Then there is another error which causes the crashing but I couldn't find the reproducer for it yet.

                    aha_1980A 1 Reply Last reply
                    0
                    • S sykac

                      @J-Hilk @JKSH So it seems there is more problems in my serial communication. One problem starts probably in the hardware. The COM port of the device disconnects from the PC (I don't why, it could be some driver/firmware issue), QSerialPort emits error "The attached device is not functioning.". Then the application closes the serial port and tries to reopen it. It opens succesfully but when waitForReadyRead(3000) is called after that, the thread hangs forever. It doesn't crash, just hangs.

                      It is weird as in the Device Manager I cannot see the COM port anymore, although the QSerialPort opens succesfully.

                      Then there is another error which causes the crashing but I couldn't find the reproducer for it yet.

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #14

                      @sykac said in Turning off power to a running QSerialPort:

                      One problem starts probably in the hardware. The COM port of the device disconnects from the PC (I don't why, it could be some driver/firmware issue)

                      Reading you topic title, could it be that the USB connection between PC and FTDI is interrupted? And that's what I said, this may lead to endless loops in the device driver.

                      This kind of problems can hardly be solved in the user space.

                      Qt has to stay free or it will die.

                      1 Reply Last reply
                      1

                      • Login

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