demystification of "chat" - re: /dev/tty* + modem test logic

Tim Writer tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org
Mon Aug 25 23:24:36 UTC 2003


Max Blanco <blanco-S8qYAnHmZTt34ZA5RureAJ4VBq8PJc8F at public.gmane.org> writes:

> Thanks to Tim and Peter for their demystification of the "chat" command.
> My test logic made no sense as I tried vainly to set up my modem: I had 
> thought "chat" looked at "/dev/modem" implicitly.  Not so - see below.
> A better logic (?) is at end.

See my comments below.

> Tim Writer wrote:
> 
> > Max Blanco <blanco-S8qYAnHmZTt34ZA5RureAJ4VBq8PJc8F at public.gmane.org> writes:
> 
> >
> > > Through which /dev port does "chat" cmd look?
> > >
> > > I can't find this info anywhere in the chat man page. There exists no
> > > "usr/share/doc/chat" directory.
> > 
> > I believe it reads from standard input and writes to standard output.  
> > If you're using it with PPP, pppd arranges to connect its standard input
> > and standard output to the relevant tty.
> 
> On Sat, 23 Aug 2003, Peter L. Peres wrote:
> 
> > 
> > chat talk to its stdin and stdout but it will not work stand-alone, as in:
> > 
> > chat "" ATZ OK </dev/modem >/dev/modem
> > 
> > because the line disipline and buffering need to be set. pppd does this
> > before calling chat. calling chat as above will fail on any machine, in
> > despite of working modem etc. The call will hang (can be interrupted with
> > ^C).
> > 
> 
> I would appreciate helpful comments on this...:
> ---begin untested perl code: "/usr/bin/mdmtst"---
> #!/usr/bin/perl
> print STDOUT "mdmtst: program to test your modem.\n";
> print STDOUT "\tuse at own risk\n";
> #dialout string:
> $mdmstrng="ATL1DT4165551212\n";
> print STDOUT "\tusing: $mdmstrng\n";
> 
> #dmesg check:
> $dmesg=`dmesg | grep tty`;
> print STDOUT "Your kernel says (man dmesg)\n$dmesg\n";
> 
> #tests:
> &mdmctl("ttyS");
> print STDOUT "...deprecated /dev/cua* for ancient distros...\n";
> &mdmctl("cua");
> print STDOUT "Modem test finished.\n";
> 
> sub mdmctl {
> 	my $prefix=$@;
> 	print STDOUT "Testing: $prefix\*\n";
> 	for $i (0..3) {
> 		print STDOUT "\t\/dev\/$prefix$i\n";
> 		open (MDM,">/dev/$prefix$i") or die;
> 		print MDM $mdmstrng;
> 		sleep(2);
> 		close (MDM);
> 	}
> 	print STDOUT "Done $prefix\* tests.\n";
> }
> ---end untested perl code---

In a nutshell, you're trying to cycle through /dev/ttyS{0,1,2,3} in an
attempt to ... what, find your modem?  As noted above, there's more to
working with a modem (or any serial device) than just opening it.  You have
to deal with issues like buffering, inter-character delays, baud rate,
parity, and reading and writing from the same device.  Rather than reinvent
the wheel, I'd suggest using something like minicom or kermit.  If you have
to write a script or you're just interested in learning about it, you should
read Chapter 11 of "Advanced Programming in the UNIX Environment" by Richard
Stevens.

-- 
tim writer <tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org>                                  starnix inc.
tollfree: 1-87-pro-linux                        thornhill, ontario, canada
http://www.starnix.com              professional linux services & products
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list