How to check the power supply

  • Thread starter Thread starter Michael Meyer
  • Start date Start date
M

Michael Meyer

Hi,

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

Regards

Michael
 
Michael Meyer skrev:
Hi,

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

Regards

Michael
Define "check"?

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

Managed code:
You have Microsoft.WindowsMobile.Status

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

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

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

Ref: http://msdn2.microsoft.com/en-us/library/aa456240.aspx#yctiwy_snapi_part1_topic3

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

Hope this helps,

Cheers,
Arun
 
Arun said:
Hi Michael,

Managed code:
You have Microsoft.WindowsMobile.Status

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

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

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

Ref: http://msdn2.microsoft.com/en-us/library/aa456240.aspx#yctiwy_snapi_part1_topic3

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

Hope this helps,

Cheers,
Arun


Michael Meyer skrev:> Hi,

Define "check"?

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

Thanks for your help.

Michael
 
Back
Top