Moose/Instrument/HP8596E.pm untested

filter: Statementstmt 0.0% 0 / 103 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 34 Podpod 0.0% 0 / 25 totaltotal 0.0% 0 / 173 SCAR 34.0
CC
5
Cov
0%
validate_trace_param
30.0
BUILD
2.0
idn
2.0
CRAP 30.0
1 package Lab::Moose::Instrument::HP8596E;
2 $Lab::Moose::Instrument::HP8596E::VERSION = '3.881';
3 #ABSTRACT: HP8596E Spectrum Analyzer
4  
5 use v5.20;
6  
7  
8 use PDL::Core qw/pdl cat nelem/;
9  
10 use Moose;
11 use Moose::Util::TypeConstraints;
12 use MooseX::Params::Validate;
13 use Lab::Moose::Instrument qw/
14 timeout_param
15 precision_param
16 validated_getter
17 validated_setter
18 validated_channel_getter
19 validated_channel_setter
20 validated_no_param_setter
21 /;
22 use Lab::Moose::Instrument::Cache;
23 use Carp;
24 use namespace::autoclean;
25  
26 extends 'Lab::Moose::Instrument';
27  
28 with 'Lab::Moose::Instrument::SpectrumAnalyzer', qw(
29 Lab::Moose::Instrument::Common
30  
31 Lab::Moose::Instrument::SCPI::Format
32  
33 Lab::Moose::Instrument::SCPI::Sense::Bandwidth
34 Lab::Moose::Instrument::SCPI::Sense::Frequency
35 Lab::Moose::Instrument::SCPI::Sense::Sweep
36 Lab::Moose::Instrument::SCPI::Sense::Power
37 Lab::Moose::Instrument::SCPI::Display::Window
38 Lab::Moose::Instrument::SCPI::Unit
39  
40 Lab::Moose::Instrument::SCPI::Initiate
41  
42 Lab::Moose::Instrument::SCPIBlock
43  
44 );
45  
46 sub BUILD {
47 my $self = shift;
48  
49 # limitation of hardware
50 $self->capable_to_query_number_of_X_points_in_hardware(0);
51 $self->capable_to_set_number_of_X_points_in_hardware(0);
52 $self->hardwired_number_of_X_points(401);
53  
54 #$self->clear();
55 $self->cls();
56 }
57  
58  
59 sub validate_trace_param {
60 my ( $self, $trace ) = @_;
61 if ( $trace < 1 || $trace > 3 ) {
62 confess "trace has to be in (1..3)";
63 }
64 # convert trace number to name 1->A, 2->B, ...
65 if ( $trace == 1 ) {
66 $trace = 'A';
67 }
68 elsif ( $trace == 2 ) {
69 $trace = 'B';
70 }
71 elsif ( $trace == 3 ) {
72 $trace = 'C';
73 }
74 return $trace;
75 }
76  
77 ##### This device predates creation of SCPI commands (introduced in 1999), so we fake them
78  
79 sub idn {
80 my ( $self, %args ) = validated_getter( \@_ );
81 return $self->query( command => '*ID?', %args );
82 }
83  
84 sub cls {
85 my ( $self, %args ) = validated_no_param_setter( \@_ );
86 return $self->write( command => 'CLS', %args );
87 }
88  
89  
90 ### Sense:Frequency emulation
91 sub sense_frequency_start_query {
92 my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
93  
94 return $self->cached_sense_frequency_start(
95 $self->query( command => "FA?", %args ) );
96 }
97  
98 sub sense_frequency_start {
99 my ( $self, $channel, $value, %args ) = validated_channel_setter( \@_ );
100 $self->write(
101 command => sprintf( "FA %.17g", $value ),
102 %args
103 );
104 $self->cached_sense_frequency_start($value);
105 }
106  
107 sub sense_frequency_stop_query {
108 my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
109  
110 return $self->cached_sense_frequency_stop(
111 $self->query( command => "FB?", %args ) );
112 }
113  
114 sub sense_frequency_stop {
115 my ( $self, $channel, $value, %args ) = validated_channel_setter( \@_ );
116 $self->write(
117 command => sprintf( "FB %.17g", $value ),
118 %args
119 );
120 $self->cached_sense_frequency_stop($value);
121 }
122  
123 ### Sense:Power emulation
124  
125 sub sense_power_rf_attenuation_query {
126 my ( $self, %args ) = validated_getter( \@_ );
127  
128 return $self->cached_sense_power_rf_attenuation(
129 $self->query( command => "AT?", %args ) );
130 }
131  
132 sub sense_power_rf_attenuation {
133 my ( $self, $value, %args ) = validated_setter( \@_ );
134  
135 $self->write( command => "AT $value", %args );
136 $self->cached_sense_power_rf_attenuation($value);
137 }
138  
139 ### Sense:Sweep:Points emulation
140  
141  
142 sub sense_sweep_points_query {
143 confess(
144 "sub sense_sweep_points_query is not implemented by hardware, we should not be here"
145 );
146 }
147  
148 sub sense_sweep_points {
149 confess(
150 "sub sense_sweep_points is not implemented by hardware, we should not be here"
151 );
152 }
153  
154 ### Sense:Sweep:Count emulation
155  
156 sub sense_sweep_count_query {
157 my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
158 return $self->cached_sense_sweep_count(1); # hardwired
159 }
160  
161 sub sense_sweep_count {
162 my ( $self, $channel, $value, %args ) = validated_channel_setter( \@_ );
163  
164 $value = 1; # hard wired
165 $self->cached_sense_sweep_count($value);
166 }
167  
168 ### Sense:Bandwidth:Resolution emulation
169  
170 sub sense_bandwidth_resolution_query {
171 my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
172  
173 return $self->cached_sense_bandwidth_resolution(
174 $self->query( command => "RB?", %args ) );
175 }
176  
177 sub sense_bandwidth_resolution {
178 my ( $self, $channel, $value, %args ) = validated_channel_setter(
179 \@_,
180 value => { isa => 'Num' }
181 );
182 $self->write(
183 command => sprintf( "RB %.17g", $value ),
184 %args
185 );
186 $self->cached_sense_bandwidth_resolution($value);
187 }
188  
189 sub sense_bandwidth_video_query {
190 my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
191  
192 return $self->cached_sense_bandwidth_video(
193 $self->query( command => "VB?", %args ) );
194 }
195  
196 sub sense_bandwidth_video {
197 my ( $self, $channel, $value, %args ) = validated_channel_setter(
198 \@_,
199 value => { isa => 'Num' }
200 );
201 $self->write(
202 command => sprintf( "VB %.17g", $value ),
203 %args
204 );
205 $self->cached_sense_bandwidth_video($value);
206 }
207  
208 ### Sense:Sweep:Time
209  
210 sub sense_sweep_time_query {
211 my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
212 return $self->cached_sense_sweep_time(
213 $self->query( command => "ST?", %args ) );
214 }
215  
216 sub sense_sweep_time {
217 my ( $self, $channel, $value, %args ) = validated_channel_setter( \@_ );
218  
219 $self->write( command => "ST $value", %args );
220 $self->cached_sense_sweep_time($value);
221 }
222  
223 ### Display:Window:Trace:Y:Scale:Rlevel
224  
225 sub display_window_trace_y_scale_rlevel_query {
226 my ( $self, $channel, %args ) = validated_channel_getter( \@_ );
227  
228 return $self->cached_display_window_trace_y_scale_rlevel(
229 $self->query( command => "RL?", %args ) );
230 }
231  
232 sub display_window_trace_y_scale_rlevel {
233 my ( $self, $channel, $value, %args ) = validated_channel_setter( \@_ );
234 $self->write(
235 command => sprintf( "RL %.17g", $value ),
236 %args
237 );
238 $self->cached_display_window_trace_y_scale_rlevel($value);
239 }
240  
241 ### Unit:Power
242  
243 sub unit_power_query {
244 my ( $self, %args ) = validated_getter( \@_ );
245  
246 return $self->cached_unit_power(
247 $self->query( command => "AUNITS?", %args ) );
248 }
249  
250 sub unit_power {
251 my ( $self, $channel, $value, %args ) = validated_channel_setter( \@_ );
252  
253 # allowed values are DBM, DBMV, DBUV, V, W
254 $self->write(
255 command => sprintf( "AUNITS %s", $value ),
256 %args
257 );
258 $self->cached_unit_power($value);
259 }
260  
261 ### Trace/Data emulation
262 sub get_traceY {
263 # grab what is on display for a given trace
264 my ( $self, %args ) = validated_hash(
265 \@_,
266 timeout_param(),
267 precision_param(),
268 trace => { isa => 'Int', default => 1 },
269 );
270  
271 my $precision = delete $args{precision};
272 my $trace = delete $args{trace};
273  
274 $trace = $self->validate_trace_param($trace);
275  
276  
277 # 'TDF P' switches output format to the human readable (ascii)
278 # number representation. Numbers are separated by commas
279 my $reply = $self->query(
280 command => "TDF P; TR$trace?",
281 %args
282 );
283 my @dat = split( /,/, $reply );
284  
285 return pdl @dat;
286  
287 }
288  
289 __PACKAGE__->meta()->make_immutable();
290  
291 1;
292  
293 __END__
294  
295 =pod
296  
297 =encoding UTF-8
298  
299 =head1 NAME
300  
301 Lab::Moose::Instrument::HP8596E - HP8596E Spectrum Analyzer
302  
303 =head1 VERSION
304  
305 version 3.881
306  
307 =head1 SYNOPSIS
308  
309 my $data = $hp->get_spectrum(trace=>1, timeout => 10);
310  
311 =head1 Driver for HP8596E series spectrum analyzers
312  
313 =head1 METHODS
314  
315 =head2 validate_trace_param
316  
317 Validates or applies hardware friendly aliases to trace parameter.
318 Trace has to be in (1..3).
319  
320 =head1 Missing SCPI functionality
321  
322 HP8596E has no Sense:Sweep:Points implementation
323  
324 =head2 sense_sweep_points_query
325  
326 =head2 sense_sweep_points
327  
328 =head1 NAME
329  
330 Lab::Moose::Instrument::HP8596E - HP Spectrum Analyzer
331  
332 =head1 VERSION
333  
334 version 3.621
335  
336 =head1 METHODS
337  
338 This driver implements the following high-level method:
339  
340 =head2 get_spectrum
341  
342 $data = $hp->get_spectrum(timeout => 10, trace => 2);
343  
344 Perform a single sweep and return the resulting spectrum as a 2D PDL:
345  
346 [
347 [freq1, freq2, freq3, ..., freqN],
348 [power1, power2, power3, ..., powerN],
349 ]
350  
351 I.e. the first dimension runs over the sweep points.
352  
353 This method accepts a hash with the following options:
354  
355 =over
356  
357 =item B<timeout>
358  
359 timeout for the sweep operation. If this is not given, use the connection's
360 default timeout.
361  
362 =item B<trace>
363  
364 number of the trace (1..3). Defaults to 1.
365  
366 =back
367  
368 =head1 SEE ALSO
369  
370 This driver modeled closely to RS_FSV (see L<Lab::Moose::Instrument::RS_FSV>) and should perform similar functions.
371  
372 In particular commands from the following SCPI subsystems are implemented
373  
374 L<Lab::Moose::Instrument::SCPI::Sense::Frequency>,
375 L<Lab::Moose::Instrument::SCPI::Sense::Sweep>
376  
377 =head1 COPYRIGHT AND LICENSE
378  
379 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
380  
381 Copyright 2018 Eugeniy E. Mikhailov
382 2020 Andreas K. Huettel
383  
384  
385 This is free software; you can redistribute it and/or modify it under
386 the same terms as the Perl 5 programming language system itself.
387  
388 =cut