Michael C. Toren on 5 Nov 2004 16:51:02 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] ok..Trying to get PERL to read/write to a tty port...


On Fri, Nov 05, 2004 at 11:27:24AM -0500, George Gallen wrote:
> I don't get any error on file open but the process hangs.  I used stty
> to set the port to 9600/e/7/1

Another approach would be to use the POSIX::Termios module[0] to set the
appropriate serial port settings after opening the device in your Perl
script.

> Any ideas.

[..]

> print SERIALOUT "W\r";

One potential problem is that the print statement above is not triggering
a write(2) on the open file descriptor, as you have not turned autoflush
on, and have not sent a "\n".  Try changing "\r" to "\n", or doing either:

	use IO::Handle;
	SERIALOUT->autoflush(1);

or:

	my $oldfh = select SERIALOUT;
	$| = 1;
	select $oldfh;

> my $charin = getc(SERIALOUT);
> print $charin "\n\n";

You'll probably also want to check the return value of print and getc, to
determine if there were any errors writing to or reading from the serial
port.

-mct

[0]: http://search.cpan.org/~nwclark/perl-5.8.5/ext/POSIX/POSIX.pod#POSIX::Termios

-- 
perl -e'$u="\4\5\6";sub H{8*($_[1]%79)+($_[0]%8)}sub G{vec$u,H(@_),1}sub S{vec
($n,H(@_),1)=$_[2]}$_=q^{P`clear`;for$iX){PG($iY)?"O":" "forX8);P"\n"}for$iX){
forX8){$c=scalar grep{G@$_}[$i-1Y-1Z-1YZ-1Y+1ZY-1ZY+1Z+1Y-1Z+1YZ+1Y+1];S$iY,G(
$iY)?$c=~/[23]/?1:0:$c==3?1:0}}$u=$n;select$M,$C,$T,.2;redo}^;s/Z/],[\$i/g;s/Y
/,\$_/xg;s/X/(0..7/g;s/P/print+/g;eval' #     Michael C. Toren <mct@toren.net>

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug