Connection/GPIB.pm

filter: Statementstmt 48.7% 19 / 39 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 55.5% 5 / 9 Podpod 25.0% 1 / 4 totaltotal 42.3% 25 / 59 SCAR 15.4
CC
3
Cov
43%
new
6.0
serial_poll
6.0
EnableTermChar
2.0
CRAP 4.7
« Moose/Instrument/ZI_MFLI.pm ↑ Summary Connection/MODBUS_RS232.pm »
1 package Lab::Connection::GPIB;
2 #ABSTRACT: GPIB Connection base class
3 1 $Lab::Connection::GPIB::VERSION = '3.881';
4 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 #
7 # This is the GPIB Connection base class. It provides the interface definition for all
8 # connections implementing the GPIB protocol.
9 #
10 # In your scripts, use the implementing classes (e.g. Lab::Connection::LinuxGPIB).
11 #
12 # Instruments using a GPIB connection will check the inheritance tree of the provided connection
13 # for this class.
14 #
15 #
16 # TODO: Access to GPIB attributes, device clear, ...
17 #
18  
19 1 ▶use Lab::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Lab::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 our @ISA = ("Lab::Connection");
24  
25 1 our %fields = (
26 bus_class => undef, # 'Lab::Bus::LinuxGPIB', 'Lab::Bus::VISA', ...
27 gpib_address => undef,
28 gpib_saddress => undef, # secondary address, if needed
29 brutal => 0, # brutal as default?
30 wait_status => 0, # sec;
31 wait_query => 10e-6, # sec;
32 read_length => 1000, # bytes
33 );
34  
35 sub new {
36 0 ▶ my $proto = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
37 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
38 0 my $self = $class->SUPER::new(@_)
39 ; # getting fields and _permitted from parent class
40 0 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
41  
42 # # Parameter checking
43 # if( !defined $self->config('gpib_address') || $self->config('gpib_address') !~ /^[0-9]*$/ ) {
44 # Lab::Exception::CorruptParameter->throw( error => "No GPIB address specified! I can't work like this.\n" );
45 # }
46  
47 0 return $self;
48 }
49  
50 #
51 # These are the method stubs you have to overwrite when implementing the GPIB connection for your
52 # hardware/driver. See documentation for detailed description of the parameters, expected exceptions
53 # and expected return values.
54 #
55 # You might just be satisfied with the generic ones from Lab::Connection, take a look at them.
56 #
57  
58 # sub Clear { # @_ = ()
59 # return 0;
60 # }
61  
62 # sub Write { # @_ = ( command => $cmd, wait_status => $wait_status, brutal => 1/0 )
63 # return 0; # status true/false
64 # }
65  
66 # sub Read { # @_ = ( read_length => $read_length, brutal => 1/0 )
67 # return 0; # result
68 # }
69 # now comes GPIB-specific stuff
70  
71 sub EnableTermChar { # 0/1 off/on
72 0 ▶ my $self = shift;
Subroutine EnableTermChar: not called CC=1 SCAR=6.9
Pod undocumented
73 0 my $enable = shift;
74 0 my $result = $self->bus()
75 ->connection_enabletermchar( $self->connection_handle(), $enable );
76 0 return $result;
77 }
78  
79 sub SetTermChar { # the character as string
80 0 ▶ my $self = shift;
Subroutine SetTermChar: not called CC=1 SCAR=6.9
Pod undocumented
81 0 my $termchar = shift;
82 0 my $result = $self->bus()
83 ->connection_settermchar( $self->connection_handle(), $termchar );
84 0 return $result;
85 }
86  
87 #
88 # perform a serial poll on the bus and return the status byte
89 # Returns an array with index 0=>LSB, 8=>MSB of the status byte
90 #
91 sub serial_poll {
92 1 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 0 ▶ my $self = shift;
Subroutine serial_poll: not called CC=2 SCAR=17.9
Pod undocumented
94 0 my $statbyte = $self->bus()->serial_poll( $self->connection_handle() );
95 0 my @stat = ();
96  
97 0 ▶ for ( my $i = 0; $i < 8; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 8) 0 0 0
98 0 $stat[$i] = 0x01 & ( $statbyte >> $i );
99 }
100 0 return @stat;
101  
102 #return (split(//, unpack('b*', pack('N',$self->bus()->serial_poll($self->connection_handle())))))[-8..-1];
103 }
104  
105 1 1;
106  
107  
108 1 1;
109  
110 __END__
111  
112 =pod
113  
114 =encoding utf-8
115  
116 =head1 NAME
117  
118 Lab::Connection::GPIB - GPIB Connection base class
119  
120 =head1 VERSION
121  
122 version 3.881
123  
124 =head1 SYNOPSIS
125  
126 This is the base class for all connections providing a GPIB interface.
127 Every inheriting class constructor should start as follows:
128  
129 sub new {
130 my $proto = shift;
131 my $class = ref($proto) || $proto;
132 my $self = $class->SUPER::new(@_);
133 $self->_construct(__PACKAGE__); #initialize fields etc.
134 ...
135 }
136  
137 =head1 DESCRIPTION
138  
139 C<Lab::Connection::GPIB> is the base class for all connections providing a GPIB interface.
140 It is not usable on its own. It inherits from L<Lab::Connection>.
141  
142 Its main use so far is to define the data fields common to all GPIB interfaces.
143  
144 =head1 CONSTRUCTOR
145  
146 =head2 new
147  
148 Generally called in child class constructor:
149  
150 my $self = $class->SUPER::new(@_);
151  
152 Return blessed $self, with @_ accessible through $self->Config().
153  
154 =head1 METHODS
155  
156 This just calls back on the methods inherited from Lab::Connection.
157  
158 If you inherit this class in your own connection however, you have to provide the following methods.
159 Take a look at e.g. L<Lab::Connection::VISA_GPIB> and at the basic implementations
160 in L<Lab::Connection> (they may even suffice).
161  
162 =head3 Write()
163  
164 Takes a config hash, has to at least pass the key 'command' correctly to the underlying bus.
165  
166 =head3 Read()
167  
168 Takes a config hash, reads back a message from the device.
169  
170 =head3 Clear()
171  
172 Clears the instrument.
173  
174 =head2 config
175  
176 Provides unified access to the fields in initial @_ to all the child classes.
177 E.g.
178  
179 $GPIB_PAddress=$instrument->Config(GPIB_PAddress);
180  
181 Without arguments, returns a reference to the complete $self->Config aka @_ of the constructor.
182  
183 $Config = $connection->Config();
184 $GPIB_PAddress = $connection->Config()->{'GPIB_PAddress'};
185  
186 =head1 CAVEATS/BUGS
187  
188 Probably few. Mostly because there's not a lot to be done here. Please report.
189  
190 =head1 SEE ALSO
191  
192 =over 4
193  
194 =item * L<Lab::Connection>
195  
196 =item * L<Lab::Connection::LinuxGPIB>
197  
198 =item * L<Lab::Connection::VISA_GPIB>
199  
200 =back
201  
202 =head1 COPYRIGHT AND LICENSE
203  
204 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
205  
206 Copyright 2011 Andreas K. Huettel, Florian Olbrich
207 2012 Alois Dirnaichner, Florian Olbrich, Hermann Kraus, Stefan Geissler
208 2016 Simon Reinhardt
209 2017 Andreas K. Huettel
210 2020 Andreas K. Huettel
211  
212  
213 This is free software; you can redistribute it and/or modify it under
214 the same terms as the Perl 5 programming language system itself.
215  
216 =cut
« Moose/Instrument/ZI_MFLI.pm ↑ Summary Connection/MODBUS_RS232.pm »