views:

1417

answers:

10

There is some easily available information on finding the status of a battery, or weather it's charging or not. (GetSystemPowerStatus API or System.Windows.Forms.SystemInformation.PowerStatus).

I want to be able to stop a battery from charging based on some criteria, e.g. battery power > 20%.

Is there an API to do this?

+5  A: 

I think it's impossible, because you have need some API for battery or battery charger.

And this API can provide to you manufacturer of notebook and battery or battery charger support this.

MicTech
Marking as the "best" answer
Marcel
I wonder when (or if) we will ever see a hardware manufacturer which provides every possible aspect of his designs to programmatically achieve anything! Being stopped by hardware is so uncool.
Kensai
@Kensai - imagine the havok that malware could wreak! Destroy your battery as well as stealing your personal info!
Coxy
+1  A: 

I think MiCTech is right. I dont think it is possible but here are some resources which you might useful.

Shoban
+2  A: 

I honestly don't know, but I'd have a look at the APM or ACPI APIs.

Other than that, the only option I can think of right now is a USB controlled robotic arm that ejects the battery when you need to stop charging, but that's probably not what you are looking for, and borders on the complicator's glove in terms of level of over-engineering. :)

Jack Leow
A: 

But for example Vista won't charge battery if it is unplugged and then plugged while it's capacity is above 96% so it means that in can be accessed and manipulated somehow.

Renesis
Where did you get that information?
Aardvark
It happens on my laptop, whenever I unplug it and plug it again if the capacity is over 96% it says, plugged in, not charging.If I then unplug and let it discharge below 96%, and then plug in again it will charge to 100%.
Renesis
I'd like that behavior, but would like to set the % to something else, e.g. 20%
Marcel
**@Renesis:** Why do you think Windows is responsible for such behavior? I would rather think the BIOS/battery itself is responsible for this, and Vista simply reporting the facts.
Jay
It seems that Vista probably isn't responsible but bios. But I'm wondering how this is done on IBM thinkpads.
Renesis
IBM (or Lenovo now) Thinkpads have their own drivers to control battery charging. If you build your own hardware and write your own drivers, you can get it to do anything you want.
Eclipse
+1  A: 

One of the options is to get hold of the device(I) for battery (Microsoft ACPI-Compliant Control Method Battery). Listen for PowerNotification events forever. On each notification check the PowerStatus of the battery. There are APIs for all of the above purposes in .Net and win32

Keep the device(I) disabled as long as the powerstatus is >threshold. Enable it as soon as goes below that or when you are not on AC power (i.e. before removing AC power, your continuously monitoring software should enable that battery device - or you manually enable it).

hmm,...this is a very buggy solution, but it can achieve what you want, although you have to be very careful.

Trilok
+2  A: 

I use Sony Vaio. It has a utility called Battery Care Function which allows you to control the charging level.

isara
A: 

I would just get a UPS and programatically tell it to cut all power... most should have an interface for doing this. Otherwise, as someone already said - a computer-controlled power strip would do it ^^

I've actually played with this idea when I was testing/writing about way too many new laptop models a while ago and the battery testing was annoying to set up, monitor and analyze.

I wrote an app that would do exactly everything (setup, listening, measuring, reporting) except unplugging the power and then replugging it and starting the computer again...

Oskar Duveborn
+1  A: 

I think it's possible, because it was patented by IBM - patent no. 7570015.

Not sure if there's a Windows API available for that.

Matt
Software patents are evil. This is absurd to patent such an abstract idea. Same like patenting idea of crossing the street depending on the color of the traffic lights.
Developer Art
Luckily, those patents are not valid in EU.
Matt
+1  A: 

You can swap for my battery if you like. It used to last 5 hours, now it only lasts for 1, so it never charges beyond 20% of its original capacity :-)

Jason Williams
A: 

open the device manager.... look for battery.... right click> disable

moh