This is documentation of a fix found in late November 2008.
Our team was plagued by a GPS COTS product that would intermittently not clean up the GPS COM port when closing. An unrecoverable error would occur if our code tried to open the COTS product a second time after it failed to close the port. After going back and forth with the vendor and no solution, it came on us to work around it. I first tried to toggle the power to GPS chip using
SetDevicePower("COM5:", POWER_NAME, 4); //unpowered
SetDevicePower("COM5:", POWER_NAME, 0); //full power
which didn’t seem to do anything. After a lot of searching through MSDN I found these two native calls that saved our release to test. They completely reloaded the driver making the COM port usable again.
BOOL DeactivateDevice(HANDLE hDevice); HANDLE ActivateDevice(LPCWSTR lpszDevKey, DWORD dwClientInfo);
The handle for the device can easily be found in the registry in HKLM\Drivers\Active. Look for your device as a subkey and provide that same name to ActivateDevice to reload the driver.
Leave a comment