none
How to programmatically load/unload USB HOST Client driver in WEC7 from user application RRS feed

  • Question

  • We are implementing the USB Host Test client driver in WEC7 for special device. There are basically three Host Test Client drivers and one will be loaded and active at a time.

    We are having user mode application that interacts with USB device through one of the Test client driver. We are implementing command -updatedriver in this user mode application.  To update the driver we need to unloaded all the instances of currently loaded test client driver and then load the require client driver for all the connected test devices.

    I have searched and tried several options but could not find proper way of unloading/loading the USB host test client driver from user mode application.

    Please let me know if anyone has suggestion here.

    Regards,

    Rakesh.

    Friday, June 14, 2013 9:10 AM

Answers

  • Thanks for information. I have found the way to do this. My USB Test device is a special device and it has a vendor command (Disconnect after specified time and reconnect). I have used this vendor command to instruct the device to disconnect and reconnect on the bus. Before this I have updated the Host Client driver registry setting for the updated driver to load on next attach. it works
    fine as of now.

    Rakesh.


    Friday, June 14, 2013 12:38 PM

All replies

  • AFAIK there is no direct way to do that. Whenever the device detach is happening, the client driver will be unloaded and whenever the device attach happen the driver will be loaded again. if your client devices are permanently fixed, you can simulate the detach and attach some how to unload and load the client driver.

    Vinoth.R

    www.e-consystems.com

    http://vinoth-vinothblog.blogspot.com


    Friday, June 14, 2013 11:37 AM
  • Thanks for information. I have found the way to do this. My USB Test device is a special device and it has a vendor command (Disconnect after specified time and reconnect). I have used this vendor command to instruct the device to disconnect and reconnect on the bus. Before this I have updated the Host Client driver registry setting for the updated driver to load on next attach. it works
    fine as of now.

    Rakesh.


    Friday, June 14, 2013 12:38 PM
  • Hi Rakesh,

    My requirement is almost exactly same as yours in the posts mentioned by you above. Can you pls let me know the exact steps that you have followed for this. I need to select the usb client /class driver based on the user inputs and load it. prior to this i need to uninstall the previously loaded ones.

    thanks,

    Vasagan

    Tuesday, October 29, 2013 7:40 AM
  • Here's i code snippet i wrote based upon bruce blogs. (credit goes to him, i only modified it a bit)

    #if defined(UNDER_CE)	
    		//only do this for wince !
    		//we need to make sure usbser is loaded, we do this by unloading hcd1, hcd2, hcd3 and hcd4
    		//this forces a reenumeration and the driver gets loaded !
    		int itiration=0;
    		while(itiration < 4)
    		{
    			LPWSTR pszToken;
    			if(itiration == 0){ pszToken = L"hcd0:";}
    			else if(itiration == 1){ pszToken = L"hcd1:";}
    			else if(itiration == 2){ pszToken = L"hcd2:";}
    			else if(itiration == 3){ pszToken = L"hcd3:";}
    			else if(itiration == 4){ pszToken = L"hcd4:";}
    
    			DEVMGR_DEVICE_INFORMATION devInfo = {0};
    			LPWSTR pszDeviceKey = NULL;
    			devInfo.dwSize = sizeof(devInfo);
    			HANDLE hFind = FindFirstDevice(DeviceSearchByLegacyName, pszToken, &devInfo);
    			if (INVALID_HANDLE_VALUE != hFind)
    			{
    				// Clean up find handle
    				FindClose(hFind);
    				// Store driver registry key
    				pszDeviceKey = wcsdup(devInfo.szDeviceKey);
    				// Unload driver
    				RETAILMSG(1, (L"Found driver \"%s\", unloading...\r\n", devInfo.szLegacyName));
    				DeactivateDevice(devInfo.hDevice);
    
    				::Sleep(500);
    				if (pszDeviceKey)
    				{
    					// Reload driver
    					RETAILMSG(1, (L"Reloading from \"%s\"...\r\n", pszDeviceKey));
    					ActivateDeviceEx(pszDeviceKey, NULL, 0, NULL);
    				}
    			}
    			::Sleep(100);
    			itiration++;
    		}
    #endif

    This will unload the hcd drivers and reload them. This will force a re-enumeration of all connected devices.

    It's not exactly what you are looking for but i think you can use this as a start. 

    Hope this helps :)



    • Edited by Kevin Deckx Wednesday, October 30, 2013 2:51 PM
    • Proposed as answer by Kevin Deckx Thursday, October 31, 2013 2:11 PM
    Wednesday, October 30, 2013 2:49 PM
  • Funny, I opened this thread because I was going to suggest something like that.

    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com

    • Proposed as answer by Kevin Deckx Thursday, October 31, 2013 2:11 PM
    Wednesday, October 30, 2013 5:42 PM
    Moderator