Read notebook battery status

Erel

B4X founder
Staff member
Licensed User
Longtime User
The following code reads the status of a notebook battery:
B4X:
Sub Globals
    'Declare the global variables here.

End Sub

Sub App_Start
    obj.New1(False)
    obj.CreateNew("System.Windows.Forms.SystemInformation" & obj.System_Windows_Forms)
    obj.Value = obj.GetProperty("PowerStatus")

    Msgbox(FindPowerLineStatus, FindBatteryLifePercent)
End Sub

Sub FindBatteryLifePercent
    Return obj.GetProperty("BatteryLifePercent")
End Sub
Sub FindPowerLineStatus
    Return obj.GetProperty("PowerLineStatus") 'returns Offline or Online
End Sub
 

Attachments

  • desktop-battery.sbp
    761 bytes · Views: 455

Byak@

Active Member
Licensed User
or you can use a dzHW.dll
but may be you know how read a cpu usage and ram usage???
 

mjcoon

Well-Known Member
Licensed User
This is about the desktop-target (notebook battery)

Is this also working for getting the battery status of a Windows Mobile device?

My WM5.0 device gives some strange values, but this may be more to do with the hardware and my (attached) code...

Mike.
 

Attachments

  • PowerMonitor.sbp
    3.8 KB · Views: 397

mjcoon

Well-Known Member
Licensed User
You could also look at my PowerStatus library.

Thanks Andrew, I only had v0.9 zip of that library which had no .chm or .cs files.

In the former file, two descriptions seem inconsistent on backup vs. main; is there an error? ...
BackupBatteryLifeTime : Int32 : Returns a value indicating the number of seconds of main battery, if present, life remaining, or –1 if remaining seconds are unknown.

BackupBatteryFullLifeTime : Int32 : Returns the number of seconds of backup battery, if present, life when at full charge, or –1 if full battery lifetime is unknown.


Some of those values are amazing detail; I must have a look at them for my device!

Mike.
 
Top