serial_port_win32 icon indicating copy to clipboard operation
serial_port_win32 copied to clipboard

How to check if COM port is disconnected

Open sneiksus opened this issue 10 months ago • 1 comments

Greeting, is there a way to check that USB cable was unpluged? isOpened property always return true even when the usb cable was physically disconnected?

sneiksus avatar Apr 03 '24 10:04 sneiksus

isOpened property just reflects user code states in dart. So it's true if the usb cable was physically disconnected.

I know you want isOpened to automatically become false when cable disconnected. It needs WNDPROC callback function in winuser.h And may be multi-thread? I didn't implement this function because I don't know how dart implements win32 system callback function. 😭 Maybe win32 package supports this function now. I will try it.

Now, there are some other solutions to check USB COM PORT connection status:

  1. Using getAvailablePorts function to compare lists
  2. try write bytes or read bytes, and catch exception
  3. try close and reopen it

FengChendian avatar Apr 04 '24 09:04 FengChendian