Página 1 de 3

[DLL] Battery 1.5.0.0

Publicado: 31 Mar 2013 12:31
por Ceone
Imagen

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".
Código:
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.."%");
Descarga:
1.0.0.0
HIDE: ON
Hidebb Message Hidden Description


1.5.0.0
HIDE: ON
Hidebb Message Hidden Description

Re: [DLL] Battery 1.0.0.0

Publicado: 31 Mar 2013 13:57
por mecivic
Thank you

Re: [DLL] Battery 1.0.0.0

Publicado: 31 Mar 2013 21:21
por sattel
Gracias....

Re: [DLL] Battery 1.0.0.0

Publicado: 01 Abr 2013 07:30
por tam
Thank you

Publicado: 02 Abr 2013 09:25
por hniust
gracias

Publicado: 02 Abr 2013 10:05
por Ceone
En breve actualizare esta DLL, modificare las funciones que devuelven string para que devuelvan valores numéricos, de este modo podrán ser adaptadas con mayor facilidad a cualquier idioma.

Un Saludo Ceone.

Publicado: 02 Abr 2013 11:00
por abood1987
thanks

Publicado: 02 Abr 2013 21:21
por Paneitor
gracias

Publicado: 03 Abr 2013 13:20
por Ceone
Actualizado a 1.5.0.0

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".
Descarga:
1.5.0.0
HIDE: ON
Hidebb Message Hidden Description

Re: [DLL] Battery 1.5.0.0

Publicado: 05 Abr 2013 10:30
por Haitham.2012
Thank you for what you offer us amazing ideas

Re: [DLL] Battery 1.5.0.0

Publicado: 05 Abr 2013 14:57
por Haitham.2012
there bug :

1 - full life time always = -1

2 - life remaining = Minutes only ,

i mean if battery life remaining = 4 h : 25 m

your dll result = 25 min

can you fix it

Publicado: 05 Abr 2013 14:59
por Ceone
Haitham.2012 escribió:there bug :

1 - full life time always = -1

2 - life remaining = Minutes only ,

i mean if battery life remaining = 4 h : 25 m

your dll result = 25 min

can you fix it
thanks for report im working in it.... ;)

Publicado: 06 Abr 2013 13:00
por xxsolracxx
gracias

Publicado: 07 Abr 2013 19:01
por Haitham.2012
We waiting the file .... ceone

Thank you

Publicado: 08 Abr 2013 01:03
por FRAPIDS
Gracias

Publicado: 11 Abr 2013 12:46
por dangngocnguyenit
:normas: good

Re: [DLL] Battery 1.5.0.0

Publicado: 10 May 2013 20:47
por ETS
great work :)

Publicado: 24 May 2013 02:10
por Holly
I will try

Publicado: 30 Ago 2013 21:35
por chakal03
thanks

Publicado: 03 Sep 2013 16:46
por patch
Any news on the fix?