Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The problem is not the control sequence

The hints at the link i provided seem to suggest it is in how you are sending the control sequences, that the timeing is very important.

Try this

use Fcntl qw/:DEFAULT/; use IO::Termios (); use IO::Stty (); use IO::Handle; # use IO::Socket; use IO::Select; sysopen my $fh, '/dev/ttyUSB0', O_RDWR or die "sysopen: $!"; my $handle = IO::Termios->new($fh) or die "IO::Termios->new: $!"; $handle->set_mode('300,7,e,1'); IO::Stty::stty($handle, qw/ raw -parodd cs7 -cstopb parenb -ixoff -crt +scts -hupcl -ixon -opost -onlcr -isig -icanon -iexten -echo -echoe -e +choctl -echoke/); my $msg1 = "\x2F\x3F\x21\x0D\x0A"; my $msg2 = "\x06\x30\x30\x30\x0D\x0A"; for my $sleep (qw /.1 .2 .3 .4 .5 .6 .7 .8 .9 1.0 1.1 1.2/) { tryit ($msg1,$msg2,$sleep,2); } exit; sub sw{ my $raw=shift; $handle->syswrite($raw) == length($raw) or die "syswrite : $raw"; } sub tryit { my $msg1=shift; my $msg2=shift; my $sleep=shift; my $timeout=shift; my $sel_read = IO::Select->new(); $sel_read-> add($handle); my $didsomething=1; my $buf; print "waiting $sleep between sends\n"; sw($msg1); select (undef,undef,undef,$sleep); sw($msg2); while ($didsomething) { $didsomething=0; my ($rd_ptr,$wr_ptr,$er_ptr)=IO::Select->select($sel_read,undef,un +def,$timeout); for my $fh (@$rd_ptr) { $buf=''; $didsomething=1; my $rv = sysread($fh, $buf, 64*1024, length($buf)); if (!$rv) { if (defined($rv)) { die 'EOF';} else {die 'Connection terminated';} } # bad rv else { print $buf;} } # $fh } # while print "no chars for $timeout secs\n"; } # tryit #for (1..300) { # my $toread = 1; # $handle->sysread(my $in, $toread) # == $toread or die "sysread"; # print $in; #} $handle->close;

commented out last for loop


In reply to Re^7: r/w attached infrared head on /dev/ttyUSB0 by huck
in thread r/w attached infrared head on /dev/ttyUSB0 by stoerti

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (5)
    As of 2020-01-18 19:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?