.NET Framework - How to check the power supply

Asked By Michael Meyer on 10-Feb-08 05:43 AM
Hi,

I am looking for a possibility to check the power supply of my PDA. I am
using the .netCF 2.0.

Regards

Michael

--
http://www.mchme.de




bpbro replied on 10-Feb-08 05:54 AM
Michael Meyer skrev:
Define "check"?

You can read the BatteryLevel, BatteryState and such using
Microsoft.WindowsMobile.Status

--
Bjørn Brox
Arun replied on 12-Feb-08 06:25 AM
Hi Michael,

Managed code:
You have Microsoft.WindowsMobile.Status

BatteryLevel batteryLevel =3D SystemState.PowerBatteryStrength;
BatteryState batteryState =3D SystemState.PowerBatteryState;

string batteryLevelText;
switch (batteryLevel)
{
case BatteryLevel.VeryLow:
batteryLevelText =3D "Battery Level: Very Low";
break;
case BatteryLevel.Low:
batteryLevelText =3D "Battery Level: Low";
break;
case BatteryLevel.Medium:
batteryLevelText =3D "Battery Level: Medium";
break;
case BatteryLevel.High:
batteryLevelText =3D "Battery Level: High";
break;
case BatteryLevel.VeryHigh:
batteryLevelText =3D "Battery Level: Very High";
break;
}

string batteryStateText =3D "Battery State: ";
if ((batteryState & BatteryState.Normal) =3D=3D BatteryState.Normal)
batteryStateText +=3D "Normal";
if ((batteryState & BatteryState.NotPresent) =3D=3D
BatteryState.NotPresent)
batteryStateText +=3D "Not Present";
if ((batteryState & BatteryState.Charging) =3D=3D BatteryState.Charging)
batteryStateText +=3D "Charging";
if ((batteryState & BatteryState.Low) =3D=3D BatteryState.Low)
batteryStateText +=3D "Low";
if ((batteryState & BatteryState.Critical) =3D=3D
BatteryState.ChargCriticaling)
batteryStateText +=3D "Critical";

Ref: http://msdn2.microsoft.com/en-us/library/aa456240.aspx#yctiwy_snapi_par=
t1_topic3

UnManaged:
[DllImport("coredll.dll", EntryPoint =3D "GetSystemPowerStatusEx",
SetLastError =3D true)]
private static extern bool
GetSystemPowerStatusEx(BatteryPowerStatus pStatus, bool flag);

Hope this helps,

Cheers,
Arun
Michael Meyer replied on 11-Feb-08 06:00 PM
Arun schrieb:

Thanks for your help.

Michael


--
http://www.mchme.de