Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   How do I activate consecutive sysreads to a serial port ? (http://www.velocityreviews.com/forums/t894338-how-do-i-activate-consecutive-sysreads-to-a-serial-port.html)

bell 09-20-2005 11:27 PM

How do I activate consecutive sysreads to a serial port ?
 
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


bell 09-21-2005 01:23 AM

Re: How do I activate consecutive sysreads to a serial port ?
 
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: $!";





bell wrote:
> 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




All times are GMT. The time now is 10:32 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.