Thread: detect power supply

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    23

    detect power supply

    previously i was writting a code to ping a websever to check if the server was down. and now from the program i will need to check if the power supply to a server is down, if it was, the UPS will be activated to supply power.

    anyone know that how i could detect the power while UPS is up using C language. what function that i should include?

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    In a Windows environment, you may want to check out WMI Win32_UninterruptiblePowerSupply.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    how about linux?

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    UPS stands for what?

    Theres no specific C function that will accomplish this. I would assume your going to have to parse system information saved by the operating system. Your best bet is probably to look at some source code from other projects that have done this. And see what they look for. I'm not even sure if you will be able to detect this from the sever itself. In my mind I'm thinking of a server with a backup genterator incase of power outage. which I really can't see as to how you would know where power was coming from. Unless there was some sort of switch that sent that info to the system.

    but if you mean, like a laptop when its not plugged in and you can tell its running on battery, than yes its probably possible... check for projects done in KDE and GNOME, they both have power monitor things I believe...just find out the name. Grab the source and start sifting threw ( I doubt it will be an easy task ).

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    UPS stands for what?
    Uninterruptible Power Supply.

    I'll make another assumption that you're probably using an APC system since IMHO, it's the dominant UPS system on the market. If so, you may want to check this APCUPSD link out. The source is available for modification.

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    i'm not quite sure that whether this can check the power...
    Code:
    ioctl(ups_fd, TIOCMBIS, &dtr_bit);
    while(1){
    ioctl(ups_fd, TIOCMGET, &flags);
    if( flags & TIOCM_CAR) //DCD
            {
             syslog(LOG_ALERT, "Power Failure, UPS active.");
            }
            exit(1);
    }
    ]
    this basically is checking the serial port. so i detect the DCD port, if the ups power on meaning dcd in high and the primary power went off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hmm i think i broke something (power supply)
    By MisterSako in forum Tech Board
    Replies: 1
    Last Post: 02-11-2006, 11:32 PM
  2. Problem With My Box
    By HaVoX in forum Tech Board
    Replies: 9
    Last Post: 10-15-2005, 07:38 AM
  3. European Power Supply
    By The Brain in forum Tech Board
    Replies: 6
    Last Post: 08-25-2005, 12:38 AM
  4. Power Supply
    By Mustang5670 in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 01-08-2004, 09:10 AM
  5. power supply?
    By skeptik in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-28-2001, 07:58 PM