LinuxGpib.pm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package LinuxGpib;
  2. use 5.006;
  3. use strict;
  4. use warnings;
  5. use Carp;
  6. require Exporter;
  7. require DynaLoader;
  8. use AutoLoader;
  9. our @ISA = qw(Exporter DynaLoader);
  10. # Items to export into callers namespace by default. Note: do not export
  11. # names by default without a very good reason. Use EXPORT_OK instead.
  12. # Do not simply export all your public functions/methods/constants.
  13. # This allows declaration use LinuxGpib ':all';
  14. # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
  15. # will save memory.
  16. our %EXPORT_TAGS = ( 'all' => [ qw(
  17. ibcac
  18. ibclr
  19. ibcmd
  20. ibconfig
  21. ibdev
  22. ibdma
  23. ibeot
  24. ibevent
  25. ibfind
  26. ibgts
  27. iblines
  28. ibloc
  29. ibonl
  30. ibpad
  31. ibrd
  32. ibrdi
  33. ibrpp
  34. ibrsp
  35. ibrsv
  36. ibsad
  37. ibsic
  38. ibsre
  39. ibtmo
  40. ibtrg
  41. ibwait
  42. ibwrt
  43. ibwrti
  44. ) ] );
  45. our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
  46. our @EXPORT = qw(
  47. );
  48. our $VERSION = '0.01';
  49. use constant EDVR => 0;
  50. use constant ECIC => 1;
  51. use constant ENOL => 2;
  52. use constant EADR => 3;
  53. use constant EARG => 4;
  54. use constant ESAC => 5;
  55. use constant EABO => 6;
  56. use constant ENEB => 7;
  57. use constant EDMA => 8;
  58. use constant EBTO => 9;
  59. use constant EOIP => 10;
  60. use constant ECAP => 11;
  61. use constant EFSO => 12;
  62. use constant EOWN => 13;
  63. use constant EBUS => 14;
  64. use constant ESTB => 15;
  65. use constant ESRQ => 16;
  66. use constant ETAB => 20;
  67. use constant ELCK => 21;
  68. use constant TNONE => 0;
  69. use constant T10us => 1;
  70. use constant T30us => 2;
  71. use constant T100us => 3;
  72. use constant T300us => 4;
  73. use constant T1ms => 5;
  74. use constant T3ms => 6;
  75. use constant T10ms => 7;
  76. use constant T30ms => 8;
  77. use constant T100ms => 9;
  78. use constant T300ms => 10;
  79. use constant T1s => 11;
  80. use constant T3s => 12;
  81. use constant T10s => 13;
  82. use constant T30s => 14;
  83. use constant T100s => 15;
  84. use constant T300s => 16;
  85. use constant T1000s => 17;
  86. sub AUTOLOAD {
  87. # This AUTOLOAD is used to 'autoload' constants from the constant()
  88. # XS function. If a constant is not found then control is passed
  89. # to the AUTOLOAD in AutoLoader.
  90. my $constname;
  91. our $AUTOLOAD;
  92. ($constname = $AUTOLOAD) =~ s/.*:://;
  93. croak "& not defined" if $constname eq 'constant';
  94. my $val = constant($constname, @_ ? $_[0] : 0);
  95. if ($! != 0) {
  96. if ($! =~ /Invalid/ || $!{EINVAL}) {
  97. $AutoLoader::AUTOLOAD = $AUTOLOAD;
  98. goto &AutoLoader::AUTOLOAD;
  99. }
  100. else {
  101. croak "Your vendor has not defined LinuxGpib macro $constname";
  102. }
  103. }
  104. {
  105. no strict 'refs';
  106. # Fixed between 5.005_53 and 5.005_61
  107. if ($] >= 5.00561) {
  108. *$AUTOLOAD = sub () { $val };
  109. }
  110. else {
  111. *$AUTOLOAD = sub { $val };
  112. }
  113. }
  114. goto &$AUTOLOAD;
  115. }
  116. bootstrap LinuxGpib $VERSION;
  117. # Preloaded methods go here.
  118. sub new {
  119. my $pkg = shift;
  120. my $dev = undef;
  121. my $i;
  122. if (@_ == 1) {
  123. $dev = ibfind($_[0]);
  124. } elsif (@_ == 6) {
  125. $dev = ibdev(@_);
  126. } else {
  127. die("Bad parameter list to LinuxGpib::new($pkg @_)");
  128. }
  129. # This has to be tested changed (use status vars)
  130. # deadlock, if device not found
  131. bless \$dev, $pkg;
  132. return $dev;
  133. }
  134. # Autoload methods go after =cut, and are processed by the autosplit program.
  135. 1;
  136. __END__
  137. # Below is stub documentation for your module. You better edit it!
  138. =head1 NAME
  139. LinuxGpib - Perl extension for Gpib (uses libgpib from http://linux-gpib.sourceforge.net)
  140. =head1 SYNOPSIS
  141. use Gpib;
  142. =head1 DESCRIPTION
  143. This module allows access to libgpib.so from within Perl.
  144. WARNING: Not all functions have been tested yet!
  145. USE IT AT YOUR OWN RISK!
  146. =head2 EXPORT
  147. None by default.
  148. =head2 Exportable functions
  149. int ibcac(int ud, int v)
  150. int ibclr(int ud)
  151. int ibcmd(int ud, char *cmd, unsigned long cnt)
  152. int ibconfig( int ud, int option, int value )
  153. int ibdev(int minor, int pad, int sad, int timo, int eot, int eos)
  154. int ibdma( int ud, int v )
  155. int ibeot(int ud, int v)
  156. int ibevent(int ud, short *event)
  157. int ibfind(char *dev)
  158. int ibgts(int ud, int v)
  159. int iblines(int ud, unsigned short *buf)
  160. int ibloc(int ud)
  161. int ibonl(int ud, int onl)
  162. int ibpad(int ud, int v)
  163. int ibrd(int ud, char *rd, unsigned long cnt)
  164. int ibrdi(int ud, char *rd, unsigned long cnt)
  165. int ibrpp(int ud, char *ppr)
  166. int ibrsp(int ud, char *spr)
  167. int ibrsv(int ud, int v)
  168. int ibsad(int ud, int v)
  169. int ibsic(int ud)
  170. int ibsre(int ud, int v)
  171. int ibtmo(int ud,int v)
  172. int ibtrg(int ud)
  173. int ibwait(int ud, int mask)
  174. int ibwrt(int ud, char *rd, unsigned long cnt)
  175. int ibwrti(int ud, char *rd, unsigned long cnt)
  176. =head1 AUTHOR
  177. Thomas Nisius <tnisius@web.de>
  178. =head1 SEE ALSO
  179. =cut