serial_port_win32
serial_port_win32 copied to clipboard
How to check if COM port is disconnected
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?
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:
- Using
getAvailablePorts
function to compare lists - try write bytes or read bytes, and catch exception
- try close and reopen it