| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ====================================================================== |
|
2
|
|
|
|
|
|
|
# $Id: PortIO.pm,v 1.3 2005/03/05 06:45:56 andrew Exp $ |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Sys::PortIO - perform direct port I/O from Perl |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Sys::PortIO; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
port_open($portnum); |
|
13
|
|
|
|
|
|
|
write_byte($portnum, $value); |
|
14
|
|
|
|
|
|
|
$value = read_byte($portnum); |
|
15
|
|
|
|
|
|
|
port_close($portnum); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
This module provides a Perl interface to the low-level port I/O |
|
20
|
|
|
|
|
|
|
operations provided by Linux, FreeBSD, or OpenBSD. Among other things, |
|
21
|
|
|
|
|
|
|
this is useful for writing Perl scripts that interface with parallel, |
|
22
|
|
|
|
|
|
|
serial, or joystick ports. |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 BUGS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
On some systems (for example, Linux), doing a port read or write on an |
|
27
|
|
|
|
|
|
|
unopened port will cause a segmentation fault. |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 TODO |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over 4 |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item Support optional range argument to C. |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item Set $! on errors, instead of dying (sometimes with a segfault). |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item Alternately, automatically open ports as needed. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=back |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Linux I/O port mini-HOWTO: |
|
44
|
|
|
|
|
|
|
L |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
On Linux or other glibc systems, see L, L, and L. |
|
47
|
|
|
|
|
|
|
FreeBSD uses F for port access. On OpenBSD and NetBSD, see |
|
48
|
|
|
|
|
|
|
L and L. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 AUTHOR |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Andrew Ho, Eandrew@zeuscat.comE |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Copyright (C) 2005 by Andrew Ho. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
59
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.6.0 or, |
|
60
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
66
|
|
|
|
|
|
|
# Packages declaration (the real code is in the XS interface) |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
package Sys::PortIO; |
|
69
|
|
|
|
|
|
|
require 5.006; |
|
70
|
1
|
|
|
1
|
|
6582
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
35
|
|
|
71
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
41
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
require Exporter; |
|
74
|
1
|
|
|
1
|
|
852
|
use AutoLoader qw(AUTOLOAD); |
|
|
1
|
|
|
|
|
3174
|
|
|
|
1
|
|
|
|
|
9
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
77
|
|
|
|
|
|
|
our @EXPORT_OK = qw(port_open read_byte write_byte port_close); |
|
78
|
|
|
|
|
|
|
our @EXPORT = @EXPORT_OK; |
|
79
|
|
|
|
|
|
|
our $VERSION = '0.1'; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
require XSLoader; |
|
82
|
|
|
|
|
|
|
XSLoader::load('Sys::PortIO' => $VERSION); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# ====================================================================== |
|
88
|
|
|
|
|
|
|
__END__ |