shuting down a computer

Discussion in 'General Electronics Chat' started by bug13, Aug 22, 2016.

  1. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    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!!
     
  2. tcmtech

    Well-Known Member

    Nov 4, 2013
    2,029
    1,617
    Have you been to the UPS units manufacturer's website to look for their downloads for that sort of stuff?
     
  3. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    They don't seem to do 12V UPS.
     
  4. markdem

    Member

    Jul 31, 2013
    73
    38
    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: Aug 22, 2016
  5. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    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
     
  6. markdem

    Member

    Jul 31, 2013
    73
    38
    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"?
     
  7. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,669
    804
    Why not do it the easy way and simply hook up a relay across the shutdown button?
     
  8. markdem

    Member

    Jul 31, 2013
    73
    38
    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 :)
     
  9. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    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.
     
  10. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    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.
     
  11. markdem

    Member

    Jul 31, 2013
    73
    38
    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?
     
  12. GopherT

    AAC Fanatic!

    Nov 23, 2012
    5,979
    3,686
    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").
     
  13. MrSoftware

    Member

    Oct 29, 2013
    497
    122
    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.
     
  14. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    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.
     
  15. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    I will look into this option
     
  16. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    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.
     
  17. MrAl

    Well-Known Member

    Jun 17, 2014
    2,418
    488
    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().
     
  18. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,669
    804
    I guess that running
    Code (Text):
    1. shutdown -s -t 0 -f
    should do the trick
     
  19. markdem

    Member

    Jul 31, 2013
    73
    38
    Sorry, for some resign I thought you where building the whole thing. In this case, carry on :)

    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
     
  20. MrSoftware

    Member

    Oct 29, 2013
    497
    122
    Once the actual shutting down begins,it cannot be stopped.you can only stop it during the delay time, if you used the -t option.
     
Loading...