File Coverage

blib/lib/Lab/Moose/Instrument/Common.pm
Criterion Covered Total %
statement 23 50 46.0
branch 0 2 0.0
condition n/a
subroutine 9 17 52.9
pod 11 11 100.0
total 43 80 53.7


line stmt bran cond sub pod time code
1             package Lab::Moose::Instrument::Common;
2             #ABSTRACT: Role for common commands declared mandatory by IEEE 488.2
3             $Lab::Moose::Instrument::Common::VERSION = '3.900';
4 14     14   11272 use v5.20;
  14         55  
5              
6 14     14   103 use Moose::Role;
  14         39  
  14         131  
7 14     14   78788 use MooseX::Params::Validate;
  14         42  
  14         163  
8              
9 14         954 use Lab::Moose::Instrument qw/
10             validated_getter
11             validated_setter
12             validated_no_param_setter
13 14     14   6686 /;
  14         40  
14 14     14   101 use Carp;
  14         40  
  14         812  
15              
16 14     14   126 use namespace::autoclean;
  14         51  
  14         123  
17              
18              
19             sub cls {
20 9     9 1 61 my ( $self, %args ) = validated_no_param_setter( \@_ );
21 9         112 return $self->write( command => '*CLS', %args );
22             }
23              
24              
25             sub idn {
26 0     0 1 0 my ( $self, %args ) = validated_getter( \@_ );
27 0         0 return $self->query( command => '*IDN?', %args );
28             }
29              
30              
31             sub idn_manufacturer {
32 0     0 1 0 my ( $self, %args ) = validated_getter( \@_ );
33 0         0 my $i=$self->query( command => '*IDN?', %args );
34 0         0 my ($man, $mod, $ser, $fir) = split /,\s*/, $i, 4;
35 0         0 return $man;
36             }
37              
38              
39             sub idn_model {
40 0     0 1 0 my ( $self, %args ) = validated_getter( \@_ );
41 0         0 my $i=$self->query( command => '*IDN?', %args );
42 0         0 my ($man, $mod, $ser, $fir) = split /,\s*/, $i, 4;
43 0         0 return $mod;
44             }
45              
46              
47             sub idn_serial {
48 0     0 1 0 my ( $self, %args ) = validated_getter( \@_ );
49 0         0 my $i=$self->query( command => '*IDN?', %args );
50 0         0 my ($man, $mod, $ser, $fir) = split /,\s/, $i, 4;
51 0         0 return $ser;
52             }
53              
54              
55             sub idn_firmware {
56 0     0 1 0 my ( $self, %args ) = validated_getter( \@_ );
57 0         0 my $i=$self->query( command => '*IDN?', %args );
58 0         0 my ($man, $mod, $ser, $fir) = split /,\s/, $i, 4;
59 0         0 return $fir;
60             }
61              
62              
63             sub opc {
64 0     0 1 0 my ( $self, %args ) = validated_no_param_setter( \@_ );
65 0         0 return $self->write( command => '*OPC', %args );
66             }
67              
68              
69             sub opc_query {
70 0     0 1 0 my ( $self, %args ) = validated_getter( \@_ );
71 0         0 return $self->query( command => '*OPC?', %args );
72             }
73              
74              
75             sub opc_sync {
76 0     0 1 0 my ( $self, %args ) = validated_getter( \@_ );
77 0         0 my $one = $self->opc_query(%args);
78 0 0       0 if ( $one ne '1' ) {
79 0         0 croak "OPC query did not return '1'";
80             }
81 0         0 return $one;
82             }
83              
84              
85             sub rst {
86 14     14 1 7185 my ( $self, %args ) = validated_no_param_setter( \@_ );
87 14         99 return $self->write( command => '*RST', %args );
88             }
89              
90              
91             sub wai {
92 9     9 1 39 my ( $self, %args ) = validated_no_param_setter( \@_ );
93 9         46 return $self->write( command => '*WAI', %args );
94             }
95              
96             1;
97              
98             __END__
99              
100             =pod
101              
102             =encoding UTF-8
103              
104             =head1 NAME
105              
106             Lab::Moose::Instrument::Common - Role for common commands declared mandatory by IEEE 488.2
107              
108             =head1 VERSION
109              
110             version 3.900
111              
112             =head1 METHODS
113              
114             =head2 cls
115              
116             Send I<*CLS> command.
117              
118             =head2 idn
119              
120             Return result of I<*IDN?> query.
121              
122             =head2 idn_manufacturer
123              
124             Returns the manufacturer field from an I<*IDN?> query.
125              
126             =head2 idn_model
127              
128             Returns the model field from an I<*IDN?> query.
129              
130             =head2 idn_serial
131              
132             Returns the serial number field from an I<*IDN?> query.
133              
134             =head2 idn_firmware
135              
136             Returns the firmware version field from an I<*IDN?> query.
137              
138             =head2 opc
139              
140             Send I<*OPC> command.
141              
142             =head2 opc_query
143              
144             Return result of I<*OPC?> query.
145              
146             =head2 opc_sync
147              
148             Perform C<opc_query> and croak if it does not return '1'. Make sure to provide
149             a sufficient timeout.
150              
151             =head2 rst
152              
153             Send I<*RST> command.
154              
155             =head2 wai
156              
157             Send I<*WAI> command.
158              
159             =head1 COPYRIGHT AND LICENSE
160              
161             This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
162              
163             Copyright 2016 Simon Reinhardt
164             2017 Andreas K. Huettel, Simon Reinhardt
165             2018 Andreas K. Huettel
166             2020 Andreas K. Huettel, Sam Bingner
167              
168              
169             This is free software; you can redistribute it and/or modify it under
170             the same terms as the Perl 5 programming language system itself.
171              
172             =cut