View Single Post
Old Jan 10th, 2006, 7:47 AM   #1
jerryleo
Newbie
 
Join Date: Jan 2006
Posts: 2
Rep Power: 0 jerryleo is on a distinguished road
Data logging problem from the serial port

I use a perl scritp to log the real time output from Ashech Z-Surveyor GPS receiver through the serial port on a FC3 box.

It worked fine at the beginning. After a few minutes, it couldn't read data through serial port any more , and only logged a few KB data. But I can make sure that GPS receiver outputs data to serial port every 30 seconds continuously. I have no idea how to do it.

Any ideas?

Thanks a lot!


Here are the main parts of data logging script

sub LogData
{

$SessNum =0;
$BuffLen = 1024;
$TempFileName = ".temp.log";

$SiteName = ReadVar($ConfigFile,"SiteName","____");

$SessDuration = ReadVar($ConfigFile,"SessDuration",60); # Minutes
$SessDuration *= 60*1000; # ms

print STDERR "Open log file $TempFileName\n";
open(LOGFILE,">$TempFileName") or die "Can not open log file $TempFileName";

$SIG{INT} = \&catch_zap; # Install signall handler


print "\$PASHQ,SNV\n\r"; # Query ephemeris

undef $EndTime;

LoggingData: while (not $Killed)
{
$ReadLen = 0;
$timeout = 60;
eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required
alarm $timeout;
$ReadLen = read(STDIN,$Buff,$BuffLen);
alarm 0;
};

if ( $ReadLen > 0 )
{
($Time,$LastPbnPos) = CheckTime($Buff,$EndTime);
$SetEndTime = 0;
$SetEndTime = 1 if ( not defined($EndTime) and defined($Time) );
$SetEndTime = 2 if ( defined $LastPbnPos) ;
$EndTime = $Time + ($SessDuration - $Time % $SessDuration ) if ( $SetEndTime );

if ( $SetEndTime == 2 )
{
# Write part of the buffer containing the PBN
# with the given yime tag to the file and then close it
$SplitPoint = $LastPbnPos + 58;
$SplitPoint = $ReadLen if $SplitPoint > $ReadLen;
$Head = substr($Buff,0,$SplitPoint);
$Tail = substr($Buff,$SplitPoint);
syswrite(LOGFILE,$Head,$SplitPoint);

print STDERR "Close log file $TempFileName\n";
close(LOGFILE) or die "Can not close log file $FileName";

# Give the valid name to the temporary file
$FileName = ComposeLogFileName($SiteName,$SessNum);
print STDERR "Rename $TempFileName to $FileName\n";
rename ($TempFileName,$FileName) or die "Can not rename files\n";

# Open the new file, write remainder of the buffer to it
print STDERR "Open log file $TempFileName\n";
open(LOGFILE,">$TempFileName") or die "Can not open file $TempFileName";
syswrite(LOGFILE,$Tail,$ReadLen - $SplitPoint);

# Make sure we have ephemeris in the new file
print "\$PASHQ,SNV\n\r";
++$SessNum;
}
else
{
syswrite(LOGFILE,$Buff,$ReadLen);
}
}
}

if ( $Killed )
{
print STDERR "Log processed killed, clean up...\n";
print STDERR "Close log file $TempFileName\n";
close(LOGFILE) or die "Can not close log file $FileName";

# Give the valid name to the temporary file
$FileName = ComposeLogFileName("____",$SessNum);
print STDERR "Rename $TempFileName to $FileName\n";
rename ($TempFileName,$FileName) or die "Can not rename files\n";

print STDERR "Delete ID file [$LogIdFile]\n";
unlink $LogIdFile;
}
}

sub catch_zap {
$Killed = 1;
}
jerryleo is offline   Reply With Quote