shuting down a computer

Thread Starter

bug13

Joined Feb 13, 2012
2,002
Hi guys

I want to build a circuit to monitor the voltage of an SLA battery. And be able to shut down a windows base PC safely. What is the best way to talk to a windows base PC?

I am hoping there is a standard UPS protocol that windows use, and my circuit can just talk to windows directly. But I don't seem to find anything about this.

Any ideas?

Thanks guys!!
 

markdem

Joined Jul 31, 2013
113
As Microsoft no longer has a native UPS service, you will need to write one. The this small application would just listen for a command from your circuit and run "shutdown -s - t %u" where %u is time in seconds on the computer.

Here is a good guide to writing a windows service in c#.
http://www.c-sharpcorner.com/upload...lop-and-install-a-windows-service-in-c-sharp/

This should not be very hard at all. Remember that you would need to run the app as a service if you want it to work while no one is logged on.

Not sure if you could find the protocol that APC uses, but I would be it would be faster to write the service app then try to talk to someone else's.

Have fun
 
Last edited:

Thread Starter

bug13

Joined Feb 13, 2012
2,002
As Microsoft no longer has a native UPS service, you will need to write one. The this small application would just listen for a command form your circuit and run "shutdown -s - t %u" where %u is time in seconds on the computer.

Here is a good guide to writing a windows service in c#.
http://www.c-sharpcorner.com/upload...lop-and-install-a-windows-service-in-c-sharp/

This should not be very hard at all. Remember that you would need to run the app as a service if you want it to work while no one is logged on.

Not sure if you could find the protocol that APC uses, but I would be it would be faster to write the service app then try to talk to someone else's.

Have fun
Thanks, look like I have to do it this way. Since I am making my own circuit, what else should I be monitoring, apart from voltage?
Cheers guys
 

markdem

Joined Jul 31, 2013
113
I would say current (both line and battery) and temperature would be nice to know.

I will however ask, why are you building your own UPS and not just using one off the shelf? What do you mean "12v ups"?
 

markdem

Joined Jul 31, 2013
113
Why not do it the easy way and simply hook up a relay across the shutdown button?
Depending what the pc is doing at the time, it may not shutdown as it will wait until the current process is done.
I would say I could write the shutdown app faster then I could wire a relay anyway :)
 

Thread Starter

bug13

Joined Feb 13, 2012
2,002
I would say current (both line and battery) and temperature would be nice to know.

I will however ask, why are you building your own UPS and not just using one off the shelf? What do you mean "12v ups"?
I am not sure if I need to know the currents, could you explain why I need to know the current?

Maybe I shouldn't refer to the little computer I want to back up by a battery as PC. It's a little computer with very low specs, powered by 12VDC. It run one program and one program only. Since it powered by 12VDC, we need to back it up by 12V supply. (Or other way, I am open to better idea)

I don't seem to find a 12VDC backup supply that when the battery is low, is somehow let the computer know, and computer can do normal power down. So when I say "12V UPS", I mean a device can continue to supply my little computer when the main is lost, and be able to tell the computer shutdown safely.
 

Thread Starter

bug13

Joined Feb 13, 2012
2,002
Why not do it the easy way and simply hook up a relay across the shutdown button?
I don't think my little computer support ATX power (it powered by 12VDC), but I will look into it. And also we have program running some database application, we would like a safe power down if possible.
 

markdem

Joined Jul 31, 2013
113
Ah, now I get it. It is a DC powered pc. Now this project makes sense.
It also makes the unit you need to build far easier as you don't need a inverter..

I am not sure if you NEED to measure current, I just said it would be nice to know it. Someone else will need to chime in about what yo need to do to charge the batters.

Has the pc got a internal power supply, or is it external? If external, you could just replace the whole thing with something from here.
https://www.power-supplies-australia.com.au/battery-chargers-ups
If internal, can you pull it out?
I don't think you could build something that cheap unless you already know a design. Some of them have a dry contact to indicate failed AC. All you would need to do is make a small unit to send a command to the pc. Have you got a spare serial or USB port available?
 

GopherT

