Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

problem with simple STDIN to UART script

by CSTJr (Initiate)
on May 23, 2018 at 16:42 UTC ( #1215107=perlquestion: print w/replies, xml ) Need Help??
CSTJr has asked for the wisdom of the Perl Monks concerning the following question:

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!


Replies are listed 'Best First'.
Re: problem with simple STDIN to UART script
by haukex (Canon) on May 23, 2018 at 16:55 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1215107]
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-11-13 04:39 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (149 votes). Check out past polls.