Turning off power to a running QSerialPort
-
@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.
-
@sykac said in Turning off power to a running QSerialPort:
- 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
-
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. -
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.
-
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.
-
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.
-
@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?
-
@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
-
@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.
-
@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.