How do I activate consecutive sysreads to a serial port ?

Discussion in 'Perl Misc' started by bell, Sep 21, 2005.

  1. bell

    bell Guest

    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, Sep 21, 2005
    #1
    1. Advertising

  2. bell

    bell Guest

    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
    bell, Sep 21, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rasha
    Replies:
    0
    Views:
    1,679
    Rasha
    Mar 17, 2005
  2. Pom
    Replies:
    2
    Views:
    1,617
    Bas-i
    Jan 31, 2007
  3. Max Kotasek
    Replies:
    4
    Views:
    961
    Max Kotasek
    Apr 9, 2010
  4. Junkone
    Replies:
    2
    Views:
    194
    Jarmo Pertman
    Oct 27, 2010
  5. msalerno
    Replies:
    3
    Views:
    401
    Ilmari Karonen
    Jul 14, 2005
Loading...

Share This Page