[mdlug] Serial port monitoring -- new answer

Aaron Kulkis akulkis3 at hotpop.com
Thu Jan 31 11:30:13 EST 2008


Drew wrote:
>      I wish to write a script that returns a TRUE value if and only if
> (1) VMware is running, AND (2) the serial port (/dev/ttyS0) is actually
> connected through the modem and phone line to a remote host. To this
> end:
> 
> * How may the state of Carrier Detect be read?
> 
> * If there is no actual modem, but just a straight serial connection
>    using pins 2, 3, and ground, can reading Carrier Detect in that
>    manner be relied upon to return an OFF status?
> 
> 

This isn't complete, but it should point you in the right direction.


$ man ttyS
TTYS(4)              Linux Programmer's Manual              TTYS(4)



NAME
        ttyS - serial terminal lines

DESCRIPTION
        ttyS[0-3] are character devices for the serial terminal lines.

        They are typically created by:

               mknod -m 660 /dev/ttyS0 c 4 64 # base address 0x3f8
               mknod -m 660 /dev/ttyS1 c 4 65 # base address 0x2f8
               mknod -m 660 /dev/ttyS2 c 4 66 # base address 0x3e8
               mknod -m 660 /dev/ttyS3 c 4 67 # base address 0x2e8
               chown root:tty /dev/ttyS[0-3]


FILES
        /dev/ttyS[0-3]

SEE ALSO
        chown(1), getty(1), mknod(1), tty(4), setserial(8)



Linux                             1992-12-19 
    TTYS(4)


$ man 8 setserial
SETSERIAL(8)                                          SETSERIAL(8)



NAME
        setserial - get/set Linux serial port information

SYNOPSIS
        setserial [ -abqvVWz ] device [ parameter1 [ arg ] ] ...

        setserial -g [ -abGv ] device1 ...

DESCRIPTION
        setserial  is a program designed to set and/or report the
        configuration information associated with a serial port.
        This information  includes what I/O port and IRQ a particular
        serial port is using, and whether or not the break key should
        be interpreted as the  Secure  Attention  Key, and so on.

        ....

        hup_notify
	      Notify a process blocked on opening a dial in line
	      when a process has finished using a callout line
	      (either by closing it or by the serial line being
	      hung up) by returning EAGAIN to the open.

               The  application of this parameter is for getty's
	      which are blocked on a serial port's dial in line.
	      This allows the getty to reset the modem (which may
	      have had its configuration modified by the application
	      using the callout device) before  blocking on the
	      open again.

        ^hup_notify
               Do  not  notify a process blocked on opening a dial
	      in line when the callout device is hung up.

"hup" is standard Unix/Linux terminology for "hang up"

also useful (although this requires writing C or C++ code):
$ man 4 tty_ioctl
and look at /usr/include/termios.h which in turn refers to
/usr/include/bits/termios.h


struct termios
   {
     tcflag_t c_iflag;           /* input mode flags */
     tcflag_t c_oflag;           /* output mode flags */
     tcflag_t c_cflag;           /* control mode flags */
     tcflag_t c_lflag;           /* local mode flags */
     cc_t c_line;                        /* line discipline */
     cc_t c_cc[NCCS];            /* control characters */
     speed_t c_ispeed;           /* input speed */
     speed_t c_ospeed;           /* output speed */
#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
#define _HAVE_STRUCT_TERMIOS_C_OSPEED 1
   };

...


/* c_cflag bit meaning */
#ifdef __USE_MISC
# define CBAUD  0010017
#endif
#define  B0     0000000         /* hang up */



>      Then, I want to set up a permanent cron task that runs once a
> minute, executes the above script, and increments a counter (to be
> reset at the beginning of each month) on each TRUE return. How does
> one set this up?
> 
>      I am running Fedora Core 4.





More information about the mdlug mailing list