Click here to Skip to main content
14,875,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a USB serial port in C#. The .net serial port read/write operations work well except in some infrequent cases. If I halt the serial read operations -- as in the case of a debugger break operation -- the serial port seems to hang up. Even if I restart the .exe, the serial port no longer reads data.

I can get it restarted in one of two ways: 1) unplugging and re-plugging the USB serial cable or 2) manually going in to the Device Manager and doing a "disable" and then "enable". In either cases, the serial port begins to read the data properly again. This seems to suggest the problem is not at the serial data transmitter.

I am aware that I can use DevCon to do the disable/enable operations in software. However, this seems a Klutzy way of solving this problem.

Any ideas appreciated.

What I have tried:

I have tried to clear the InBuffer and OutBuffer for the port but this has no effect.
Posted
Updated 13-Nov-18 7:34am

Usbser.sys still seems to be buggy. A workaround for debugging can be, to connect your device via a usb hub.
See also the discussion here: Checking whether usbser.sys is still working/polling a COM port/CDC device[^]
   
After a bit of further experimenting, I found a purely software solution to re-starting the stuck USB serial port. The solution of 1) manually doing a disable/enable in the Device Manager and 2) manually unplugginh/replugging the USB cable was not suitable for operational use -- I need a purely software solution w/o user interventiion. I attempted to use the DevCon to do the disable/enable -- however, on my computer, the results were that the devcon disable step required a reboot in order to finish. This was also deemed not suitable for operations because of the time to do the computer reboot

Finally, I attempted to use devcon's restart procedure. This seems to do the trick. So now I always do a restart after I detect the presence of the serial port device. This takes a negligible amount of time - but always seems to start a stuck USB serial port.

Does anyone have any idea as to what is actually going on here?
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900