How do I activate consecutive sysreads to a serial port ?

B

bell

Sorry if this has been already resolved; but I have a problem getting
both sysreads to work.
I do transmit but only one sysread is active.
Why do I never see the print ( "rec 001 $in $rx \n"); execute ?
ENVIRONMENT: CYGWIN with Perl 5.8.6
EXPERIENCE in Perl: much less than intermediate..
Any help is greatly appreciated.

use strict;
use warnings;
use Fcntl;



sysopen (TTYIN, "/dev/ttyS0", O_RDWR )
or die "can't open /dev/ttyS0: $!";

open(PORT_TX, "+>&TTYIN")
or die "can't dup PORT_TX: $!";

my $ofh = select(PORT_TX); $| = 1; select($ofh);

print PORT_TX "aaaa";
my $in;
my $rx;
my $timeout = 100;


eval {
local $SIG{ALRM} = sub { die "timeout" };
alarm($timeout);
$in= sysread (TTYIN, $rx, 1);
};
alarm(0);

print "sysREAD-001\n";
print ( "rec 001 $in $rx \n");


eval {
local $SIG{ALRM} = sub { die "timeout" };
alarm($timeout);
$in= sysread (TTYIN, $rx, 1);
};
alarm(0);

print "sysREAD-002\n";
print ( "rec 002 $in $rx \n");

print PORT_TX "dddd";

close ( PORT_TX) or die "child can't closing COM1: $!";

Most of this code is webish
 
B

bell

The fix

use strict;
use warnings;
use Fcntl;


sysopen (TTYIN, "/dev/ttyS0", O_RDWR )
or die "can't open /dev/ttyS0: $!";


open(PORT_TX, "+>&TTYIN")
or die "can't dup PORT_TX: $!";


my $ofh = select(PORT_TX); $| = 1; select($ofh);


print PORT_TX "aaaa";
my $in;
my $rx;
my $timeout = 10;


eval {
local $SIG{ALRM} = sub { die "timeout" };
alarm($timeout);
eval {
$in= sysread (TTYIN, $rx, 1)
or die "sysread 001 died:$!";
};
alarm(0);
};
alarm(0);


print "sysREAD-001\n";
print ( "rec 001 $in $rx \n");


eval {
local $SIG{ALRM} = sub { die "timeout" };
alarm($timeout);
eval {
$in= sysread (TTYIN, $rx, 1)
or die "sysread 001 died:$!";
};
alarm(0);
};
alarm(0);


print "sysREAD-002\n";
print ( "rec 002 $in $rx \n");


print PORT_TX "dddd";


close ( PORT_TX) or die "child can't closing COM1: $!";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top