Connection/LinuxGPIB.pm untested

filter: Statementstmt 0.0% 0 / 65 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 113 CC 4 SCAR 13.1
CC
4
Cov
0%
Write
6.0
Read
6.0
Query
6.0
CRAP 3.7
1 package Lab::Connection::LinuxGPIB;
2 #ABSTRACT: LinuxGPIB connection
3 $Lab::Connection::LinuxGPIB::VERSION = '3.899';
4 use v5.20;
5  
6 #
7 # GPIB Connection class for Lab::Bus::LinuxGPIB
8 #
9 #
10 # TODO: Access to GPIB attributes, device clear, ...
11 #
12  
13 use strict;
14 use Scalar::Util qw(weaken);
15 use Time::HiRes qw (usleep sleep);
16 use Lab::Connection::GPIB;
17 use Lab::Exception;
18  
19 eval { require LinuxGpib; LinuxGpib->import(); };
20 die("Failed to load LinuxGpib in Lab::Connection::LinuxGPIB!\n$@") if ($@);
21  
22 our @ISA = ("Lab::Connection::GPIB");
23  
24 our %fields = (
25 bus_class => 'Lab::Bus::LinuxGPIB',
26 wait_status => 0, # usec;
27 wait_query => 10e-6, # sec;
28 read_length => 1000, # bytes
29 timeout => 1, # seconds
30 );
31  
32 sub new {
33 my $proto = shift;
34 my $class = ref($proto) || $proto;
35 my $twin = undef;
36 my $self = $class->SUPER::new(@_)
37 ; # getting fields and _permitted from parent class
38 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
39  
40 return $self;
41 }
42  
43 sub Write {
44 my $self = shift;
45 my $options = undef;
46 if ( ref $_[0] eq 'HASH' ) { $options = shift }
47 else { $options = {@_} }
48  
49 my $timeout = $options->{'timeout'} || $self->timeout();
50 $self->bus()->timeout( $self->connection_handle(), $timeout );
51  
52 return $self->bus()
53 ->connection_write( $self->connection_handle(), $options );
54 }
55  
56 sub Read {
57 my $self = shift;
58 my $options = undef;
59 if ( ref $_[0] eq 'HASH' ) { $options = shift }
60 else { $options = {@_} }
61  
62 my $timeout = $options->{'timeout'} || $self->timeout();
63 $self->bus()->timeout( $self->connection_handle(), $timeout );
64  
65 return $self->bus()
66 ->connection_read( $self->connection_handle(), $options );
67 }
68  
69 sub Query {
70 my $self = shift;
71 my $options = undef;
72 if ( ref $_[0] eq 'HASH' ) { $options = shift }
73 else { $options = {@_} }
74  
75 my $wait_query = $options->{'wait_query'} || $self->wait_query();
76 my $timeout = $options->{'timeout'} || $self->timeout();
77 $self->bus()->timeout( $self->connection_handle(), $timeout );
78  
79 $self->Write($options);
80 usleep($wait_query);
81 return $self->Read($options);
82 }
83  
84 #
85 # Query from Lab::Connection is sufficient
86 # EnableTermChar, SetTermChar from Lab::Connection::GPIB are sufficient.
87 #
88  
89  
90 1;
91  
92 __END__