Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Serial Buffer Overrun

by ccherri (Acolyte)
on Dec 19, 2012 at 22:38 UTC ( #1009655=perlquestion: print w/replies, xml ) Need Help??
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 (Hermit) 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.


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1009655]
Approved by marto
Front-paged by Corion
NodeReaper adjusts the cross hairs

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2018-06-18 20:26 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.