Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Answer: How to read the RS-232 lines?

( #76566=categorized answer: print w/ replies, xml ) Need Help??

Q&A > input and output > How to read the RS-232 lines? contributed by kb2yht

I use Device::SerialPort for talking to the PIC UART:
use Device::SerialPort; my $port = Device::SerialPort->new( "/dev/ttyS0" ); $port->baudrate(9600); $port->databits(8); $port->stopbits(1); $port->parity("none"); my $string = ''; my $more = 1; while($more) { my $pass = $port->write('S$'); my $end_seen = 0; while ( not $end_seen ) { local $_ = $port->input; if ( $_ ne '' ) { if ( m/S:/ ) { # string start $string = $_; } elsif ( m/:$/ ) { # string end $string .= $_; print $string; # deal with the final string $end_seen=1; $more=0; } else { $string .= $_; } } } }
Be warned - If you are trying to get something out cleanly in one try, it will probably not work. I found that I have to interrogate the PIC over and over to keep the UART alive and talking to me.

Comment on Answer: How to read the RS-232 lines?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (14)
As of 2015-07-07 19:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls