in reply to Continusously reading from serial port

I agree with targetsmart ... up to a point:

Assuming appendLoggedFile does what it says on the tin, I can't see that that call can be problemmatic since (I assume) it's constantly writing to a file on the file system - if it were problemmatic i.e. the file system is full, then it wouldn't be possible to get the thing working by restarting - unless, of course, your script resets the output file before going into the loop i.e. outside the scope of the snippet you provide.

If the behaviour of both readXML and writeValueXML were to be disclosed, then that opens up the possibility of discounting either, or both, of them as being the source(s) of your troubles.

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: Continusously reading from serial port
by rustybar (Novice) on Apr 19, 2009 at 02:52 UTC

    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!