Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve dual batteries status?

 Dim power As PowerStatus = SystemInformation.PowerStatus
 Dim percent As Single = power.BatteryLifePercent

or

PowerStatus power = SystemInformation.PowerStatus;
float percent = power.BatteryLifePercent;

(I would prefer a vb answer as that is what the application is written in but can convert so c# is fine if you dont know vb)

I understand that the above will give me the battery percentage remaining - BUT I have a tablet that is 'hot swappable' (it has a main battery then a small 5 minute battery that runs the tablet while you swap batteries on it) - how would I find the status of the second battery?

I am looking for something like SystemInformation.PowerStatus(0) but I have NO idea what I am actually trying to find and I must be having a Google block as I cannot find anything.

like image 712
Graham Ritchie Avatar asked Mar 06 '14 07:03

Graham Ritchie


People also ask

Is a dual battery system worth it?

For longer trips, a traditional dual battery system is often preferred. If you're planning to be off-grid for long periods of time or be constantly on the move, a dual battery system allows you to tailor the system to your specific needs.

Why would you need two batteries in a truck?

Diesel trucks have two batteries, as opposed to most cars, which have only one. Diesel trucks need two batteries so they can crank at a higher amp. This is needed because a diesel engine demands a high-resistance load to start successfully.


2 Answers

You can use WMI and Win32 to get the battery levels.

Try this:

ObjectQuery query = new ObjectQuery("Select * FROM Win32_Battery");

foreach (ManagementObject o in new ManagementObjectSearcher(query).Get())
{
    uint level = (uint)o.Properties["EstimatedChargeRemaining"].Value;
} 
like image 178
Patrick Hofman Avatar answered Oct 06 '22 21:10

Patrick Hofman


In case of multiple batteries, you can make use of WMI. Specifically, Win32_Battery class.However, this will be a bit slower than using PowerStatus class.

like image 21
danish Avatar answered Oct 06 '22 20:10

danish