I asked this question yesterday on Stack Overflow. It may be a hardware question, and it may be a software question. The question is getting very few views in the original forum, so I am reposting it here.

A few years ago, I wrote a little program in PyQt5 which monitored changes in the output from QSerialPortInfo.availablePorts() to produce a live information display, showing devices which are connected to USB ports, and accessible to the user (so the USB mouse and keyboard are not listed). I have tested this program with success on two Linux machines and one MacBook.

When I wrote this program, I had only one kind of device that interested me, Nordic nRF52 development boards. I might connect two or three of them to one host computer at a time, adding and removing them on the fly. The dev boards had no power switches, so you could only disconnect them by unplugging the USB cable. I know, this is not recommended, but I had no choice. In any case, it worked for me. The host computer OS recognized the disconnect event, freed up the corresponding port, and removed that port from the output of QSerialPortInfo.availablePorts().

In a current test using my program, I have a different device, a Kiprim programmable power supply which can supposedly be controlled using the SCPI protocol over the USB connection at the back of the unit. I just tried to find this device using my PyQt5 serial port scanner. My program finds the device and reserves a serial port for it when the USB cable is connected. It frees up the serial port when the USB cable is unplugged. So far, so good.

Unlike the Nordic development boards, the Kiprim power supply also has a power switch. However, if I turn the switch off when the power supply is connected over USB, the host does not free up a serial port and the output of QSerialPortInfo.availablePorts() remains unchanged.

I want my host computer to be notified that the connection to the peripheral has been lost, even if the cable is still attached.

Why are unplugging the USB cable and powering off the device being recognized as two distinct events? What is the software and/or hardware explanation? Is this issue unique to Qt (PyQt, PyQt5) or is this a more universal issue, either defined by the OS or by a USB standard?

And finally: what is the recommended way for the host computer to detect the peripheral power-off event?

Thanks for your advice!

  • 1
    \$\begingroup\$ So what if the serial port section is powered from PC and it does not matter if the device is on or off? I think I'll write that as an answer. \$\endgroup\$
    – Justme
    Commented Nov 7, 2023 at 18:14
  • \$\begingroup\$ @Justme I am aware that that is also a possibility. It does not apply to the Kiprim power supply. The nRF52 boards I was using a few years ago could be USB powered, or they could be operated from a coin battery if you supplied one. In the case of the Kiprim power supply, it has a 110V power cord. \$\endgroup\$
    – John L.
    Commented Nov 7, 2023 at 18:18
  • \$\begingroup\$ So you did not understand. It does not matter if there is a 110V power cord. Please see my answer which hopefully explains it better. It so does apply to your power supply. \$\endgroup\$
    – Justme
    Commented Nov 7, 2023 at 18:25

1 Answer 1


There are bus-powered and self-powered USB devices.

Bus-powered devices get their power from PC and self-powered devices have a separate power supply that is required to be on before it shows up on the PC.

But you can also mix these up.

Clearly your power supply has an USB serial interface that is powered from PC, and it is the simplest way of doing it because it likely needs to be electrically isolated from the power supply output, maybe with optocouplers. So it does not matter if the device is on or off, or if it has mains plug connected or disconnected. PC powers the USB section and it will always show up as a serial port.

It's actually exactly same if your power supply had an RS-232 port, and you had an USB-to-RS232 adapter connected between your PC and power supply.

The adapter does not care if there is something listening or even connected on the RS-232 side, the USB chip is still powered from the PC and looks like a serial port.

  • \$\begingroup\$ Thanks, I hadn't considered the possibility that the USB cable would be used to power the power supply's USB interface, when there is plenty of power available on the power supply! I'll try communicating with the power supply using the SCPI protocol as long as the OS says that the serial port is available. I wonder what information might be returned, if any, when the power supply is switched off. \$\endgroup\$
    – John L.
    Commented Nov 8, 2023 at 7:11
  • \$\begingroup\$ @JohnL. That scenario is either defined in the manual or it isn't so you need to figure it out. Maybe there is no CPU to respond. Maybe some handshake like says power is on/off or PSU CPU present for communications. \$\endgroup\$
    – Justme
    Commented Nov 8, 2023 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.