I've written a little keyboard to UART script as a first step to something more complex. The following code will let me send data from a PuTTY terminal over the serial connection, display it (STDOUT), and send a period back over the UART. In other words, the UART connection is working.

However, if I uncomment the "my $outchar=<>;" line, everything stops working. I suspect this is because it's blocking. I've also tried replacing the line with a "my $outchar=getc();" line. This works a little better in that the characters coming in over the serial port eventually print, but only if a couple characters are typed on STDIN. This despite the `stty cbreak` instruction.

use warnings; use strict; use IO::Termios (); $| = 1; my $fh = IO::Termios->open('/dev/ttyAPP4', '115200,8,n,1') or die "IO::Termios->open: $!"; `stty cbreak`; print $fh "Begin\n\r"; while(1){ my $inchar=<$fh>; # my $outchar=<>; if($inchar){ print $inchar; print $fh "."; } # if($outchar){ # print $fh $outchar; # } }

Is there a non-blocking approach to doing what I'm after? I managed to get the IO:Termios module installed, though it was a little nightmarish. I dread having to add another module. :p

Thanks in advance for any advice!

Calvin

In reply to problem with simple STDIN to UART script by CSTJr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.