Q: I'd like to minimize power consumption for my system. Is it possible to shut off an installed device, like an 802.11b card, when I'm not using it though code?
That depends on the OS and the driver. Windows CE 4.2 does support device power management, and some device drivers do as well. If you have both, then you're in luck.
The simple way to determine if your device itself supports the required power management APIs, use the Power Control Panel applet. The Device Status tab shows all installed devices that have API support. In the image to the left I've inserted a Cisco PCM340/350 card into a BitsyX running build 4.20.05. You'll see that it comes up as "CISCO1". That name is important, as you'll need to pass it to the power management API (see below).
If you'd like more information on just what the driver needs to support the power management calls, see this MSDN topic.
If your device has power management support, all that is needed to turn it off and back on is the SetDevicePower API. The code below is an example that shuts of the Cisco card for 5 seconds, then turns it back on. Notice the bolded name of the device we retrieved above.
Note that BitsyX build 4.20.05 uses Microsoft's PCX500.dll 802.11 driver, not Cisco's. We've not tested to see if Cisco's driver has the necessary API support.
#include "windows.h"
#include
DWORD PowerOffCisco3X0()
{
// note that the clsid GUID here is from
// [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\Interfaces]
// which is set by OS version in platform.reg
return SetDevicePower(_T("{98C5250D-C29A-4985-AE5F-AFE5367E5006}\\CISCO1"), POWER_NAME, D3);
}
BOOL PowerOnCisco3X0()
{
return SetDevicePower(_T("{98C5250D-C29A-4985-AE5F-AFE5367E5006}\\CISCO1"), POWER_NAME, D0);
}
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
RETAILMSG(1, (_T("ret = 0x%x\\r\\n"), PowerOffCisco3X0()));
Sleep(5000);
RETAILMSG(1, (_T("ret = 0x%x\\r\\n"), PowerOnCisco3X0()));
return 0;
}