win32::SerialPort are_match just won"t work
am 16.02.2006 02:05:11 von gormanstAll,
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";
}