I emailed the author of the GPS-Perl module and he suggested to use the alarm function. so I tried it out with the code below but, it still hung on the get_position so maybe perlmonks has a suggestion.
sub gps {
my $gps_device;
while (1) {
goto END if $die == 1;
if ($gps_start == 1) {
$gps_device = GPS::NMEA->new(Port => $gps, Baud => 4800) o
+r die;
my $timeout = 5;
while (1){
#stops the warnings in the GPS device module
local $^W = 0;
print "before\n";
eval {
local $SIG{ALRM} = sub {die "GPS Device has timed
+out\n"};
alarm $timeout;
($ns,$lat,$ew,$lon) = $gps_device->get_position;
#warn $@ if $@;
alarm 0;
};
die if $@ && $@ ne "GPS Device has timed out\n";
if ($@){
print "WARNING\n";
}
else{
print "nope\n";
}
#($ns,$lat,$ew,$lon) = $gps_device->get_position;
print "after\n";
print "$die\n";
goto END if $die == 1;
last if $gps_start == 0;
sleep 3;
}
undef $gps_device;
} else {sleep 4}
}
END:
}
|