File Coverage

blib/lib/Lab/Moose/Instrument/SCPI/Sense/Function/Concurrent.pm
Criterion Covered Total %
statement 52 59 88.1
branch 3 4 75.0
condition n/a
subroutine 13 15 86.6
pod 8 8 100.0
total 76 86 88.3


line stmt bran cond sub pod time code
1             package Lab::Moose::Instrument::SCPI::Sense::Function::Concurrent;
2             $Lab::Moose::Instrument::SCPI::Sense::Function::Concurrent::VERSION = '3.900';
3             #ABSTRACT: Role for the SCPI SENSe:FUNCtion subsystem with support for concurrent sense
4              
5 3     3   2292 use v5.20;
  3         15  
6              
7 3     3   25 use Moose::Role;
  3         9  
  3         25  
8 3     3   16113 use Lab::Moose::Instrument::Cache;
  3         16  
  3         27  
9             use Lab::Moose::Instrument
10 3     3   1896 qw/validated_channel_getter validated_channel_setter/;
  3         16  
  3         172  
11 3     3   32 use MooseX::Params::Validate;
  3         16  
  3         38  
12 3     3   1416 use Carp;
  3         27  
  3         186  
13              
14 3     3   31 use namespace::autoclean;
  3         9  
  3         18  
15              
16             excludes 'Lab::Moose::Instrument::SCPI::Sense::Function';
17              
18              
19             cache sense_function_concurrent =>
20             ( getter => 'sense_function_concurrent_query' );
21              
22             sub sense_function_concurrent_query {
23 2     2 1 1328 my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
24              
25 2         16 my $value = $self->query( command => "SENS${channel}:FUNC:CONC?", %args );
26 2         19 return $self->cached_sense_function_concurrent($value);
27             }
28              
29             sub sense_function_concurrent {
30 4     4 1 13868 my ( $self, $channel, $value, %args ) = validated_channel_setter(
31             \@_,
32             value => { isa => 'Bool' }
33             );
34              
35 4         27 $self->write( command => "SENS${channel}:FUNC:CONC $value", %args );
36 4         23 return $self->cached_sense_function_concurrent($value);
37             }
38              
39              
40             cache sense_function => ( getter => 'sense_function_query' );
41              
42             sub sense_function {
43 2     2 1 23 my ( $self, $channel, $value, %args ) = validated_channel_setter( \@_ );
44 2         13 return $self->cached_sense_function($value);
45             }
46              
47              
48             sub sense_function_query {
49              
50             # overwrite in instrument driver to get different default.
51 0     0 1 0 return 'CURR';
52             }
53              
54              
55             cache sense_function_on =>
56             ( isa => 'ArrayRef[Str]', getter => 'sense_function_on_query' );
57              
58             sub sense_function_on {
59 6     6 1 4022 my ( $self, $channel, $value, %args ) = validated_channel_setter(
60             \@_,
61             value => { isa => 'ArrayRef[Str]' }
62             );
63 6         16 my @values = @{$value};
  6         18  
64 6 100       25 if ( not $self->cached_sense_function_concurrent ) {
65 3 50       14 if ( @values != 1 ) {
66 0         0 croak
67             "sense_function_on without concurrent sense only accepts single function";
68             }
69             }
70 6         14 @values = map {"'$_'"} @values;
  6         27  
71 6         18 my $param = join( ',', @values );
72              
73 6         37 $self->write( command => "SENS${channel}:FUNC:ON $param", %args );
74 6         37 return $self->sense_function_on_query(%args);
75             }
76              
77             sub sense_function_on_query {
78 13     13 1 70 my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
79              
80 13         63 my $value = $self->query( command => "SENS${channel}:FUNC:ON?", %args );
81 13         61 $value =~ s/["']//g;
82 13         45 my @values = split( ',', $value );
83 13         80 $self->cached_sense_function_on( [@values] );
84 13         69 return [@values];
85             }
86              
87              
88             sub sense_function_off {
89 2     2 1 734 my ( $self, $channel, $value, %args ) = validated_channel_setter(
90             \@_,
91             value => { isa => 'ArrayRef[Str]' }
92             );
93 2         7 my @values = @{$value};
  2         6  
94 2         5 @values = map {"'$_'"} @values;
  3         12  
95 2         8 my $param = join( ',', @values );
96              
97 2         13 $self->write( command => "SENS${channel}:FUNC:OFF $param", %args );
98              
99             # update cached_sense_function_on
100 2         14 $self->sense_function_on_query(%args);
101             }
102              
103             sub sense_function_off_query {
104 0     0 1   my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
105              
106 0           my $value = $self->query( command => "SENS${channel}:FUNC:OFF?", %args );
107 0           $value =~ s/["']//g;
108 0           my @values = split( ',', $value );
109 0           return [@values];
110             }
111              
112             1;
113              
114             __END__
115              
116             =pod
117              
118             =encoding UTF-8
119              
120             =head1 NAME
121              
122             Lab::Moose::Instrument::SCPI::Sense::Function::Concurrent - Role for the SCPI SENSe:FUNCtion subsystem with support for concurrent sense
123              
124             =head1 VERSION
125              
126             version 3.900
127              
128             =head1 DESCRIPTION
129              
130             This role is intended for instruments which support multiple concurrent sense
131             functions. For example, the Keithley2400 or KeysightB2901A source/measure units
132             which can measure voltage and current simultaneously.
133              
134             The set sense function is used by other SENSE: roles, like SENSE:NPLC. For
135             example, let us enable concurrent measurement of voltage and current and set the integration time for both
136             measured parameters:
137              
138             $source->sense_function_concurrent(value => 1);
139             $source->sense_function_on(value => ['VOLT', 'CURR']);
140              
141             # Set NPLC for current measurement
142             $source->sense_function(value => 'CURR');
143             $source->sense_nplc(value => 10);
144              
145             # Set NPLC for voltage measurement
146             $source->sense_function(value => 'VOLT');
147             $source->sense_nplc(value => 10);
148              
149             =head1 METHODS
150              
151             =head2 sense_function_concurrent_query/sense_function_concurrent
152              
153             Set/Get concurrent property of sensor block. Allowed values: C<0> or C<1>.
154              
155             =head2 sense_function
156              
157             $source->sense_function(value => $function);
158              
159             Unlike the C<sense_function> method from the
160             L<Lab::Moose::Instrument::SCPI::Sense::Function> method, does not send a command, only used by other SENSE: roles, like SENSE:NPLC
161              
162             =head2 cached_sense_function/sense_function_query
163              
164             C<sense_function_query> is only used to initialize the cache.
165              
166             =head2 sense_function_on
167              
168             $source->sense_function_on(value => ['CURR', 'VOLT']);
169              
170             Enable parameters which should be measured.
171              
172             =head2 sense_function_on_query
173              
174             my @params = @{$source->sense_function_on_query()};
175              
176             Query list of parameters which are measured.
177              
178             =head2 sense_function_off_query/sense_function_off
179              
180             $source->sense_function_off(value => ['CURR']);
181              
182             Query/set list of parameters which should not be measured.
183              
184             =head1 COPYRIGHT AND LICENSE
185              
186             This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
187              
188             Copyright 2018 Simon Reinhardt
189             2020 Andreas K. Huettel
190              
191              
192             This is free software; you can redistribute it and/or modify it under
193             the same terms as the Perl 5 programming language system itself.
194              
195             =cut