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!
Calvin
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problem with simple STDIN to UART script
by haukex (Archbishop) on May 23, 2018 at 16:55 UTC |