views:

46

answers:

1

I've wrote a small piece of code that reads the current battery charge/discharge on my laptop. I followed the example code on this MSDN page.

My program updates the information every 100ms (by calling the DeviceIoControl function with IOCTL_BATTERY_QUERY_STATUS as control code) but the read value changes only after 5-10 seconds. For example if I change the screen brightness from the minimum value to the maximum the rate is updated only 5-10 seconds later. I've used Visual C++ 2010 on Windows 7 32-bit.

Does anybody knows how to get a real-time reading of the charge/discharge rate?

+3  A: 

Depending on the accuracy of the sensor, it is likely that the status is only updated by the power device driver every 5-10 seconds or when significant changes take place.

FreshCode
A relatively recent blog post ( http://blogs.msdn.com/b/oldnewthing/archive/2010/09/24/10067119.aspx ) by Raymond Chen seems relevant even though it happens to be in the context of a different API call: "These battery levels come from the hardware itself, so you are at the mercy of whoever manufactured your motherboard. Some laptops update the values at 1-second intervals; others can take 5 seconds or more."
TheUndeadFish
I run the program on another laptop and there I get updates every 2-4 seconds. I've also discovered that some new HP laptop doesn't have that sensor.