Subject: Re: Detecting a closed circuit
To: None <netbsd-help@netbsd.org>
From: James K. Lowden <jklowden@schemamania.org>
List: netbsd-help
Date: 12/05/2002 23:47:40
On Thu, 5 Dec 2002 12:11:00 -0500, Andrew Brown <atatat@atatdot.net>
wrote:
> >The UPS in our machine room provides a pair of wires which are an open 
> >circuit when on line power and a closed circuit when on battery power. 
> >I'd like to detect this on a NetBSD/i386 box so sysadmins can be
> >notified via pager when we go onto UPS.  I'd prefer if it could be
> >detected on two different boxes for failover, but one box would work.
> 
> off the top of my head (upon which i am not wearing any sort of
> electrical engineering hat), i'd say that the closed circuit could be
> used to drive a relay that would connect the...uh...ctr line to the
> dcd line on a serial port.  or something like that.

I can't tell a relay from an oscilloscope, which might be why I don't
think you need one.  

"man termios" says when you open a terminal file the process normally
blocks "until a connection is established ... [as] indicated by the
assertion of the hardware CARRIER DETECT (CD) line".  

So, suppose your circuit-that-closes-on-batter-power tied CD to something
already high, say, DTR.  Order of events becomes:

Wire everything up.
Start program that opens the terminal device.
Program blocks, awaiting "connection".
Wait for blackout.
[time passes...]
Blackout.
Circuit closes, raising CD.
Program unblocks, calls in the National Guard, whatever.

I think this would work for two machines.  In terms of RS-232, assuming
these machines are within 100 feet of each other, I don't see any reason
you couldn't tie their DTRs together and their CDs together, and bridge
them both with the same close-on-battery curcuit.  

It looks easy from here, but I never did any such thing.  And, see, no
relay. :)

--jkl