A good module to access the serial port is Device::SerialPort in *NIX and Win32::SerialPort on Windows. Their docs as well as googling their names will get you some sample programs which is probably the easiest way to get started, here are some examples: Device::SerialPort Examples.., Reading Data from a Serial Port using Win32::SerialPort

The general approach to read from the serial port is to read it a single byte at a time, unless you know exactly how many bytes you're expecting, in which case you can request that number of bytes from the driver. Make sure to read about the different timeout settings the driver accepts, so that you don't time out too soon or end up waiting for a byte forever in case one gets lost somewhere (which does tend to happen on serial ports). Also note that the modules I mentioned are generally blocking I/O, meaning that your program won't do anything else if it's waiting for data from the serial port. Although I've rarely needed it, there are ways to work around this, but it can be tricky to get right, so looking for help online is very helpful there too.

Lastly, I've found it's important to remember the distinction between bytes and characters, a line which Perl unfortunately blurs a little from time to time. Most serial protocols I've seen express their data in bytes, and you want to keep treating them as such, and not as characters at the Unicode level, until the protocol calls for some explicit decoding of the bytes.


In reply to Re: BP: Serial protocol detection by Anonymous Monk
in thread BP: Serial protocol detection by ademmler

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.