Click here to get back home

win32::SerialPort are_match just won't work

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
win32::SerialPort are_match just won't work gormanst 02-15-2006
Get Chitika Premium
Posted by gormanst on February 15, 2006, 8:05 pm
Please log in for more thread options


All,

I have a simple program. All it is trying to do is issue the "AT"
attention command and grab the OK that is the result of the command
using are_match. It never works. I have tried every permutation of the
regex, seriously like 15 different tries. Please, if you can, tell me
what I am doing wrong! I am going to bang my head into the wall soon.

Thanks in advance.





X?X?X?X?X?X?X??X?X?X?X?X?X?XCODE?X?X?X?X?X?X?X?X?X?X?X?X?X?X?
#!/usr/bin/perl -w
use strict;

use Win32::SerialPort 0.19;

my $ob;
my $file = "COM1_test.cfg";
sub what_is_this( $ );
// Debug function to look inside unknown return....
sub what_is_this( $ )
{
my $item = shift;
my $length = length($item);
my @characters = split(//,$item);

my $temp = $item;

$temp =~ tr/\n/N/;
$temp =~ tr/\r/R/;

my $a = 1;


}
// Standard Cut/Paste waitfor from CPAN examples......
sub waitfor {
my $timeout = Win32::GetTickCount() + (1000 * shift);
$ob->lookclear; # clear buffers
my $gotit = "";

for (;;) {
return unless (defined ($gotit = $ob->streamline));
if ($gotit ne "")
{
my ($found, $end) = $ob->lastlook;
return $found;
}
if($ob->reset_error)
{
return"ERROR";
}
if(Win32::GetTickCount() > $timeout)
{
my ($match, $after, $pattern, $instead) = $ob->lastlook;
what_is_this($instead);
print "match \t<".$match.">\nafter \t<".$after .">\npattern
\t<".$pattern.">\ninstead \t<".$instead.">\n";
return "TIMEOUT";
}
}
}
/// EXECUTION STARTS HERE....

$ob = Win32::SerialPort->start ($file) or die
"Can't start $file\n";

$ob->error_msg(1); # use built-in error messages
$ob->user_msg(1);

$ob->are_match("BUSY","CONNECT","NO DIALTONE",
"ERROR","RING",
"NO CARRIER","NO ANSWER","-re",
'/.*(OK).*/');


my $reset = 1;
while($reset)
{
my $command = "AT";
print "Sending <$command>\n";
$ob->write($command ."\r");
# Wait one second for a response
my $resp = waitfor(1);
if($resp ne "" && $resp =~ /OK/)
{
printf "Received <%s>\n", $resp;
$reset = 0;
}
$ob->write("+++\r");
print "...\n";
}


Posted by Dr.Ruud on February 15, 2006, 9:23 pm
Please log in for more thread options


gormanst schreef:

> I have a simple program. All it is trying to do is issue the "AT"
> attention command and grab the OK that is the result of the command
> using are_match. It never works.

You don't mention that you have a working modem attached.

Did you test with HyperTerminal (or alike)? Is the COM1_test.cfg OK?


> I have tried every permutation of the
> regex, seriously like 15 different tries. Please, if you can, tell me
> what I am doing wrong! I am going to bang my head into the wall soon.

Why do you think that a regex is involved in the problem?


> if($resp ne "" && $resp =~ /OK/)
> {
> printf "Received <%s>\n", $resp;
> $reset = 0;
> }

You might make that

if ($resp ne "") {
printf "Received <%s>\n", $resp;
$reset = 0 if $resp =~ /OK/;
}

for testing. Also for testing, add a "\n" member to are_match().


The '/.*(OK).*/' member of the are_match() can be written as '/OK/', so
you don't need a regex for that at all.

See also example 7 here:
http://www.foo.be/docs/tpj/issues/vol4_1/tpj0401-0020.html

If all fails, do a factory reset of the modem. Check the registers (like
s3 and s4) for strange values. Also try a ';' before the end-<CR> of the
AT-command: "AT;\r". Test manually with a program like HyperTerminal.

--
Affijn, Ruud

"Gewoon is een tijger."


Similar ThreadsPosted
Need help with Win32::SerialPort August 13, 2004, 5:43 am
help on win32::serialport June 4, 2007, 5:12 pm
Please help on win32::serialport July 13, 2007, 12:41 pm
Help need about Win32::SerialPort December 2, 2008, 2:58 pm
problem in using win32::SerialPort September 7, 2007, 2:27 am
Win32::serialport and Windows NT 4 July 31, 2007, 6:08 pm
win32::api doesn't work? January 18, 2005, 11:47 pm
No response from printer using Win32::SerialPort October 11, 2006, 11:36 am
hiding Win32::SerialPort->start( ... ) error messages April 19, 2005, 2:27 am
Does Win32::Perms $PermsObj->Remove( $User ) Work? June 22, 2005, 1:23 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap