![Imagen](http://img132.imageshack.us/img132/8470/capturahl.png)
Buenas amigos de AMSSpecialist.com siguiendo con Visual Studio vi una opción interesante que te informa de algunos parámetros de la batería y como AMS que yo recuerde no lleva nada sobre este tema he pensado en hacer un dll que nos informe del estado de la batería, espero que os guste.
Funciones:
- Status - retorno Number: 1: "Charging", 2: "Critical", 3: "High", 4: "Low", 5: "NoSystemBattery", 6: "Unknown", 0: "No Case".
- FullLifetime - retorno Number: devuelve el periodo de duración de la carga.
- LifePercent - retorno Number: devuelve el tanto por ciento de batería.
- LifeRemaining - retorno Number: devuelve en periodo de duración restante de la batería.
- PowerLineState - retorno Number: 1: "Offline", 2: "Online", 3: "Unknown" 0: "No Case".
UnmanagedExports.cs:
using System;
using RGiesecke.DllExport;
using System.Windows.Forms;
namespace Battery
{
internal static class BatteryClass
{
[DllExport("Status", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int Status()
{
int ChargeStatus;
switch (SystemInformation.PowerStatus.BatteryChargeStatus)
{
case BatteryChargeStatus.Charging:
ChargeStatus = 1;
break;
case BatteryChargeStatus.Critical:
ChargeStatus = 2;
break;
case BatteryChargeStatus.High:
ChargeStatus = 3;
break;
case BatteryChargeStatus.Low:
ChargeStatus = 4;
break;
case BatteryChargeStatus.NoSystemBattery:
ChargeStatus = 5;
break;
case BatteryChargeStatus.Unknown:
ChargeStatus = 6;
break;
default:
ChargeStatus = 0;
break;
}
/// Return int:
///1: "Charging"
///2: "Critical"
///3: "High"
///4: "Low"
///5: "NoSystemBattery"
///6: "Unknown"
///0: "No Case"
return ChargeStatus;
}
[DllExport("FullLifetime", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int FullLifetime()
{
return SystemInformation.PowerStatus.BatteryFullLifetime;
}
[DllExport("LifePercent", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int LifePercent()
{
return Convert.ToInt16(100 * SystemInformation.PowerStatus.BatteryLifePercent);
}
[DllExport("LifeRemaining", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int LifeRemaining()
{
return TimeSpan.FromSeconds(SystemInformation.PowerStatus.BatteryLifeRemaining).Minutes;
}
[DllExport("PowerLineState", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int PowerLineState()
{
int PLStatus;
switch (SystemInformation.PowerStatus.PowerLineStatus)
{
case PowerLineStatus.Offline:
PLStatus = 1;
break;
case PowerLineStatus.Online:
PLStatus = 2;
break;
case PowerLineStatus.Unknown:
PLStatus = 3;
break;
default:
PLStatus = 0;
break;
}
/// Return int:
/// 1: "Offline"
/// 2: "Online"
/// 3: "Unknown"
/// 0: "No Case"
return PLStatus;
}
}
}
Ejemplo DLL.CallFunction:
DLLPath = _SourceFolder.."\\AutoPlay\\Docs\\Battery.dll";
result = DLL.CallFunction(DLLPath, "LifePercent", "", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);
InputSetText("Input1", result.."%");
1.0.0.0
1.5.0.0