Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2022-05-26 14:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?