Subject: Re: simple serial port program
To: Dan McMahill <dmcmahill@NetBSD.org>
From: Andrew Smallshaw <andrews@sdf.lonestar.org>
List: netbsd-users
Date: 07/06/2006 13:17:05
On Sat, Jun 24, 2006 at 01:28:05PM -0400, Dan McMahill wrote:
> anyone have a simple program that monitors the handshaking lines on a
> serial port and can detect when one of them drops? I'm wanting to do
> some simple monitoring where I'll connect RTS and CTS, set 1 high and
> monitor when the other goes low. The connection will be made by a
> circuit which detects certain bad events like water on my basement floor
> and will email me at work and also to my phone.
A few years ago I constructed a device that works in a similar manner to
what you have in mind - that was to warn of power failiure since my UPS
at the time lacked a port for this. The basic idea I used was to keep
CTS high (ISTR RS-232 is active low) so when I wrote data (anything -
we're not monitoring the data lines) to the serial port the controlling
process would block. When a particular condition arose, ie power
failiure in my case, the data would get 'sent' and the process would
unblock and was then free to carry out the rest of its programmed
actions.
This also means that the controlling software can be very simple: a
shell script will do nicely, although I did write a C program to handle
this. You can find it at http://andrews.freeshell.org/pmon.tar.gz if
you want to see what I did.
Two words of warning though: that code was written for SCO UnixWare so
may need some slight tweaking in regards paths and device names, and I
never got round to actually finishing it. It works fine to shutdown
the system but code that relates to power coming back on doesn't work
since to do the job properly requires non-blocking I/O which is a
little more complex.
--
Andrew Smallshaw
andrews@sdf.lonestar.org