.NET USB/Serial com port removal error fix
gilabite
Posts: 20
Hello everyone, not sure if others here have had this problem but I found a way to deal with .NET's "The device is not connected" error that you get if you pull your USB cord out while your com port is still open and figured Id share. I based my project off of Parallax's AN018: "Communication with a PC application" so I will just use it to show how I fixed it, its a .NET error and has nothing to do with Parallax's example. The error happens if the serial port is opened in the PC program and you remove your USB cable (on a USB to serial device) from the PC without closing the com port first. In the example program the error gets thrown in the Timer1_Tick event and will still occur if you just try to wrap the timer events code in a try..catch. After much Googling I found a fix. Instead of copying and pasting the code in here Im just going to attach the fixed VB.NET project there isnt very much to it. I commented each line I added with ' ADDED FOR USB REMOVAL ERROR and then there is a sub added to the end called "Suppress". Oh yeah this was done in VS.NET 2010. Hope it helps someone, took this dummy awhile to figure it out ;D
AN018-QuickStart.zip
AN018-QuickStart.zip
zip
233K