Joined Nov 23, 2012
8,009
Instead of shutting down, put it to sleep. A relay on the micro switch for closing the lid of a laptop or the standby button (then use the POWER control panel app to set the lid-closed or standby button to "sleep" or "hibernate").
 

MrSoftware

Joined Oct 29, 2013
2,273
You need to know your battery capacity at any given time, and your current rate of consumption, so you can predict how long until the computer looses power unexpectedly. So you can shut it down before that happens. You might need to make a map to track battery voltage vs. current draw. i.e. For any given battery, if it reads 12v under a 1A load then it likely has much less capacity remaining than the same battery showing 12v while under a 20A load. Also the option to hibernate as opposed to actually shut down might be useful.

There are multiple ways to shut down a windows computer, here are just a few:

1) Command line using the shutdown command
2) Programmatically calling ExitWindowsEx. This link will get you started
3) Using the powrprof.dll directly via. rundll. This link will help

Using ExitWindowsEx will likely give you the most control, and since you're writing your own code you can monitor the shutdown progress and take additional actions if things aren't going as planned.
 

Thread Starter

bug13

Joined Feb 13, 2012
2,002
Has the pc got a internal power supply, or is it external? If external, you could just replace the whole thing with something from here.
https://www.power-supplies-australia.com.au/battery-chargers-ups
If internal, can you pull it out?
I don't think you could build something that cheap unless you already know a design. Some of them have a dry contact to indicate failed AC. All you would need to do is make a small unit to send a command to the pc. Have you got a spare serial or USB port available?
The pc use an external power supply.

Yes, we are already using these, and no plan to build a one from scratch. We are only building a simple voltage monitoring circuit which have the ability to communicate the low voltage/power down signal etc.
 

Thread Starter

bug13

Joined Feb 13, 2012
2,002
Instead of shutting down, put it to sleep. A relay on the micro switch for closing the lid of a laptop or the standby button (then use the POWER control panel app to set the lid-closed or standby button to "sleep" or "hibernate").
I will look into this option
 

Thread Starter

bug13

Joined Feb 13, 2012
2,002
You need to know your battery capacity at any given time, and your current rate of consumption, so you can predict how long until the computer looses power unexpectedly. So you can shut it down before that happens. You might need to make a map to track battery voltage vs. current draw. i.e. For any given battery, if it reads 12v under a 1A load then it likely has much less capacity remaining than the same battery showing 12v while under a 20A load. Also the option to hibernate as opposed to actually shut down might be useful.

There are multiple ways to shut down a windows computer, here are just a few:

1) Command line using the shutdown command
2) Programmatically calling ExitWindowsEx. This link will get you started
3) Using the powrprof.dll directly via. rundll. This link will help

Using ExitWindowsEx will likely give you the most control, and since you're writing your own code you can monitor the shutdown progress and take additional actions if things aren't going as planned.
I will properly don't want to make this project too big. As the current draws is not constant, it can change quite a bit. But thanks for the tips about using ExitWindowsEx.
 

MrAl

Joined Jun 17, 2014
13,704
Hi,

Try pressing and holding in the button on the front panel. I think that is the power button. If you press and hold it for a few seconds the computer might shut down.
You may have to change a setting in the Windows settings.
Of course you would use a relay or transistor or something to 'press' the button.
That's how it works on mine.

If it doesnt work that way on yours then you cant do it that way. But if it does, and with your programs running, then it will work with a relay too.

I also used to use the SetSuspendState() API function long ago.
There's also SetSystemPowerState().
 

markdem

Joined Jul 31, 2013
113
The pc use an external power supply.

Yes, we are already using these, and no plan to build a one from scratch. We are only building a simple voltage monitoring circuit which have the ability to communicate the low voltage/power down signal etc.
Sorry, for some resign I thought you where building the whole thing. In this case, carry on :)

I guess that running
Code:
shutdown -s -t 0 -f
should do the trick
Much like my suggestion in #4? With my method bug13 could just estimate runtime after power fail and not have to measure battery voltage. Just run "shutdown \a" to stop the shutdown if the power comes back.
In fact, that's what I would be doing unless you really want to stretch out the runtime after power fail.

Have fun
 
Top