Hi,
I'm working on a project which requires me to read data from a weather sensor board thorough serial port and log them continuously into a text file. However, I have encounter a weird problem and hope you can help me with this.
I use lookfor to poll for data and it works great. However, after like 1 day of testing, there seems no data coming from the serial port anymore and the program just hang like at the lookfor statement there. Upon restarting the program, everything works fine again. I was wondering why after 1 day of reading from the serial port, the lookfor statement seem not to work anymore. Please advise me on this issue. Thanks!
Below is my partial code:
# Set up the serial port # 9600, 81N on the USB ftdi driver $port = Device::SerialPort->new("/dev/ttyUSB0"); $port->databits(8); $port->baudrate(9600); $port->parity("none"); $port->stopbits(1); $port->read_const_time(100); # const time for read (milliseconds +) $port->read_char_time(5); # avg time between read char $port->lookclear; # empty buffers $count_interval = 0; while (1) { readXML; sleep for the time interval before polling for data $e = $data->{Weather_Data_Interval}; $interval = $e->{value}; # Poll to see if any data is coming in $values = $port->lookfor(); # If we get data, then print it if ($values) { $values =~ s/#//g; $values =~ s/\$//g; $values =~ s/\r//g; @vars = split(/,/,$values); # high frequency logging writeValueXML; $count_interval++; # for displaying in website in the requested time inte +rval if($count_interval == $interval){ appendLoggedFile; $count_interval = 0; } #print "$values\n"; } }
In reply to Continusously reading from serial port by rustybar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |