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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|