Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

How to read the RS-232 lines?

( #34876=categorized question: print w/ replies, xml ) Need Help??
Contributed by Anonymous Monk on Oct 02, 2000 at 11:11 UTC
Q&A  > input and output


Description:

I am trying to read input from the serial port from a tone-decoding PIC controller, but so far have failed miserably. The incoming number is 6 digits long. Any ideas or examples I might have look at will be most welcome.

Answer: 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.
Answer: How to read the RS-232 lines?
contributed by Anonymous Monk

There is Win32API::CommPort.
Once upon a time I used to write testbed code for hardware I designed. Generally the system control and monitoring was all done on RS-232 ports. We were using Windows, and for at least the last 5 or 6 years that I can recall we always did our testing in the lab with Perl.

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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 taking refuge in the Monastery: (7)
    As of 2014-11-27 19:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (187 votes), past polls