"Fossies" - the Fresh Open Source Software Archive

Member "sendpage-1.001001/examples/modemtest" (3 Jan 2008, 3799 Bytes) of package /linux/privat/old/sendpage-1.001001.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/local/bin/perl
    2 #
    3 # This tool is used to check how Device::SerialPort is behaving on
    4 # your machine.  It will list all the possible values for each function
    5 # as it runs.  Edit this tool to test various settings.
    6 #
    7 # $Id: modemtest 181 2005-02-22 21:06:59Z nemies $
    8 #
    9 # Copyright (C) 2000-2004 Kees Cook
   10 # kees@outflux.net, http://outflux.net/
   11 #
   12 # This program is free software; you can redistribute it and/or
   13 # modify it under the terms of the GNU General Public License
   14 # as published by the Free Software Foundation; either version 2
   15 # of the License, or (at your option) any later version.
   16 #
   17 # This program is distributed in the hope that it will be useful,
   18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20 # GNU General Public License for more details.
   21 #
   22 # You should have received a copy of the GNU General Public License
   23 # along with this program; if not, write to the Free Software
   24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   25 # http://www.gnu.org/copyleft/gpl.html
   26 
   27 use Device::SerialPort;
   28 print "Module loaded\n";
   29 
   30 # Edit this for your serial port.  (I was testing under Solaris...)
   31 $port=new Device::SerialPort("/dev/modem") || die "new: $!\n";
   32 print "Port open\n";
   33 
   34 # Are the ioctls loaded?
   35 $bool=$port->can_ioctl();
   36 print "can ioctl: ",($bool ? "Yes" : "No"),"\n";
   37 if (!$bool) {
   38         die "The rest of this test is useless without ioctl methods.\n";
   39 }
   40 
   41 # Handshaking
   42 @handshakes=$port->handshake;
   43 print "Handshakes:\n";
   44 grep(print("\t$_\n"),sort(@handshakes));
   45 $handshake=$port->handshake("none");
   46 print "Port handshake: $handshake\n";
   47 
   48 # Baud rate
   49 @bauds=$port->baudrate;
   50 print "Bauds:\n";
   51 grep(print("\t$_\n"),sort(@bauds));
   52 $baudrate=$port->baudrate("9600");
   53 print "Port baud: $baudrate\n";
   54 
   55 # Databits
   56 @databits=$port->databits;
   57 print "Databits:\n";
   58 grep(print("\t$_\n"),sort(@databits));
   59 $databits=$port->databits(8);
   60 print "Port databits: $databits\n";
   61 
   62 # Parity
   63 @parity=$port->parity;
   64 print "Parity:\n";
   65 grep(print("\t$_\n"),sort(@parity));
   66 $parity=$port->parity("none");
   67 print "Port parity: $parity\n";
   68 
   69 # Stopbits
   70 @stopbits=$port->stopbits;
   71 print "Stopbits:\n";
   72 grep(print("\t$_\n"),sort(@stopbits));
   73 $stopbits=$port->stopbits(1);
   74 print "Port stopbits: $stopbits\n";
   75 
   76 # Flip on DTR and RTS
   77 $dtr=$port->dtr_active(1);
   78 $rts=$port->rts_active(1);
   79 print "Port DTR ($dtr) and RTS ($rts) activated\n";
   80 
   81 $rts=$port->rts_active(0);
   82 print "Flipped RTS to off ($rts) (pausing for 5 seconds)\n";
   83 sleep 5;
   84 $rts=$port->rts_active(1);
   85 print "Flipped RTS to on ($rts)\n";
   86 
   87 # Flip OFF dtr
   88 $dtr=$port->dtr_active(0);
   89 print "Flipped DTR to off ($dtr) (pausing for 5 seconds)\n";
   90 sleep 5;
   91 $dtr=$port->dtr_active(1);
   92 print "Flipped DTR to on ($dtr)\n";
   93 
   94 # Just in case: reset our timing and buffers
   95 $port->lookclear();
   96 $port->read_const_time(100);
   97 $port->read_char_time(5);
   98 
   99 # Read a chunk
  100 sleep 1;
  101 ($count,$str)=$port->read(1);
  102 $cnt=$count;
  103 while ($count>0) {
  104     ($count,$got)=$port->read(1);
  105     $str.=$got;
  106     $cnt+=$count;
  107 }
  108 print "read: $cnt\n";
  109 print "-:$str:-\n";
  110 
  111 # Write an INIT to the modem
  112 ($count)=$port->write("ATZ\r");
  113 print "written: $count\n";
  114 
  115 # Read a chunk
  116 sleep 1;
  117 ($count,$str)=$port->read(1);
  118 $cnt=$count;
  119 while ($count>0) {
  120     ($count,$got)=$port->read(1);
  121     $str.=$got;
  122     $cnt+=$count;
  123 }
  124 print "read: $cnt\n";
  125 print "-:$str:-\n";
  126 
  127 # and another
  128 sleep 1;
  129 ($count,$str)=$port->read(1);
  130 $cnt=$count;
  131 while ($count>0) {
  132     ($count,$got)=$port->read(1);
  133     $str.=$got;
  134     $cnt+=$count;
  135 }
  136 print "read: $cnt\n";
  137 print "-:$str:-\n";
  138 
  139 # and one more
  140 sleep 1;
  141 ($count,$str)=$port->read(1);
  142 $cnt=$count;
  143 while ($count>0) {
  144     ($count,$got)=$port->read(1);
  145     $str.=$got;
  146     $cnt+=$count;
  147 }
  148 print "read: $cnt\n";
  149 print "-:$str:-\n";
  150 
  151 # close the port
  152 undef $port;
  153 print "Port closed\n";