Moose/Instrument/RS_FSV.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 75.0% 3 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 50.0% 1 / 2 totaltotal 89.8% 62 / 69 CC 4 SCAR 6.7
CC
4
Cov
93%
get_spectrum
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« Moose/Instrument/ZI_HDAWG.pm ↑ Summary Moose/Instrument/Common.pm »
1 package Lab::Moose::Instrument::RS_FSV;
2 2 $Lab::Moose::Instrument::RS_FSV::VERSION = '3.931';
3 #ABSTRACT: Rohde & Schwarz FSV Signal and Spectrum Analyzer
4  
5 2 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 2 ▶use PDL::Core qw/pdl cat/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Lab::Moose::Instrument qw/timeout_param precision_param/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 extends 'Lab::Moose::Instrument';
18  
19 2 with qw(
20 Lab::Moose::Instrument::Common
21  
22 Lab::Moose::Instrument::SCPI::Format
23  
24 Lab::Moose::Instrument::SCPI::Sense::Bandwidth
25 Lab::Moose::Instrument::SCPI::Sense::Frequency
26 Lab::Moose::Instrument::SCPI::Sense::Sweep
27  
28 Lab::Moose::Instrument::SCPI::Initiate
29  
30 Lab::Moose::Instrument::SCPIBlock
31  
32 );
33  
34 1 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
35 1 my $self = shift;
36 1 $self->clear();
37 1 $self->cls();
38 }
39  
40  
41  
42 3 ▶sub get_spectrum {
Subroutine get_spectrum: called CC=4 SCAR=14.0
Pod documented
43 3 my ( $self, %args ) = validated_hash(
44 \@_,
45 timeout_param(),
46 precision_param(),
47 trace => { isa => 'Int', default => 1 },
48 );
49  
50 3 my $precision = delete $args{precision};
51  
52 3 my $trace = delete $args{trace};
53  
54 3 ▶ if ( $trace < 1 || $trace > 6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trace < 1 or $trace > 6) 0 3 3
Condition33%1/3
$trace < 1 or $trace > 6
l!l&&r!l&&!r
003
MC/DC0%0/2
$trace < 1 or $trace > 6
$trace < 1 $trace > 6
Truth table33%1/3
A or B
A= $trace < 1B= $trace > 6
ABresult
1X1
011
000
55 0 croak "trace has to be in (1..6)";
56 }
57  
58 3 my $freq_array = $self->sense_frequency_linear_array();
59  
60 # Ensure single sweep mode.
61 3 ▶ if ( $self->cached_initiate_continuous() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cached_initiate_continuous) 1 2 3
62 1 $self->initiate_continuous( value => 0 );
63 }
64  
65 # Ensure correct data format
66 3 $self->set_data_format_precision( precision => $precision );
67  
68 # Get data.
69 3 my $num_points = @{$freq_array};
70 3 $args{read_length} = $self->block_length(
71 precision => $precision,
72 num_points => $num_points
73 );
74 3 $self->initiate_immediate();
75 3 $self->wai();
76 3 my $binary = $self->binary_query(
77 command => "TRAC? TRACE$trace",
78 %args
79 );
80 3 my $points_ref = pdl $self->block_to_array(
81 binary => $binary,
82 precision => $precision
83 );
84  
85 3 return cat( ( pdl $freq_array), $points_ref );
86  
87 }
88  
89  
90 #
91 #
92 # Stuff from legacy Lab::Instrument::SpectrumSCPI
93 # Needs cleanup and docs.
94 #
95 #
96  
97 # sub selftest {
98 # my $self = shift;
99 # return $self->query("*TST");
100 # }
101  
102 # sub reset {
103 # my $self = shift;
104 # $self->write("*RST");
105 # }
106  
107 # sub set_power_unit {
108 # my $self = shift;
109 # my $unit = shift || "DBM"; #DBM, W
110 # $self->write("UNIT:POW $unit");
111 # }
112  
113 # sub set_frequency {
114 # my $self = shift;
115 # my $freq = shift || "DEF"; #Hz
116 # $self->write("FREQ:CENT $freq");
117 # }
118  
119 # sub set_span {
120 # my $self = shift;
121 # my $span = shift || "DEF"; #Hz
122 # $self->write("FREQ:SPAN $span");
123 # }
124  
125 # sub set_bandwidth {
126 # my $self = shift;
127 # my $bw = shift || "DEF"; #Hz
128 # $self->write("BAND:RES $bw");
129 # }
130  
131 # sub set_sweep_time {
132 # my $self = shift;
133 # my $time = shift || "DEF"; #Hz
134 # $self->write("SWE:Time $time");
135 # }
136  
137 # sub set_continous {
138 # my $self = shift;
139 # my $cont = shift || "ON"; #ON, OFF
140 # $self->write("INIT:CONT $cont");
141 # }
142  
143 # sub auto_adjust_level {
144 # my $self = shift;
145 # $self->write(command => "SENSe:ADJ:LEVel");
146 # }
147  
148 # #NOTE: In auto attenation mode this function also switches attenuators.
149 # sub set_reference_level {
150 # my $self = shift;
151 # my $level = shift || "0"; #in dBm
152 # $self->write(command => "DISP:TRACe:Y:RLEVel $level");
153 # }
154  
155 # sub set_preamp {
156 # my $self = shift;
157 # my $state = shift || "OFF"; #ON, OFF
158 # $self->write(command => "INPut:GAIN:STATe $state");
159 # }
160  
161 # sub set_marker_auto_peak {
162 # my $self = shift;
163 # my $state = shift || "ON";
164 # my $marker = shift || 1;
165 # $self->write(command => "CALC:MARKer$marker:MAX:AUTO $state");
166 # }
167  
168 # sub get_marker_frequency {
169 # my $self = shift;
170 # my $marker = shift || 1;
171 # return $self->query(command => "CALC:MARK:X?");
172 # }
173  
174 # sub get_marker_level {
175 # my $self = shift;
176 # my $marker = shift || 1;
177 # return $self->query(command => "CALC:MARK:Y?");
178 # }
179  
180 # sub set_time_domain {
181 # my $self = shift;
182 # my $freq = shift;
183 # my $bw = shift;
184 # $self->set_continous("OFF");
185 # $self->set_frequency($freq);
186 # $self->set_span("0 Hz");
187 # $self->set_bandwidth($bw);
188 # $self->set_sweep_time("2000 US"); #TODO
189 # }
190  
191 # sub single_sweep {
192 # my $self = shift;
193 # $self->write(command => "INIT;*WAI");
194 # }
195  
196 # sub read_rms {
197 # my $self = shift;
198 # $self->single_sweep();
199 # $self->write(command => "CALC:MARK:FUNC:SUMM:RMS ON");
200 # return $self->query(command => ":CALC:MARK:FUNC:SUMM:RMS:RES?");
201 # }
202  
203 # sub read {
204 # my $self = shift;
205  
206 # #TODO: Check other modes
207 # return $self->query(command => "READ?");
208  
209 # }
210  
211 # sub get_error {
212 # my $self = shift;
213 # my $current_error = "";
214 # my $all_errors = "";
215 # my $max_errors = 5;
216 # while ( $max_errors-- ) {
217 # $current_error = $self->query(command => 'SYST:ERR?');
218 # if ( $current_error eq "" ) {
219 # $all_errors .= "Could not read error message!\n";
220 # last;
221 # }
222 # if ( $current_error =~ m/^\+?0,/ ) { last; }
223 # $all_errors .= $current_error . "\n";
224 # }
225 # if ( !$max_errors ) { $all_errors .= "Maximum Error count reached!\n"; }
226 # $self->write(command => "*CLS"); #Clear errors
227 # chomp($all_errors);
228 # return $all_errors;
229 # }
230  
231 2 __PACKAGE__->meta()->make_immutable();
232  
233 2 1;
234  
235 __END__
« Moose/Instrument/ZI_HDAWG.pm ↑ Summary Moose/Instrument/Common.pm »