news.utdallas.edu!tamsun.tamu.edu!cs.utexas.edu!sun-barr!news2me.EBay.Sun.COM!jethro.Corp.Sun.COM!eric.arnold@sun.com Tue Mar 23 14:14:47 CST 1993
Article: 1763 of comp.lang.perl
Xref: feenix.metronet.com comp.lang.perl:1763
Path: feenix.metronet.com!news.utdallas.edu!tamsun.tamu.edu!cs.utexas.edu!sun-barr!news2me.EBay.Sun.COM!jethro.Corp.Sun.COM!eric.arnold@sun.com
From: eric.arnold@sun.com
Newsgroups: comp.lang.perl
#Subject: Re: Perl and MODEMS
Date: 23 Mar 1993 18:38:00 GMT
Organization: Sun Microsystems, Inc.
Lines: 61
Distribution: world
Message-ID: <1onle8INNaq@jethro.Corp.Sun.COM>
References: <1993Mar22.123448.1272@sei.cmu.edu>
Reply-To: eric.arnold@sun.com
NNTP-Posting-Host: animus.corp.sun.com


This worked for me on a Sun(4.1.2) with a Hayes compatible USRobotics modem:


open(MODEM, "+>/dev/cua0") || die "Can't open /dev/ttyb\n";
system("stty -echo raw >/dev/cua0");

$out = "ATV1E0\r";                      # make sure modem is set to
                                        # send an "OK" instead of "0"

syswrite(MODEM, $out, length($out) ) ;  # could also do non-buffered "print"
sleep(1);                               # wait for modem to respond
sysread(MODEM, $in, 1000);              # better than $i = <MODEM>
                                        # since it gets all data at
                                        # once, including extra newlines,
                                        # but doesn't hang, like @i = <MODEM>;

print "($in)\n";

if ($in =~ /OK/ ) {                     # do this instead of $in eq "OK"
                                        # because modem may send other junk
        print "OK received\n";
} else {
        print "OK NOT received\n";
}


In article 1272@sei.cmu.edu, hsm@sei.cmu.edu (Scott Matthews) writes:
>
>Hi everybody,
>
>I have tried (unsuccessfully) for the last week to get Perl to do basic data communications via a modem in the UNIX environment.  Problem is, the Perl manual we have (wall and schwartz) doesnt specify how to do this.  Could someone tell me BRIEFLY what I have to be doing?
>
>I had been trying something like this, but have no idea if it is right...
>
>#!/usr/projects/CF/bin/perl4.019
>
>local($in,$temp);
>
>$temp = "AT\n";
>$in = '';
>
>open(MODEM, '/dev/ttyb') || die "Can't open /dev/ttyb\n";
>write(MODEM, $temp, length($temp));
>read(MODEM, $in, 10);
>
>print $in,"\n";
>
>if ($in eq 'OK') {
>        print "OK received\n";
>} else {
>        print "OK NOT received\n";
>}
>
>
>any help appreciated..
>scott






