From: Juan P. F. G. <jfe...@gm...> - 2007-06-12 19:41:28
|
Hello, I'm trying to expect an modem with cu session but i never got answer from the modem . Here is my ugly code my $command = "cu -s 9600 -l ttyS0"; if ($_[5] eq 'ROOT') { print "Iniciando conexion telnet como ROOTEXPECT \n " if ($debug eq "1"); $rootexpect=Expect->spawn($command, @params) or die "$command: $! FALLO\n"; if ($_[9] eq "MODEM") { my $timeout = "8"; $rootexpect->exp_internal('2'); $rootexpect->expect($timeout, "nnected"); $rootexpect->send("\n"); $rootexpect->send("AT\n"); $rootexpect->expect($timeout,"OK"); my $x; $rootexpect->interact($x, 'XXX'); } } Here is the debug output (Looks like modem is not acepting the \n after AT) spawn id(4): Does `\007Connected.\r\n' match: pattern #1: -ex `nnected'? YES!! Before match string: `\007Co' Match string: `nnected' After match string: `.\r\n' Matchlist: () spawn id(4): list of patterns: #1: -ex `OK' spawn id(4): Does `.\r\n' match: pattern #1: -ex `OK'? No. spawn id(4): Does `.\r\n\nAT\n' match: pattern #1: -ex `OK'? No. With the script @ interact mode AT responds fine at OK at OK at OK I connected a cisco router console port instead the modem, and changed the expect commands: $rootexpect->exp_internal('2'); $rootexpect->expect($timeout, "nnected"); $rootexpect->send("\n"); $rootexpect->expect($tiemout, "outer"); $rootexpect->send("ter le 0\n"); $rootexpect->send("sh ver\n"); $rootexpect->expect($timeout,"isco"); my $x; $rootexpect->interact($x, 'XXX'); And the router successfully returns the output of the command 'sh ver'... Any Ideas? Are there better terminals than cu, which can be used to interact with expect-perl? Thanks in advance |
From: Austin S. <te...@of...> - 2007-06-12 20:27:06
|
On Tue, Jun 12, 2007 at 12:41:25PM -0700, Juan Pablo Feria Gomez wrote: > Hello, I'm trying to expect an modem with cu session but i never got > answer from the modem . > > Here is my ugly code > > my $command = "cu -s 9600 -l ttyS0"; > if ($_[5] eq 'ROOT') { > print "Iniciando conexion telnet como ROOTEXPECT \n " > if ($debug eq "1"); > $rootexpect=Expect->spawn($command, @params) or die > "$command: $! FALLO\n"; > if ($_[9] eq "MODEM") { > my $timeout = "8"; > > $rootexpect->exp_internal('2'); > $rootexpect->expect($timeout, "nnected"); > $rootexpect->send("\n"); > $rootexpect->send("AT\n"); ^^ I suspect you need to send cu \r instead of \n. Austin |
From: Juan P. F. G. <jfe...@gm...> - 2007-06-12 21:30:08
|
^^ > I suspect you need to send cu \r instead of \n. > > Austin Thanks for your answer Austin:... I had no luck sending \r :(.. here is the output: Code $rootexpect->exp_internal('2'); $rootexpect->expect($taim, "nnected"); $rootexpect->send("\r"); $rootexpect->send("AT\r"); $rootexpect->expect($taim,"OK"); my $x; $rootexpect->interact($x, 'XXX'); Output: Sending '\r' to spawn id(4) at /usr/share/perl5/Expect.pm line 1223 Expect::print('Expect=GLOB(0x8ab1888)', '\x{d}') called at ./getconfig.devel.pl line 541 main::connect2router() called at ./getconfig.devel.pl line 355 main::grabrouterdata() called at ./getconfig.devel.pl line 175 main::BUSCAROUTERS() called at ./getconfig.devel.pl line 190 Sending 'AT\r' to spawn id(4) at /usr/share/perl5/Expect.pm line 1223 Expect::print('Expect=GLOB(0x8ab1888)', 'AT\x{d}') called at ./getconfig.devel.pl line 544 main::connect2router() called at ./getconfig.devel.pl line 355 main::grabrouterdata() called at ./getconfig.devel.pl line 175 main::BUSCAROUTERS() called at ./getconfig.devel.pl line 190 Starting EXPECT pattern matching... at /usr/share/perl5/Expect.pm line 533 Expect::expect('Expect=GLOB(0x8ab1888)', 8, 'OK') called at ./getconfig.devel.pl line 546 main::connect2router() called at ./getconfig.devel.pl line 355 main::grabrouterdata() called at ./getconfig.devel.pl line 175 main::BUSCAROUTERS() called at ./getconfig.devel.pl line 190 spawn id(4): list of patterns: #1: -ex `OK' spawn id(4): Does `.\r\n' match: pattern #1: -ex `OK'? No. spawn id(4): Does `.\r\n\rAT\r' match: pattern #1: -ex `OK'? No. Thanks again... |
From: Juan P. F. G. <jfe...@gm...> - 2007-06-13 01:17:06
|
Hi all, just to share the solution to my problem... $rootexpect->exp_internal('2'); $rootexpect->expect($taim, "nnected"); $rootexpect->send("AT\015\012"); $rootexpect->expect($taim,"OK"); $rootexpect->send("ATDT 99999999\015\012"); my $x; $rootexpect->interact($x, 'XXX'); Now is dialing fine :) from: http://www.rocketaware.com/perl/perlfaq8/How_do_I_read_and_write_the_seri.htm end of line Some devices will be expecting a ``\r'' at the end of each line rather than a ``\n''. In some ports of perl, ``\r'' and ``\n'' are different from their usual (Unix) ASCII values of ``\012'' and ``\015''. You may have to give the numeric values you want directly, using octal (``\015''), hex (``0x0D''), or as a control-character specification (``\cM''). print DEV "atv1\012"; # wrong, for some devices print DEV "atv1\015"; # right, for some devices Even though with normal text files, a ``\n'' will do the trick, there is still no unified scheme for terminating a line that is portable between Unix, DOS/Win, and Macintosh, except to terminate ALL line ends with ``\015\012'', and strip what you don't need from the output. This applies especially to socket I/O and autoflushing, discussed next. |