Hi thanks for the reply, I thought of it so but then I view the codes and could not find any possibility that they could have cause the hang up. Below are the codes, would appreciate if you all help me take a look.
sub readXML{
# create object
$xml = new XML::Simple (KeyAttr=>[]);
# read XML file
$data = $xml->XMLin($config_path . "sensors.xml");
}
sub writeValueXML{
while(! (-x $config_path . "sensors.xml")){} #wait until other
+ process finish writing the file
system("sudo chmod 644 $config_path" . "sensors.xml"); #set per
+mission for root to rw only (exclusive write)
my $output = new IO::File(">" . $config_path . "sensors.xml");
my $writer = new XML::Writer(OUTPUT => $output);
my $flag = 0;;
$count = 0;
$writer->startTag("Sensors");
while($count < $DATANUM){
#write xml values
$e = $data->{$sensor_type[$count]};
$writer->startTag("$sensor_type[$count]");
$writer->startTag("value");
$writer->characters($vars[$count]);
$writer->endTag("value");
$writer->startTag("threshold");
$writer->characters($e->{threshold});
$writer->endTag("threshold");
$writer->endTag("$sensor_type[$count]");
if(($vars[$count]*1.0) > ($e->{threshold}*1.0)){ #*1 to for
+ce it to float type
if (-e $config_path . "SensorAlert.txt" && !$flag){
while(! (-x $config_path . "SensorAlert.txt")){} #
+wait until other process finish writing the file
unlink($config_path . "SensorAlert.txt"); #set perm
+ission for root to rw only (exclusive write)
}
open WRITEFILE, "+>>", $config_path . "SensorAlert.txt";
print WRITEFILE "$count:$vars[$count]\n";
close(WRITEFILE);
$flag++;
}
$count++;
}
$e = $data->{Weather_Data_Interval};
$writer->startTag("Weather_Data_Interval");
$writer->startTag("value");
$writer->characters($e->{value});
$writer->endTag("value");
$writer->endTag("Weather_Data_Interval");
$writer->endTag("Sensors");
$writer->end();
$output->close();
if($flag){
read_config_file;
if ($config_data[10] ne "Sensors:disabled\n"){
$config_data[10] = "Sensors:true\n";
write_config_file;
}
system("sudo chmod 777 $config_path" . "SensorAlert.txt");
}
system("sudo chmod 777 $config_path" . "sensors.xml");
}
sub appendLoggedFile{
my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $da
+yOfWeek, $dayOfYear, $daylightSavings) = localtime();
$year = 1900 + $yearOffset;
my $theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $month
+s[$month] $dayOfMonth, $year";
open WRITEFILE, "+>>", $data_path . "$months[$month]_$dayOfMonth
+" . "_SensorLog.txt" or die $!;
print WRITEFILE $values . ",\t\t" . $theTime . "\n";
close(WRITEFILE);
}
and roboticus, when the program hang, I end the process and use minicom to read from the port again, and the data is still transmittin. I cannot use 2 programs to read the same port at the same time, as it will say the port is being used by other process right now.
Thanks! |