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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.