1

Ideally I would like to call a function when the USB port is disconnected while open, but I can't find if such thing is possible. While my python program runs, its opens up serial port self._serial = serial.Serial(self._serialPort, 9600, timeout=1) where self._port = '/dev/tty.usbserial-FTBNNWBM' when the device is disconnected nothing happens, until the program tries to send a command and fails.

I would like to be able to call disconnectHandler() when the device is disconnected.

Hackaholic
  • 19,069
  • 5
  • 54
  • 72
jonas
  • 175
  • 8
  • 1
    does https://stackoverflow.com/questions/21050671/how-to-check-if-device-is-connected-pyserial answer your question – 35308 Nov 30 '21 at 18:02
  • 1
    What exactly do **you** consider "best"? – martineau Nov 30 '21 at 18:14
  • What happens during the disconnect? Do you get thrown an exception ? – anarchy Nov 30 '21 at 18:20
  • That question does not answer it. Sorry. The thing I would like to happend was maybe like an interrupt would happend When the device was unplugged, with a callback to a disconnect handler – jonas Nov 30 '21 at 19:40

0 Answers0