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