In my experience, getting serial ports working with the higher-level reading functions (also timeouts and graceful closing of the ports) can be quite finicky. In fact, in a recent script I wrote that does something similar to yours, I just read the port one byte at a time and do the buffering myself, it's not the most elegant but it's robust. The code resembles the "EXAMPLE" in Device::SerialPort.

However, from perlvar:

HANDLE->autoflush( EXPR ) ... This has no effect on input buffering. See getc for that.

I don't see you writing to the port anywhere. So I don't think "autoflush" is the right term here, and perhaps you need to explain your problem better: In regards to what is being read/written from the port, what exactly is the expected behaviour, and what behaviour are you getting instead? Perhaps a short sample would help?

How can I create a filehandle for this module that it will always return me the last line from the serial port output?

By "last", do you mean "most recent"? I see a couple of options: Keep the port closed until you actually want to read; continually read the port and just remember the most recent line; or try the lookclear method from Device::SerialPort (although the docs are a little unclear to me whether lookclear will do what you need).


In reply to Re: serial port tied filehandle autoflush by Anonymous Monk
in thread serial port tied filehandle autoflush by kkaiser

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.