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.