Hi,
I'm writting rs232 communication program that communicates over binary strings. I get start word 0x55aa and then length and then data and crc at the end.
I send data reqest, device responds with data. But every now and then first byte is lost (then start byte and length are corrupted). Although I could ignore faulty received messages, I'd like to get into this more deeply - to see what happens.. Device works ok with win32 communication program, so it correctly sends all bytes when responding...
I'm using Device::SerialPort.
I have this in code :
$count_out = $ob->write($send);
warn "write failed\n" unless ($count_out);
warn "write incomplete\n" if ( $count_out != length($send) );
$result = waitfor_binary_response ();
and in waitfor_binary_response ():
($count_in, $result) = $ob->read(12);
warn "read unsuccessful 1\n" unless ($count_in == 12);
$header_binary = $result;
my($start, $byte_length, $from, $to) = unpack("vvVV", $result);
and every few seconds I get 12 bytes, but 1st byte is missing - so all other values are "shifted" by 1 byte and corrupted. Binary communication is taking place as fast as possible - but I'm not sure if being too fast is the problem. Sending and listening is positioned one after another so can't find good explanation for losing first byte...
Are there any other timing settings or something else I'm missing ? Is there any better (buffered) way to read serial port ?
Thanks in advance,
regards,
Rob.
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.