There is a cpl applet to do so ( MC75HostMode.zip's USBConfig.cpl inside USBConfig.cab). I need to be able to switch modes from an application (C, C++, whatsoever). Either I could invoke the cpl as a dll (how? which are the exported functions?), either someone is so kind to send me the source code of this cpl ... The idea is reading a pendrive using an ADP cable. This requires USB host mode. When done, it has to come back to client mode, so both AS and Ethernet cradles work again with the units. Many thanks in advance!
Programmaticaly setting USB mode (host/client) |
5 Replies
I have a customer who would like to use this code in their app. What they are noticing is that if the USB client device that they want to talk to is already attached to the USB cable when they switch to USB Host mode on our device, Windows mobile does not see the client device. You have to either disconnect the USB device and reconnect it, or suspend and wake the Windows Mobile device (MC55 in this case). The same thing happens if you use our USBConfig applet. Does anyone know of a way that they could programatically get the USB port to go looking for client devices after we switch it to host mode? They are using C# but I'll take anything you might have.
Hi JuanAntonio, Nice job. As a suggestion , how about combining the two files into one which will toggle the mode between host and client each time it is run? Best Regards, Ian Hatton
Great suggestion! I have added USBModeToggle.exe to the zip. There is also a new USBMode.exe which works as follows: No arguments, simply returns current mode. Either "CLIENT" or "HOST" as an argument (in any upper/lower cases, no quotes of course) accordingly sets the mode and returns the mode set (0 and 1). Two shortcuts are included (assuming USBmode is in \) as an example. I hope this helps someone...
Here is the part code that you can use to switch between host and client mode. #define USBCONFIG_DEVICE_KEY TEXT("Drivers\\BuiltIn\\OTG\\Settings") #define USB_PORTMODE TEXT("PortMode") #define USB_PORTMODE_EVENT_NAME TEXT("USBOTG/PortModeChangeEvent") If you want to set the terminal to HOST mode, set the "PortMode" value to "1". For Client Mode, set the "PortMode" value to "0". // Set the registry value SetRegValue(HKEY_LOCAL_MACHINE, USBCONFIG_DEVICE_KEY,USB_PORTMODE,dwUSBPortMode); Then Signal ("USBOTG/PortModeChangeEvent") event... // signal event hUSBEvent = CreateEvent(NULL, FALSE, FALSE, USB_PORTMODE_EVENT_NAME); if (NULL != hUSBEvent) { SetEvent(hUSBEvent); CloseHandle(hUSBEvent); hUSBEvent = NULL; } This Should work for you. Regards Saravana
Thanks! It works fine. Please find attached a zip which contains two standalone exe files, one to set USB host mode, the other to set to client mode. Just in case they are helpful for other collegues . Tested fine on a MC75: on client mode it A-Synchs to a PC, on host mode it detects and shows a pendrive (using a female-female USB adaptor).