File Coverage

blib/lib/Lab/Moose/Instrument/SCPI/Sense/Frequency.pm
Criterion Covered Total %
statement 41 42 97.6
branch 1 2 50.0
condition n/a
subroutine 12 12 100.0
pod 5 5 100.0
total 59 61 96.7


line stmt bran cond sub pod time code
1             package Lab::Moose::Instrument::SCPI::Sense::Frequency;
2             $Lab::Moose::Instrument::SCPI::Sense::Frequency::VERSION = '3.900';
3             #ABSTRACT: Role for the SCPI SENSe:FREQuency subsystem
4              
5 4     4   2354 use v5.20;
  4         18  
6              
7 4     4   24 use Moose::Role;
  4         11  
  4         27  
8 4     4   20854 use Lab::Moose::Instrument::Cache;
  4         21  
  4         37  
9             use Lab::Moose::Instrument
10 4     4   2470 qw/validated_channel_getter validated_channel_setter/;
  4         11  
  4         249  
11 4     4   29 use MooseX::Params::Validate;
  4         9  
  4         33  
12 4     4   1871 use Carp;
  4         11  
  4         243  
13              
14 4     4   41 use namespace::autoclean;
  4         10  
  4         29  
15              
16             with 'Lab::Moose::Instrument::SCPI::Sense::Sweep';
17              
18              
19             cache sense_frequency_start => ( getter => 'sense_frequency_start_query' );
20              
21             sub sense_frequency_start_query {
22 6     6 1 1417 my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
23              
24 6         40 return $self->cached_sense_frequency_start(
25             $self->query( command => "SENS${channel}:FREQ:STAR?", %args ) );
26             }
27              
28             sub sense_frequency_start {
29 4     4 1 14304 my ( $self, $channel, $value, %args ) = validated_channel_setter( \@_ );
30 4         54 $self->write(
31             command => sprintf( "SENS%s:FREQ:STAR %.17g", $channel, $value ),
32             %args
33             );
34 4         18 $self->cached_sense_frequency_start($value);
35             }
36              
37             cache sense_frequency_stop => ( getter => 'sense_frequency_stop_query' );
38              
39             sub sense_frequency_stop_query {
40 6     6 1 1348 my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
41              
42 6         36 return $self->cached_sense_frequency_stop(
43             $self->query( command => "SENS${channel}:FREQ:STOP?", %args ) );
44             }
45              
46             sub sense_frequency_stop {
47 4     4 1 5692 my ( $self, $channel, $value, %args ) = validated_channel_setter( \@_ );
48 4         57 $self->write(
49             command => sprintf( "SENS%s:FREQ:STOP %.17g", $channel, $value ),
50             %args
51             );
52 4         21 $self->cached_sense_frequency_stop($value);
53             }
54              
55              
56             sub sense_frequency_linear_array {
57 9     9 1 44 my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
58              
59 9         43 my $start = $self->cached_sense_frequency_start();
60 9         44 my $stop = $self->cached_sense_frequency_stop();
61 9         35 my $num_points = $self->cached_sense_sweep_points();
62              
63 9         27 my $num_intervals = $num_points - 1;
64              
65 9 50       41 if ( $num_intervals == 0 ) {
66              
67             # Return a single point.
68 0         0 return [$start];
69             }
70              
71 9         19 my @result;
72              
73 9         40 for my $i ( 0 .. $num_intervals ) {
74 321         518 my $f = $start + ( $stop - $start ) * ( $i / $num_intervals );
75 321         545 push @result, $f;
76             }
77              
78 9         38 return \@result;
79             }
80              
81             1;
82              
83             __END__
84              
85             =pod
86              
87             =encoding UTF-8
88              
89             =head1 NAME
90              
91             Lab::Moose::Instrument::SCPI::Sense::Frequency - Role for the SCPI SENSe:FREQuency subsystem
92              
93             =head1 VERSION
94              
95             version 3.900
96              
97             =head1 METHODS
98              
99             =head2 sense_frequency_start_query
100              
101             my $freq = $self->sense_frequency_start_query();
102              
103             Query the starting point of the frequency sweep.
104              
105             =head2 sense_frequency_start
106              
107             $self->sense_frequency_start(value => 4e9);
108              
109             Set the starting point of the frequency sweep.
110              
111             =head2 sense_frequency_stop_query
112              
113             =head2 sense_frequency_stop
114              
115             Query and set the end point of the frequency sweep.
116              
117             =head2 sense_frequency_linear_array
118              
119             my $arrayref = $self->sense_frequency_linear_array();
120              
121             Helper method to get an arrayref of all points in the frequency sweep.
122             Does not provide a cached form, but will read it's input from cache.
123              
124             =head1 COPYRIGHT AND LICENSE
125              
126             This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
127              
128             Copyright 2016 Simon Reinhardt
129             2017 Andreas K. Huettel, Simon Reinhardt
130             2018 Eugeniy E. Mikhailov
131             2020 Andreas K. Huettel
132              
133              
134             This is free software; you can redistribute it and/or modify it under
135             the same terms as the Perl 5 programming language system itself.
136              
137             =cut