Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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 (Abbot) 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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2018-07-22 22:44 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (457 votes). Check out past polls.