Computer States

Discussion in 'Ruby' started by Brandon B., Dec 18, 2009.

  1. Brandon B.

    Brandon B. Guest

    Hey all,

    I'm looking for a way to programmatically wake the computer up from
    sleep state, preferably at a certain time, rather than after certain
    amount of time, but ill make due with whatever solution there might be.
    any suggestions or help is much appreciated. i've been searching for a
    couple weeks on and off for a way to do this, and can only find the
    wake-on-lan, or wake-on wan (would work fine for some, but id rather
    this feature not fail should the user not have a router or an internet

    Thanks in Advance,

    Brandon B., Dec 18, 2009
    1. Advertisements

  2. I suspect most BIOSes have this feature, but I have no idea how to access it
    programmatically. I did find this:

    I have no idea how well it works, though, and it's probably going to be
    David Masover, Dec 18, 2009
    1. Advertisements

  3. Brandon B.

    Brandon B. Guest

    I suspect most BIOSes have this feature, but I have no idea how to
    i was thinking about bios features, but being able to access and change
    certain features of it will either give the user alot of hassle or
    myself in having to change things on the many different bios versions
    there are, if it is even possible to change it programmatically, not to
    mention the warning label that would have to be included by going that
    will definetly have to check this out, might be able to salvage
    something from it, with a bit of research.
    i would like to have it be cross-platform, but i dont have a problem
    with testing for the OS is need be, thanks David.
    Brandon B., Dec 18, 2009
  4. You probably want to access
    How you do that is OS specific, since it's fairly lowlevel. A very
    superficial search for "Ruby ACPI library" didn't produce any real hits,
    so it might be that you have to go low level to call the Windows, Linux,
    and Mac OS X APIs for ACPI.

    However, it is my understanding that ACPI can't wake a computer from a
    Hibernating/Suspend to Disk (ACPI S4) from within the sleep state.

    Hope this helps at least a little.
    Phillip Gawlowski, Dec 18, 2009
  5. Brandon B.

    Brandon B. Guest

    You probably want to access
    yea, i expected as much, which if fine, i just dont know how to go about
    doing so... maybe there is a way to send a "wake-up" packet to the ram,
    or nvram, and have it execute it from there at a given time? dont know
    too much about what can and cant be performed like that so, if im way
    off base, please forgive me.
    yea it has helped, thank you. i have found a linux wake up procedure
    that i might be able to tether to my needs, if it works

    require 'time'
    wake_time = Time.parse(ARGV[0])
    wake_time += 24 * 60 * 60 if wake_time <'/proc/acpi/alarm', 'w') {|f| f << wake_time.utc.strftime
    (%Y-%m-%d %H:%M:%S')}
    system('/etc/acpi/ force')

    like i said, this is for linux, obviously, which if it works takes out
    one of my issues, but what i dont know is if there is anything like the
    above file locations for windows or mac?

    well, ill keep looking around, maybe i can dig up something else using
    this as a search tool, any additional help or advice is much
    Brandon B., Dec 18, 2009
  6. You'd've to read the ACPI spec, I'm afraid, what does what, if you want
    to go really, really low level, since I stay away from the Dark Arts. ;)
    With Windows, there's the win32api gem (pre-installed in the Once Click
    Installer and/or the new RubyInstaller), providing access to the Windows
    API, so you can call the Windows system calls to send the computer to
    sleep. Or, maybe, you can shell out to "shutdown", but I'm not well
    versed in Windows CLI tools, at least to send to computer to sleep. I'm
    pretty sure that WakeOn needs an API call, though.

    With Macs, and this is from my dim memory, there's CocoaRuby (I think
    that's what it is called, googling for "cocoa ruby" should unearth
    something), which accomplishes roughly the same as the win32api gem.

    Keep in mind, you can run into binary compatibility issues on Windows
    (depending on the Ruby variant installed, there's mswin32, and mingw32,
    the latter being included in the new RubyInstaller), as well as on Mac
    (depending on the Mac Os X API changes).

    And that ain't even touching on JRuby. So, "true" cross-platform
    compatibility will be difficult, to say the least.

    Mind, just pick the Ruby versions you are able to report, and you'll be
    fine, don't let me scare you. :)
    Phillip Gawlowski, Dec 18, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.