I'm a newbie for perl programming and serial port coding.
The raw data will be output to serial port every 30 seconds.
I use sysread() to read the raw data through serial port.
Each binary data block has different size.
But all of the data block has the same structure, ASCII Header+Binary data+Enter.
Following is one of binary data blocks' example,
$PASHR,PBN,<PBN structure><Enter>
---------- ------------- -----
^ ^ ^
| | |
ASCII Header Binary Data 0x0D 0x0A
I have tow problems with reading binary data through serial port
1. If the last byte of the binary data is 0x0D,
the logged data will miss a 0x0D character. For example,
raw data
$PASHR,PBN, ... ... , 0x0D 0x0D 0x0A
logged data
$PASHR,PBN, ... ... , 0x0D 0x0A
If the last byte of the binary data isn't 0x0D,
I could log the data block without missing anying.
It sounds like that 0x0D will be ignored under certern sort of conditon
2. sysread(STDIN,$Buff,$BuffLen) returned immediately whenever new data arrived serial port,
but $Buff only hold a few of data not the whole complete data block.
Before I save the data to file, I have to filter and process some messages.
How could I get the whole complete data block?
Any ideas?
Thanks
Edit: g0n - replaced pre tags with code tags
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.