#!/usr/local/bin/perl
use POSIX qw(:termios_h :fcntl_h);
if ( "$ARGV[0]" eq "" ){ die "Useage: reset-serial \n";}
$modem = "$ARGV[0]";
sysopen ( MODEM, $modem, O_RDWR | O_NONBLOCK ) || die "reset-serial:$modem: $!\n";
sleep 1;
$mo = POSIX::Termios->new;
$mo->getattr(fileno(MODEM)) or die "reset-serial:getattr: $!\n";
$mo->setlflag($mo->getlflag & ~ECHO);
$mo->setcflag(($mo->getcflag | CREAD | CLOCAL) & ~HUPCL);
$mo->setattr(fileno(MODEM), TCSANOW) or die "reset-serial:setattr: $!\n";
close MODEM
(This was adapted from a program posted to comp.protocols.ppp by James Carlson)
To run a check of a certain serial line to see if there is a modem attached and that modem is answering, try
/usr/sbin/chat -v -t 5 '' AT OK < /dev/ttyS1 > /dev/ttyS1
If this finishes immediately, there is a modem there. If it hangs
for about 5 seconds and then returns, there is not.
If you look at the end of /var/log/messages, there will be a line
stating that chat timed out waiting for the OK.
Here is a script to run the test on all of the serial ports on your
system
Use it by nameing it chk-modem, making it executable, placing it in
root's path, and running
chk-modem
as root.
(Note this script assumes that both chk-modem and reset-serial are in
the same directory.)
#!/bin/sh
DIR="`dirname $0`/"
# Assume both this script and reset-serial in same directory
for i in `ls /dev/ttyS*`
#check all the ttyS serial ports
do
echo
echo Testing $i
if [ -r $i -a -w $i ] ; then
#Make sure port is both readable and writable.
if $DIR/reset-serial $i 2>/dev/null ; then
if /usr/sbin/chat -v -t 2 '' AT OK ; then
echo $i seems to be attached to a modem
else
echo $i does not respond to modem commands
fi
else
echo Serial port $i cannot be reset-- either in use or not a serial port
fi
else
echo $i must be both readable and writable
fi
done