Permalink
Browse files

Use Device::SerialPort.

  • Loading branch information...
1 parent 40e12fd commit 4ad880d73ddf6b2396408c0a6b626b52081ca699 @beanz committed Oct 24, 2011
Showing with 38 additions and 35 deletions.
  1. +5 −0 Changes
  2. +6 −0 debian/changelog
  3. +13 −5 lib/xPL/IOHandler.pm
  4. +14 −30 t/13-iohandler.t
View
@@ -1,5 +1,10 @@
Revision history for Perl extension xPL.
+{{$NEXT}}
+
+ - Use Device::SerialPort for more portability - thanks to
+ Lieven.
+
0.12 Sun, 23 Oct 2011 23:23:50 +0100
- Major API changes. Warns if deprecated functionality is
View
@@ -1,3 +1,9 @@
+libxpl-perl (0.13-0.1) unstable; urgency=low
+
+ * New upstream release.
+
+ -- Mark Hindess <soft-debian@temporalanomaly.com> Mon Oct 24 10:27:06 BST 2011
+
libxpl-perl (0.12-1) unstable; urgency=low
* New upstream release.
View
@@ -103,13 +103,21 @@ sub device_open {
$fh = IO::Socket::UNIX->new($dev)
or $self->argh("Unix domain socket connect to '$dev' failed: $!\n");
} else {
- # TODO: use Device::SerialPort?
- system("stty -F $dev ospeed $baud pass8 raw -echo >/dev/null") == 0 or
- $self->argh("Setting serial port with stty failed: $!\n");
- sysopen($fh, $dev,O_RDWR|O_NOCTTY|O_NDELAY)
+ require Symbol;
+ require Device::SerialPort;
+ import Device::SerialPort qw( :PARAM :STAT 0.07 );
+ $fh = Symbol::gensym();
+ my $sport = tie (*$fh, 'Device::SerialPort', $dev) or
+ $self->argh("Could not tie serial port to file handle: $!\n");
+ $sport->baudrate($baud);
+ $sport->databits(8);
+ $sport->parity("none");
+ $sport->stopbits(1);
+ $sport->datatype("raw");
+ $sport->write_settings();
+ sysopen($fh, $dev, O_RDWR|O_NOCTTY|O_NDELAY)
or $self->argh("open of '$dev' failed: $!\n");
$fh->autoflush(1);
- binmode($fh);
}
} else {
$dev .= ':'.($port||'10001') unless ($dev =~ /:/);
View
@@ -1,9 +1,9 @@
#!/usr/bin/perl -w
#
-# Copyright (C) 2009 by Mark Hindess
+# Copyright (C) 2011 by Mark Hindess
use strict;
-use Test::More tests => 34;
+use Test::More tests => 35;
use FileHandle;
use IO::Select;
use IO::Socket::INET;
@@ -151,35 +151,19 @@ my $warn =
xpl => $xpl);
});
-like($warn, qr{MyIOH: Setting serial port with stty failed}, 'stty failure');
like($warn, qr{MyIOH: open of '/dev/just-a-test' failed}, 'open failure');
-
-$warn =
- test_warn(sub {
- my $io = MyIOH->new(device => '/dev/null',
- baud => 9600,
- reader_callback => \&device_reader,
- xpl => $xpl);
- });
-
-like($warn, qr{MyIOH: Setting serial port with stty failed}, 'stty failure');
-unlike($warn, qr{MyIOH: open of '[^']*' failed}, 'open worked');
-
-$ENV{PATH} = 't/bin:'.$ENV{PATH};
-my $err;
-$warn =
- test_warn(sub {
- $err =
- test_output(sub {
- my $io = MyIOH->new(device => '/dev/null',
- baud => 9600,
- reader_callback =>
- \&device_reader,
- xpl => $xpl);
- }, \*STDERR) });
-
-is($warn, undef, 'stty worked');
-is($err, "-F /dev/null ospeed 9600 pass8 raw -echo\n", 'stty called correctly');
+like($warn, qr{CALLED Device::SerialPort::TIEHANDLE: /dev/just-a-test},
+ 'SerialPort call TIEHANDLE: /dev/just-a-test');
+like($warn, qr{CALLED Device::SerialPort::baudrate: 9600},
+ 'SerialPort call baudrate: 9600');
+like($warn, qr{CALLED Device::SerialPort::databits: 8},
+ 'SerialPort call databits: 8');
+like($warn, qr{CALLED Device::SerialPort::parity: none},
+ 'SerialPort call parity: none');
+like($warn, qr{CALLED Device::SerialPort::stopbits: 1},
+ 'SerialPort call stopbits: 1');
+like($warn, qr{CALLED Device::SerialPort::datatype: raw},
+ 'SerialPort call datatype: raw');
no warnings;
*{IO::Socket::INET::new} = sub { my $self = shift; warn $self.': ',@_; };

0 comments on commit 4ad880d

Please sign in to comment.