Subject: | IO:Stty 0.03: problems setting baud rate and special characters |
Date: | Tue, 29 Jul 2014 01:37:58 +0100 |
To: | bug-IO-Stty [...] rt.cpan.org |
From: | Kevin Broadey <kevin [...] broadey.net> |
Hi Austin and Todd,
I ran into some issues today trying to use IO::Stty 0.03 on my Macbook Air OS X Mavericks 10.9.4 to set the baud rate and special characters for a serial port. I’ve used the stty.pl wrapper script to highlight the problems, and I’ve attached a patch a that fixes all the issues. I give everything to you in the same spirit that you gave me the original package.
Patch file:
Problem definition:
$ stty.pl 9600
Can't use string ("POSIX::B9600") as a subroutine ref while "strict refs" in use at /System/Library/Perl/Extras/5.16/IO/Stty.pm line 567.
$ stty.pl intr 3
IO::Stty::stty passed invalid parameter '3'
Can't use string ("POSIX::B3") as a subroutine ref while "strict refs" in use at /System/Library/Perl/Extras/5.16/IO/Stty.pm line 566.
$ stty.pl intr ^C
Argument "^C" isn't numeric in subroutine entry at /System/Library/Perl/Extras/5.16/IO/Stty.pm line 580.
$ stty.pl intr 0x03
Argument "0x03" isn't numeric in subroutine entry at /System/Library/Perl/Extras/5.16/IO/Stty.pm line 580.
$ stty.pl intr 003
IO::Stty::stty passed invalid parameter '003'
Can't use string ("POSIX::B003") as a subroutine ref while "strict refs" in use at /System/Library/Perl/Extras/5.16/IO/Stty.pm line 566.
$ perl -v
This is perl 5, version 16, subversion 2 (v5.16.2) built for darwin-thread-multi-2level
$ uname -a
Darwin HeartOfGold.local 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Analysis:
Problem 1 is that &{“POSIX::B”.shift(@parameters)} isn’t the right way to dynamically evaluate something like &POSIX::B9600. I fixed it by building a string and passing it to “eval”. Klunky, but effective!
Problem 2 is that the logic takes /any/ integer as a baud rate parameter, which then runs into problem 1. I fixed this by changing the place the ispeed and ospeed parameters get pushed (or unshifted) into @parameters.
Problem 3 is that there’s no logic to convert hat-style control characters into their numeric equivalents. I added it.
Problem 4 is that there’s no conversion logic for hexadecimal numeric parameters. I added it.
Problem 5 is that there’s no conversion logic for octal numeric parameters, and they also get caught by the everything-numeric-is-baud-rate bug. I added the logic.
Many thanks for IO::Stty. The bugs gave me a bit more grief than I was expecting, but now I’ve got a little utility program that’s a lot neater and more portable than it was when I was dropping into system(“stty …”).
All the best
Kevin Broadey
Hi Austin and Todd,
I ran into some issues today trying to use IO::Stty 0.03 on my Macbook Air OS X Mavericks 10.9.4 to set the baud rate and special characters for a serial port. I’ve used the stty.pl wrapper script to highlight the problems, and I’ve attached a patch a that fixes all the issues. I give everything to you in the same spirit that you gave me the original package.
Patch file:
Message body is not shown because sender requested not to inline it.
Problem definition:
$ stty.pl 9600
Can't use string ("POSIX::B9600") as a subroutine ref while "strict refs" in use at /System/Library/Perl/Extras/5.16/IO/Stty.pm line 567.
$ stty.pl intr 3
IO::Stty::stty passed invalid parameter '3'
Can't use string ("POSIX::B3") as a subroutine ref while "strict refs" in use at /System/Library/Perl/Extras/5.16/IO/Stty.pm line 566.
$ stty.pl intr ^C
Argument "^C" isn't numeric in subroutine entry at /System/Library/Perl/Extras/5.16/IO/Stty.pm line 580.
$ stty.pl intr 0x03
Argument "0x03" isn't numeric in subroutine entry at /System/Library/Perl/Extras/5.16/IO/Stty.pm line 580.
$ stty.pl intr 003
IO::Stty::stty passed invalid parameter '003'
Can't use string ("POSIX::B003") as a subroutine ref while "strict refs" in use at /System/Library/Perl/Extras/5.16/IO/Stty.pm line 566.
$ perl -v
This is perl 5, version 16, subversion 2 (v5.16.2) built for darwin-thread-multi-2level
$ uname -a
Darwin HeartOfGold.local 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Analysis:
Problem 1 is that &{“POSIX::B”.shift(@parameters)} isn’t the right way to dynamically evaluate something like &POSIX::B9600. I fixed it by building a string and passing it to “eval”. Klunky, but effective!
Problem 2 is that the logic takes /any/ integer as a baud rate parameter, which then runs into problem 1. I fixed this by changing the place the ispeed and ospeed parameters get pushed (or unshifted) into @parameters.
Problem 3 is that there’s no logic to convert hat-style control characters into their numeric equivalents. I added it.
Problem 4 is that there’s no conversion logic for hexadecimal numeric parameters. I added it.
Problem 5 is that there’s no conversion logic for octal numeric parameters, and they also get caught by the everything-numeric-is-baud-rate bug. I added the logic.
Many thanks for IO::Stty. The bugs gave me a bit more grief than I was expecting, but now I’ve got a little utility program that’s a lot neater and more portable than it was when I was dropping into system(“stty …”).
All the best
Kevin Broadey