Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^7: r/w attached infrared head on /dev/ttyUSB0

by huck (Prior)
on May 30, 2019 at 14:49 UTC ( [id://11100729]=note: print w/replies, xml ) Need Help??


in reply to Re^6: r/w attached infrared head on /dev/ttyUSB0
in thread r/w attached infrared head on /dev/ttyUSB0

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11100729]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-29 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found