http://www.perlmonks.org?node_id=1009655

ccherri has asked for the wisdom of the Perl Monks concerning the following question:

I am opening a serial port to a device that is already streaming data at 9600B. Occasionally I get a "Buffer Overrun detected" message, which I do not know how to get out of and so have to ^C and start over.

I have tried the 'lookclear' and 'purge_all' method (both return a '1') and it still happens.

Even when I read part of the buffer, kill the program, and restart (with data still in the buffer) it may still happen

$AppMainBoard_Port = Win32::SerialPort->start ($app_cfgfile) @result=$AppMainBoard_Port->lookclear; print "Result: @result\n"; @result=$AppMainBoard_Port->purge_all; print "Result: @result\n"; for ($i=0 ;; ) { if ( $c = $AppMainBoard_Port -> input) { print "$c"; do_other-stuff; } }

I will get a print of $result, but often get a buffer overrun as soon as I get to 'input'

Since starting this post, I tried changing '->input' to '->read(4096)' which SEEMS to have solved the problem so far, but would be happy to hear what the Monks have to say!

Thanks, Chris

Replies are listed 'Best First'.
Re: Serial Buffer Overrun
by jmlynesjr (Deacon) on Dec 20, 2012 at 02:48 UTC

    Buffer Overrun indicates that the UART's input buffer was not read(emptied) when the next character was received. At 9600 baud a character shows up about every millisecond. Your system occasionally gets busy and doesn't get back to service the UART in time. Other options are to try at 4800 baud if that is an option or use xon/xoff or rts/cts handshaking/flow control.

    James

    There's never enough time to do it right, but always enough time to do it over...