Greetings patient Monks.
I am parsing and converting a real-time binary data stream that is coming in on the serial port (COM port). This is working fine, but every 4th byte is a 'sample delimiter' that I need to check and confirm. Currently I am using a reg exp in the ARE_MATCH function of the serialport module to grab the first 3 bytes:
$ob->are_match("-re", '\x{0a}');
The problem with this is that if one of the first 3 bytes is a 0x0a, the match will return too few bytes and mess the whole thing up. Also, if the fourth byte is anything other than 0x0a, we have a problem that we need to know about. So what I need to do is count the number of bytes as they stream in, and check every fourth byte to confirm that it is indeed a 0x0a. This would be easily done if I were reading a file using the READ function. But since I am reading a real-time datastream from the COM port instead, I am puzzled about how to do this. I have tried assigning the COM port a filehandle (with OPEN) and READing that, but of course the COM port is locked by then by the serialport module.
My apologies for the rambling explanation, but I hope that the explanation was sufficient enough to convey the issue.
Many Humble Thanks for reading this query

In reply to Counting bytes in an input stream instead of a file by sawtooth

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.