| 1 | package Lab::Instrument::TDS2024B; | ||
| 2 | #ABSTRACT: Tektronix TDS2024B digital oscilloscope | ||
| 3 | $Lab::Instrument::TDS2024B::VERSION = '3.899'; | ||
| 4 | use v5.20; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | use Lab::Instrument; | ||
| 9 | use Lab::SCPI; | ||
| 10 | use Carp; | ||
| 11 | use English; | ||
| 12 | use Time::HiRes qw(sleep); | ||
| 13 | use Clone 'clone'; | ||
| 14 | use Data::Dumper; | ||
| 15 | |||
| 16 | our $DEBUG = 0; | ||
| 17 | our @ISA = ("Lab::Instrument"); | ||
| 18 | our %fields = ( | ||
| 19 | supported_connections => ['USBtmc'], | ||
| 20 | |||
| 21 | #default settings for connections | ||
| 22 | |||
| 23 | connection_settings => { | ||
| 24 | connection_type => 'USBtmc', | ||
| 25 | usb_vendor => 0x0699, #Tektronix | ||
| 26 | usb_product => 0x036a, #TDS2024A | ||
| 27 | usb_serial => '*', #any serial number | ||
| 28 | read_buffer => 1024, | ||
| 29 | }, | ||
| 30 | |||
| 31 | device_settings => {}, | ||
| 32 | |||
| 33 | # too many characteristics can easily be "messed with" on the front | ||
| 34 | # panel, so only allow changes when scope is "locked". | ||
| 35 | |||
| 36 | device_cache => {}, | ||
| 37 | |||
| 38 | chan_cache => {}, | ||
| 39 | default_chan_cache => { | ||
| 40 | channel => undef, | ||
| 41 | chan_bwlimit => undef, | ||
| 42 | chan_coupling => undef, | ||
| 43 | chan_current_probe => undef, | ||
| 44 | chan_invert => undef, | ||
| 45 | chan_position => undef, | ||
| 46 | chan_probe => undef, | ||
| 47 | chan_scale => undef, | ||
| 48 | chan_yunit => undef, | ||
| 49 | select => undef, | ||
| 50 | }, | ||
| 51 | |||
| 52 | # non-front-panel cache items | ||
| 53 | NFP => [ | ||
| 54 | qw( | ||
| 55 | ID | ||
| 56 | HEADER | ||
| 57 | VERBOSE | ||
| 58 | LOCKED | ||
| 59 | ) | ||
| 60 | ], | ||
| 61 | |||
| 62 | shared_cache => { | ||
| 63 | ID => undef, | ||
| 64 | HEADER => undef, | ||
| 65 | VERBOSE => undef, | ||
| 66 | LOCKED => undef, | ||
| 67 | acquire_mode => undef, | ||
| 68 | acquire_numavg => undef, | ||
| 69 | acquire_stopafter => undef, | ||
| 70 | |||
| 71 | autorange_settings => undef, | ||
| 72 | cursor_type => undef, | ||
| 73 | cursor_x1 => undef, | ||
| 74 | cursor_x2 => undef, | ||
| 75 | cursor_y1 => undef, | ||
| 76 | cursor_y2 => undef, | ||
| 77 | cursor_xunits => undef, | ||
| 78 | cursor_yunits => undef, | ||
| 79 | cursor_source => undef, | ||
| 80 | |||
| 81 | data_encoding => undef, | ||
| 82 | data_destination => undef, | ||
| 83 | data_source => undef, | ||
| 84 | data_start => undef, | ||
| 85 | data_stop => undef, | ||
| 86 | data_width => undef, | ||
| 87 | |||
| 88 | display_contrast => undef, | ||
| 89 | display_format => undef, | ||
| 90 | display_persist => undef, | ||
| 91 | display_style => undef, | ||
| 92 | hardcopy_format => undef, | ||
| 93 | hardcopy_layout => undef, | ||
| 94 | hardcopy_port => undef, | ||
| 95 | |||
| 96 | meas_source_imm => undef, | ||
| 97 | meas_type_imm => undef, | ||
| 98 | meas_units_imm => undef, | ||
| 99 | |||
| 100 | meas_source_1 => undef, | ||
| 101 | meas_type_1 => undef, | ||
| 102 | meas_units_1 => undef, | ||
| 103 | |||
| 104 | meas_source_2 => undef, | ||
| 105 | meas_type_2 => undef, | ||
| 106 | meas_units_2 => undef, | ||
| 107 | |||
| 108 | meas_source_3 => undef, | ||
| 109 | meas_type_3 => undef, | ||
| 110 | meas_units_3 => undef, | ||
| 111 | |||
| 112 | meas_source_4 => undef, | ||
| 113 | meas_type_4 => undef, | ||
| 114 | meas_units_4 => undef, | ||
| 115 | |||
| 116 | meas_source_5 => undef, | ||
| 117 | meas_type_5 => undef, | ||
| 118 | meas_units_4 => undef, | ||
| 119 | |||
| 120 | horiz_view => undef, | ||
| 121 | horiz_position => undef, | ||
| 122 | horiz_scale => undef, | ||
| 123 | delay_position => undef, | ||
| 124 | delay_scale => undef, | ||
| 125 | |||
| 126 | math_definition => undef, | ||
| 127 | math_position => undef, | ||
| 128 | math_scale => undef, | ||
| 129 | fft_xposition => undef, | ||
| 130 | fft_xscale => undef, | ||
| 131 | fft_position => undef, | ||
| 132 | fft_scale => undef, | ||
| 133 | |||
| 134 | trig_type => undef, | ||
| 135 | trig_holdoff => undef, | ||
| 136 | trig_mode => undef, | ||
| 137 | trig_level => undef, | ||
| 138 | |||
| 139 | etrig_source => undef, | ||
| 140 | trig_slope => undef, | ||
| 141 | trig_coupling => undef, | ||
| 142 | |||
| 143 | ptrig_source => undef, | ||
| 144 | trig_pulse_width => undef, | ||
| 145 | trig_pulse_polarity => undef, | ||
| 146 | trig_pulse_when => undef, | ||
| 147 | |||
| 148 | vtrig_source => undef, | ||
| 149 | trig_vid_line => undef, | ||
| 150 | trig_vid_polarity => undef, | ||
| 151 | trig_vid_standard => undef, | ||
| 152 | trig_vid_sync => undef, | ||
| 153 | |||
| 154 | }, | ||
| 155 | |||
| 156 | channel => undef, | ||
| 157 | |||
| 158 | scpi_override => { | ||
| 159 | ACQuire => { | ||
| 160 | NUMACq => undef, | ||
| 161 | NUMAVg => undef, | ||
| 162 | STATE => undef, | ||
| 163 | STOPAfter => undef, | ||
| 164 | }, | ||
| 165 | AUTORate => { | ||
| 166 | STATE => undef, | ||
| 167 | }, | ||
| 168 | AUTOScale => { | ||
| 169 | |||
| 170 | # '' => undef; | ||
| 171 | SIGNAL => undef, | ||
| 172 | }, | ||
| 173 | LOCk => undef, | ||
| 174 | CH => { | ||
| 175 | BANDWIDth => undef, | ||
| 176 | CURRENTPRObe => undef, | ||
| 177 | PRObe => undef, | ||
| 178 | SCAle => undef, | ||
| 179 | VOLt => undef, | ||
| 180 | }, | ||
| 181 | |||
| 182 | CURSor => { | ||
| 183 | HBArs => { | ||
| 184 | UNIts => undef, | ||
| 185 | POSITION => undef, | ||
| 186 | }, | ||
| 187 | VBArs => { | ||
| 188 | UNIts => undef, | ||
| 189 | POSITION => undef, | ||
| 190 | }, | ||
| 191 | SELect => { | ||
| 192 | SOUrce => undef, | ||
| 193 | }, | ||
| 194 | }, | ||
| 195 | CURVe => undef, | ||
| 196 | DATa => { | ||
| 197 | ENCdg => undef, | ||
| 198 | SOUrce => undef, | ||
| 199 | TARget => undef, | ||
| 200 | WIDth => undef, | ||
| 201 | }, | ||
| 202 | DISplay => { | ||
| 203 | CONTRast => undef, | ||
| 204 | STYle => undef, | ||
| 205 | }, | ||
| 206 | |||
| 207 | FILESystem => { | ||
| 208 | DELEte => undef, | ||
| 209 | FREESpace => undef, | ||
| 210 | }, | ||
| 211 | |||
| 212 | HARDCopy => { | ||
| 213 | BUTTON => undef, | ||
| 214 | }, | ||
| 215 | |||
| 216 | HORizontal => { | ||
| 217 | SCAle => undef, | ||
| 218 | SECdiv => undef, | ||
| 219 | RECOrdlength => undef, | ||
| 220 | MAIn => { | ||
| 221 | SCAle => undef, | ||
| 222 | SECdiv => undef, | ||
| 223 | }, | ||
| 224 | DELay => { | ||
| 225 | SCAle => undef, | ||
| 226 | SECdiv => undef, | ||
| 227 | }, | ||
| 228 | }, | ||
| 229 | |||
| 230 | MATH => { | ||
| 231 | DEFINE => undef, | ||
| 232 | FFT => { | ||
| 233 | HORizontal => { | ||
| 234 | SCAle => undef, | ||
| 235 | }, | ||
| 236 | VERtical => { | ||
| 237 | SCAle => undef, | ||
| 238 | }, | ||
| 239 | }, | ||
| 240 | VERtical => { | ||
| 241 | SCAle => undef, | ||
| 242 | }, | ||
| 243 | }, | ||
| 244 | |||
| 245 | MEASUrement => { | ||
| 246 | IMMed => { | ||
| 247 | TYPe => undef, | ||
| 248 | UNIts => undef, | ||
| 249 | SOUrce => undef, | ||
| 250 | }, | ||
| 251 | MEAS => { | ||
| 252 | TYPe => undef, | ||
| 253 | UNIts => undef, | ||
| 254 | SOUrce => undef, | ||
| 255 | }, | ||
| 256 | }, | ||
| 257 | |||
| 258 | TRIGger => { | ||
| 259 | MAIn => { | ||
| 260 | EDGE => { | ||
| 261 | SLOpe => undef, | ||
| 262 | SOUrce => undef, | ||
| 263 | }, | ||
| 264 | HOLDOff => { | ||
| 265 | VALue => undef, | ||
| 266 | }, | ||
| 267 | MODe => undef, | ||
| 268 | TYPe => undef, | ||
| 269 | PULse => { | ||
| 270 | SOUrce => undef, | ||
| 271 | WIDth => { | ||
| 272 | WIDth => undef, | ||
| 273 | }, | ||
| 274 | }, | ||
| 275 | VIDeo => { | ||
| 276 | SOUrce => undef, | ||
| 277 | }, | ||
| 278 | }, | ||
| 279 | STATE => undef, | ||
| 280 | }, | ||
| 281 | |||
| 282 | WFMPre => { | ||
| 283 | BIT_Nr => undef, | ||
| 284 | BYT_Nr => undef, | ||
| 285 | BYT_Or => undef, | ||
| 286 | ENCdg => undef, | ||
| 287 | PT_Off => undef, | ||
| 288 | WFId => undef, | ||
| 289 | XINcr => undef, | ||
| 290 | XUNit => undef, | ||
| 291 | XZEro => undef, | ||
| 292 | YMUlt => undef, | ||
| 293 | YOFf => undef, | ||
| 294 | YUNit => undef, | ||
| 295 | YZEro => undef, | ||
| 296 | CH => { | ||
| 297 | WFId => undef, | ||
| 298 | XINcr => undef, | ||
| 299 | XUNit => undef, | ||
| 300 | XZEro => undef, | ||
| 301 | YMUlt => undef, | ||
| 302 | YOFf => undef, | ||
| 303 | YUNit => undef, | ||
| 304 | YZEro => undef, | ||
| 305 | }, | ||
| 306 | MATH => { | ||
| 307 | WFId => undef, | ||
| 308 | XINcr => undef, | ||
| 309 | XUNit => undef, | ||
| 310 | XZEro => undef, | ||
| 311 | YMUlt => undef, | ||
| 312 | YOFf => undef, | ||
| 313 | YUNit => undef, | ||
| 314 | YZEro => undef, | ||
| 315 | }, | ||
| 316 | REFA => { | ||
| 317 | WFId => undef, | ||
| 318 | XINcr => undef, | ||
| 319 | XUNit => undef, | ||
| 320 | XZEro => undef, | ||
| 321 | YMUlt => undef, | ||
| 322 | YOFf => undef, | ||
| 323 | YUNit => undef, | ||
| 324 | YZEro => undef, | ||
| 325 | }, | ||
| 326 | REFB => { | ||
| 327 | WFId => undef, | ||
| 328 | XINcr => undef, | ||
| 329 | XUNit => undef, | ||
| 330 | XZEro => undef, | ||
| 331 | YMUlt => undef, | ||
| 332 | YOFf => undef, | ||
| 333 | YUNit => undef, | ||
| 334 | YZEro => undef, | ||
| 335 | }, | ||
| 336 | REFC => { | ||
| 337 | WFId => undef, | ||
| 338 | XINcr => undef, | ||
| 339 | XUNit => undef, | ||
| 340 | XZEro => undef, | ||
| 341 | YMUlt => undef, | ||
| 342 | YOFf => undef, | ||
| 343 | YUNit => undef, | ||
| 344 | YZEro => undef, | ||
| 345 | }, | ||
| 346 | REFD => { | ||
| 347 | WFId => undef, | ||
| 348 | XINcr => undef, | ||
| 349 | XUNit => undef, | ||
| 350 | XZEro => undef, | ||
| 351 | YMUlt => undef, | ||
| 352 | YOFf => undef, | ||
| 353 | YUNit => undef, | ||
| 354 | YZEro => undef, | ||
| 355 | }, | ||
| 356 | }, | ||
| 357 | }, | ||
| 358 | ); | ||
| 359 | |||
| 360 | |||
| 361 | sub new { | ||
| 362 | my $proto = shift; | ||
| 363 | my $class = ref($proto) || $proto; | ||
| 364 | |||
| 365 | foreach my $k ( keys( %{ $fields{default_chan_cache} } ) ) { | ||
| 366 | $fields{device_cache}->{$k} = $fields{default_chan_cache}->{$k}; | ||
| 367 | } | ||
| 368 | |||
| 369 | foreach my $k ( keys( %{ $fields{shared_cache} } ) ) { | ||
| 370 | $fields{device_cache}->{$k} = $fields{shared_cache}->{$k}; | ||
| 371 | } | ||
| 372 | |||
| 373 | my $self = $class->SUPER::new(@_); | ||
| 374 | $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__); | ||
| 375 | |||
| 376 | $self->{connection_settings}->{READ_BUFFER} = 1024; # TDS2024B limit? | ||
| 377 | $self->{config}->{no_cache} = 1; | ||
| 378 | $self->{config}->{default_read_mode} = 'cache'; | ||
| 379 | $DEBUG = $self->{config}->{debug} if exists $self->{config}->{debug}; | ||
| 380 | |||
| 381 | # initialize channel caches | ||
| 382 | foreach my $ch (qw(CH1 CH2 CH3 CH4 MATH REFA REFB REFC REFD)) { | ||
| 383 | $self->{chan_cache}->{$ch} = {}; | ||
| 384 | foreach my $k ( keys( %{ $self->{default_chan_cache} } ) ) { | ||
| 385 | $self->{chan_cache}->{$ch}->{$k} | ||
| 386 | = $self->{default_chan_cache}->{$k}; | ||
| 387 | } | ||
| 388 | $self->{chan_cache}->{$ch}->{channel} = $ch; | ||
| 389 | foreach my $k ( keys( %{ $self->{shared_cache} } ) ) { | ||
| 390 | $self->{chan_cache}->{$ch}->{$k} = $self->{shared_cache}->{$k}; | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | $self->{device_cache} = $self->{chan_cache}->{CH1}; | ||
| 395 | $self->{channel} = "CH1"; | ||
| 396 | return $self; | ||
| 397 | } | ||
| 398 | |||
| 399 | #initialize scope.. this means setting up status bit masking | ||
| 400 | #for non-destructive testing for device errors | ||
| 401 | |||
| 402 | sub _device_init { | ||
| 403 | my $self = shift; | ||
| 404 | $self->write("*ESE 60") | ||
| 405 | ; # 0x3C -> CME+EXE+DDE+QYE to bit 5 of SBR (read with *STB?) | ||
| 406 | $self->write("*CLS"); # clear status registers | ||
| 407 | } | ||
| 408 | |||
| 409 | { # keep perl from bitching about this stuff | ||
| 410 | no warnings qw(redefine); | ||
| 411 | |||
| 412 | # calling argument parsing; this is an extension of the | ||
| 413 | # _check_args and _check_args_strict routines in Instrument.pm, | ||
| 414 | # allowing more flexibility in how routines are called. | ||
| 415 | # In particular routine(a=>1,b=>2,..) and | ||
| 416 | # routine({a=>1,b=>2,..}) can both be used. | ||
| 417 | |||
| 418 | # note: if this code does not properly recognize the syntax, | ||
| 419 | # then you have to use the {key=>value...} form. | ||
| 420 | |||
| 421 | # calling: | ||
| 422 | # ($par1,$par2,$par3,$tail) = $self->_Xcheck_args(\@_,qw(par1 par2 par3)); | ||
| 423 | # or, for compatibility: | ||
| 424 | # ($par1,$par2,$par3,$tail) = $self->_Xcheck_args(\@_,[qw(par1 par2 par3)]); | ||
| 425 | |||
| 426 | sub Lab::Instrument::_check_args { | ||
| 427 | my $self = shift; | ||
| 428 | my $args = shift; | ||
| 429 | my $params = [@_]; | ||
| 430 | $params = $params->[0] if ref( $params->[0] ) eq 'ARRAY'; | ||
| 431 | my $arguments = {}; | ||
| 432 | |||
| 433 | if ( $#{$args} == 0 && ref( $args->[0] ) eq 'HASH' ) { # case 3 | ||
| 434 | %{$arguments} = ( %{ $args->[0] } ); | ||
| 435 | } | ||
| 436 | else { | ||
| 437 | my $simple = 1; | ||
| 438 | if ( $#{$args} & 1 == 1 ) { # must have even # arguments | ||
| 439 | my $found = {}; | ||
| 440 | for ( my $j = 0; $j <= $#{$args}; $j += 2 ) { | ||
| 441 | if ( ref( $args->[$j] ) ne '' ) { # a ref for a key? no | ||
| 442 | $simple = 1; | ||
| 443 | last; | ||
| 444 | } | ||
| 445 | foreach my $p ( @{$params} ) { # named param | ||
| 446 | $simple = 0 if $p eq $args->[$j]; | ||
| 447 | } | ||
| 448 | if ( exists( $found->{ $args->[$j] } ) ) | ||
| 449 | { # key used 2x? no | ||
| 450 | $simple = 1; | ||
| 451 | last; | ||
| 452 | } | ||
| 453 | $found->{ $args->[$j] } = 1; | ||
| 454 | } | ||
| 455 | } | ||
| 456 | |||
| 457 | if ($simple) { # case 1 | ||
| 458 | my $i = 0; | ||
| 459 | foreach my $arg ( @{$args} ) { | ||
| 460 | if ( defined @{$params}[$i] ) { | ||
| 461 | $arguments->{ @{$params}[$i] } = $arg; | ||
| 462 | } | ||
| 463 | $i++; | ||
| 464 | } | ||
| 465 | } | ||
| 466 | else { # case 2 | ||
| 467 | %{$arguments} = ( @{$args} ); | ||
| 468 | } | ||
| 469 | } | ||
| 470 | |||
| 471 | my @return_args = (); | ||
| 472 | |||
| 473 | foreach my $param ( @{$params} ) { | ||
| 474 | if ( exists $arguments->{$param} ) { | ||
| 475 | push( @return_args, $arguments->{$param} ); | ||
| 476 | delete $arguments->{$param}; | ||
| 477 | } | ||
| 478 | else { | ||
| 479 | push( @return_args, undef ); | ||
| 480 | } | ||
| 481 | } | ||
| 482 | |||
| 483 | push( @return_args, $arguments ); | ||
| 484 | |||
| 485 | if (wantarray) { | ||
| 486 | return @return_args; | ||
| 487 | } | ||
| 488 | else { | ||
| 489 | return $return_args[0]; | ||
| 490 | } | ||
| 491 | } | ||
| 492 | |||
| 493 | sub Lab::Instrument::_check_args_strict { | ||
| 494 | my $self = shift; | ||
| 495 | my $args = shift; | ||
| 496 | my $params = [@_]; | ||
| 497 | $params = $params->[0] if ref( $params->[0] ) eq 'ARRAY'; | ||
| 498 | |||
| 499 | my @result = $self->_check_args( $args, $params ); | ||
| 500 | |||
| 501 | my $num_params = @result - 1; | ||
| 502 | |||
| 503 | for ( my $i = 0; $i < $num_params; ++$i ) { | ||
| 504 | if ( not defined $result[$i] ) { | ||
| 505 | croak("missing mandatory argument '$params->[$i]'"); | ||
| 506 | } | ||
| 507 | } | ||
| 508 | |||
| 509 | if (wantarray) { | ||
| 510 | return @result; | ||
| 511 | } | ||
| 512 | else { | ||
| 513 | return $result[0]; | ||
| 514 | } | ||
| 515 | } | ||
| 516 | |||
| 517 | } | ||
| 518 | # | ||
| 519 | # utility function: check header/verbose and parse | ||
| 520 | # query reply appropriately; remove quotes in present | ||
| 521 | # ex: $self->_parseReply('ACQ:MODE average',qw{AVE PEAK SAM}) | ||
| 522 | # gives AVE | ||
| 523 | sub _parseReply { | ||
| 524 | my $self = shift; | ||
| 525 | my $in = shift; | ||
| 526 | |||
| 527 | my $h = $self->get_header(); | ||
| 528 | if ($h) { | ||
| 529 | my $c; | ||
| 530 | ( $c, $in ) = split( /\s+/, $in ); | ||
| 531 | return '' unless defined($in) && $in ne ''; | ||
| 532 | } | ||
| 533 | |||
| 534 | # remove quotes on strings | ||
| 535 | if ( $in =~ /^\"(.*)\"$/ ) { | ||
| 536 | $in = $1; | ||
| 537 | $in =~ s/\"\"/"/g; | ||
| 538 | } | ||
| 539 | elsif ( $in =~ /^\'(.*)\'$/ ) { | ||
| 540 | $in = $1; | ||
| 541 | $in =~ s/\'\'/'/g; | ||
| 542 | } | ||
| 543 | |||
| 544 | return $in unless $#_ > -1; | ||
| 545 | my $v = $self->get_verbose(); | ||
| 546 | return $in unless $v; | ||
| 547 | return _keyword( $in, @_ ); | ||
| 548 | } | ||
| 549 | |||
| 550 | # | ||
| 551 | # select keyword | ||
| 552 | # example: $got = _keyword('input', qw{ IN OUT EXT } ) | ||
| 553 | # returns $got = 'IN' | ||
| 554 | |||
| 555 | sub _keyword { | ||
| 556 | my $in = shift; | ||
| 557 | $in = shift if ref($in) eq 'HASH'; # dispose of $self->_keyword form... | ||
| 558 | my $r; | ||
| 559 | |||
| 560 | $in =~ s/^\s+//; | ||
| 561 | foreach my $k (@_) { | ||
| 562 | if ( $in =~ /^$k/i ) { | ||
| 563 | return $k; | ||
| 564 | } | ||
| 565 | } | ||
| 566 | Lab::Exception::CorruptParameter->throw("Invalid keyword input '$in'\n"); | ||
| 567 | } | ||
| 568 | |||
| 569 | # convert 'short form' keywords to long form | ||
| 570 | |||
| 571 | sub _bloat { | ||
| 572 | my $in = shift; | ||
| 573 | $in = shift if ref($in) eq 'HASH'; # dispose of $self->_bloat | ||
| 574 | my $tr = shift; # hash of short=>long: | ||
| 575 | |||
| 576 | $in =~ s/^\s+//; | ||
| 577 | $in =~ s/\s+$//; | ||
| 578 | return $in if $in eq ''; | ||
| 579 | |||
| 580 | foreach my $k ( keys( %{$tr} ) ) { | ||
| 581 | if ( $in =~ /^${k}/i ) { | ||
| 582 | return $tr->{$k}; | ||
| 583 | } | ||
| 584 | } | ||
| 585 | |||
| 586 | return uc($in); # nothing matched | ||
| 587 | } | ||
| 588 | |||
| 589 | # parse a GPIB number with suffix, units | ||
| 590 | # $result = _parseNRf($numberstring,$unit1[,$unit2,...]) | ||
| 591 | # _parseNRf('maximum','foo) -> 'MAX' | ||
| 592 | # _parseNRf('-3.7e+3kJ','j') -> -3.7e6 | ||
| 593 | # _parseNRf('2.3ksec','s','sec') -> 2300 ('s' and 'sec' alternate units) | ||
| 594 | # note special cases for suffixes: MHZ, MOHM, MA | ||
| 595 | # also handling 'dB' -> (number)dB(magnitudesuffix)(unit V|W|etc) | ||
| 596 | # | ||
| 597 | # if problem, string returned starts 'ERR: ..message...' | ||
| 598 | # see IEEE std 488-2 7.7.3 | ||
| 599 | |||
| 600 | sub _parseNRf { | ||
| 601 | my $in = shift; | ||
| 602 | $in = shift if ref($in) eq 'HASH'; # $self->_parseNRf handling... | ||
| 603 | my $un = shift; | ||
| 604 | $un = '' unless defined $un; | ||
| 605 | my $us; | ||
| 606 | |||
| 607 | if ( ref($un) eq 'ARRAY' ) { | ||
| 608 | $us = $un; | ||
| 609 | } | ||
| 610 | elsif ( ref($un) eq 'SCALAR' ) { | ||
| 611 | $us = [ $$un, @_ ]; | ||
| 612 | } | ||
| 613 | elsif ( ref($un) eq '' ) { | ||
| 614 | $us = [ $un, @_ ]; | ||
| 615 | } | ||
| 616 | my $str = $in; | ||
| 617 | |||
| 618 | $str =~ s/^\s+//; | ||
| 619 | $str =~ s/\s+$//; | ||
| 620 | |||
| 621 | if ( $str =~ /^MIN/i ) { | ||
| 622 | return 'MIN'; | ||
| 623 | } | ||
| 624 | if ( $str =~ /^MAX/i ) { | ||
| 625 | return 'MAX'; | ||
| 626 | } | ||
| 627 | |||
| 628 | my $mant = 0; | ||
| 629 | my $exp = 0; | ||
| 630 | if ( $str =~ /^([+\-]?(\d+\.\d*|\d+|\d*\.\d+))\s*/i ) { | ||
| 631 | $mant = $1; | ||
| 632 | $str = $POSTMATCH; | ||
| 633 | return $mant if $str eq ''; | ||
| 634 | if ( $str =~ /^e\s*([+\-]?\d+)\s*/i ) { | ||
| 635 | $exp = $1; | ||
| 636 | $str = $POSTMATCH; | ||
| 637 | } | ||
| 638 | return $mant * ( 10**$exp ) if $str eq ''; | ||
| 639 | |||
| 640 | my $kexp = $exp; | ||
| 641 | my $kstr = $str; | ||
| 642 | foreach my $u ( @{$us} ) { | ||
| 643 | $u =~ s/^\s+//; | ||
| 644 | $u =~ s/\s+$//; | ||
| 645 | |||
| 646 | $str = $kstr; | ||
| 647 | $exp = $kexp; | ||
| 648 | if ( $u =~ /^db/i ) { # db(magnitude_suffix)?(V|W|... unit)? | ||
| 649 | my $dbt = $POSTMATCH; | ||
| 650 | if ( $str =~ /^dBex(${dbt})?$/i ) { | ||
| 651 | $exp += 18; | ||
| 652 | } | ||
| 653 | elsif ( $str =~ /^dBpe(${dbt})?$/i ) { | ||
| 654 | $exp += 15; | ||
| 655 | } | ||
| 656 | elsif ( $str =~ /^dBt(${dbt})?$/i ) { | ||
| 657 | $exp += 12; | ||
| 658 | } | ||
| 659 | elsif ( $str =~ /^dBg(${dbt})?$/i ) { | ||
| 660 | $exp += 9; | ||
| 661 | } | ||
| 662 | elsif ( $str =~ /^dBma(${dbt})$/i ) { | ||
| 663 | $exp += 6; | ||
| 664 | } | ||
| 665 | elsif ( $str =~ /^dBk(${dbt})?$/i ) { | ||
| 666 | $exp += 3; | ||
| 667 | } | ||
| 668 | elsif ( $str =~ /^dBm(${dbt})?$/i ) { | ||
| 669 | $exp -= 3; | ||
| 670 | } | ||
| 671 | elsif ( $str =~ /^dBu(${dbt})?$/i ) { | ||
| 672 | $exp -= 6; | ||
| 673 | } | ||
| 674 | elsif ( $str =~ /^dBn(${dbt})?$/i ) { | ||
| 675 | $exp -= 9; | ||
| 676 | } | ||
| 677 | elsif ( $str =~ /^dBp(${dbt})?$/i ) { | ||
| 678 | $exp -= 12; | ||
| 679 | } | ||
| 680 | elsif ( $str =~ /^dBf(${dbt})?$/i ) { | ||
| 681 | $exp -= 15; | ||
| 682 | } | ||
| 683 | elsif ( $str =~ /^dB${dbt}$/i ) { | ||
| 684 | $exp += 0; | ||
| 685 | } | ||
| 686 | else { | ||
| 687 | next; | ||
| 688 | } | ||
| 689 | } | ||
| 690 | else { # regular units stuff: (magnitude_suffix)(unit)? | ||
| 691 | if ( $str =~ /^ex(${u})?$/i ) { | ||
| 692 | $exp += 18; | ||
| 693 | } | ||
| 694 | elsif ( $str =~ /^pe(${u})?$/i ) { | ||
| 695 | $exp += 15; | ||
| 696 | } | ||
| 697 | elsif ( $str =~ /^t(${u})?$/i ) { | ||
| 698 | $exp += 12; | ||
| 699 | } | ||
| 700 | elsif ( $str =~ /^g(${u})?$/i ) { | ||
| 701 | $exp += 9; | ||
| 702 | } | ||
| 703 | elsif ( $u =~ /(HZ|OHM)/i && $str =~ /^ma?(${u})$/i ) { | ||
| 704 | $exp += 6; | ||
| 705 | } | ||
| 706 | elsif ( $u =~ /A/i && $str =~ /^ma$/i ) { | ||
| 707 | $exp -= 3; | ||
| 708 | } | ||
| 709 | elsif ( $u !~ /(HZ|OHM)/i && $str =~ /^ma(${u})?$/i ) { | ||
| 710 | $exp += 6; | ||
| 711 | } | ||
| 712 | elsif ( $str =~ /^k(${u})?$/i ) { | ||
| 713 | $exp += 3; | ||
| 714 | } | ||
| 715 | elsif ( $str =~ /^m(${u})?$/i ) { | ||
| 716 | $exp -= 3; | ||
| 717 | } | ||
| 718 | elsif ( $str =~ /^u(${u})?$/i ) { | ||
| 719 | $exp -= 6; | ||
| 720 | } | ||
| 721 | elsif ( $str =~ /^n(${u})?$/i ) { | ||
| 722 | $exp -= 9; | ||
| 723 | } | ||
| 724 | elsif ( $str =~ /^p(${u})?$/i ) { | ||
| 725 | $exp -= 12; | ||
| 726 | } | ||
| 727 | elsif ( $str =~ /^f(${u})?$/i ) { | ||
| 728 | $exp -= 15; | ||
| 729 | } | ||
| 730 | elsif ( $str =~ /^${u}$/i ) { | ||
| 731 | $exp += 0; | ||
| 732 | } | ||
| 733 | else { | ||
| 734 | next; | ||
| 735 | } | ||
| 736 | } | ||
| 737 | return $mant * ( 10**$exp ); | ||
| 738 | } | ||
| 739 | } | ||
| 740 | return "ERR: '$str' number parsing problem"; | ||
| 741 | |||
| 742 | } | ||
| 743 | |||
| 744 | |||
| 745 | sub reset { | ||
| 746 | my $self = shift; | ||
| 747 | $self->write("*RST"); | ||
| 748 | $self->_debug(); | ||
| 749 | $self->_reset_cache(); | ||
| 750 | } | ||
| 751 | |||
| 752 | our $_rst_state = { | ||
| 753 | LOCKED => 'NON', | ||
| 754 | HEADER => '1', | ||
| 755 | VERBOSE => '1', | ||
| 756 | |||
| 757 | data_encoding => 'RIBINARY', | ||
| 758 | data_destination => 'REFA', | ||
| 759 | data_source => 'CH1', | ||
| 760 | data_start => 1, | ||
| 761 | data_stop => 2500, | ||
| 762 | data_width => 1, | ||
| 763 | |||
| 764 | display_format => 'YT', | ||
| 765 | display_style => 'VECTORS', | ||
| 766 | display_persist => 0, | ||
| 767 | display_contrast => 50, | ||
| 768 | |||
| 769 | acquire_mode => 'SAMPLE', | ||
| 770 | acquire_numavg => 16, | ||
| 771 | acquire_stopafter => 'RUNSTOP', | ||
| 772 | autorange_settings => 'BOTH', | ||
| 773 | |||
| 774 | chan_probe => 10, | ||
| 775 | chan_current_probe => 10, | ||
| 776 | chan_scale => 1.0, | ||
| 777 | chan_position => 0.0, | ||
| 778 | chan_coupling => 'DC', | ||
| 779 | chan_bwlimit => 0, | ||
| 780 | chan_invert => 0, | ||
| 781 | chan_yunit => 'V', | ||
| 782 | |||
| 783 | cursor_type => 'OFF', | ||
| 784 | cursor_source => 'CH1', | ||
| 785 | cursor_vbars_units => 'SECONDS', | ||
| 786 | cursor_x1 => -2.0e-3, | ||
| 787 | cursor_x2 => 2.0e-3, | ||
| 788 | cursor_y1 => 3.2, | ||
| 789 | cursor_y2 => -3.2, | ||
| 790 | |||
| 791 | hardcopy_format => 'JPEG', | ||
| 792 | hardcopy_layout => 'PORTRAIT', | ||
| 793 | hardcopy_port => 'USB', | ||
| 794 | |||
| 795 | horiz_view => 'MAIN', | ||
| 796 | horiz_scale => 5.0E-4, | ||
| 797 | horiz_position => 0.0E0, | ||
| 798 | delay_scale => 5.0E-5, | ||
| 799 | delay_position => 0.0E0, | ||
| 800 | |||
| 801 | meas_type_1 => 'NONE', | ||
| 802 | meas_source_1 => 'CH1', | ||
| 803 | meas_units_1 => undef, | ||
| 804 | |||
| 805 | meas_type_2 => 'NONE', | ||
| 806 | meas_source_2 => 'CH1', | ||
| 807 | meas_units_2 => undef, | ||
| 808 | |||
| 809 | meas_type_3 => 'NONE', | ||
| 810 | meas_source_3 => 'CH1', | ||
| 811 | meas_units_3 => undef, | ||
| 812 | |||
| 813 | meas_type_4 => 'NONE', | ||
| 814 | meas_source_4 => 'CH1', | ||
| 815 | meas_units_4 => undef, | ||
| 816 | |||
| 817 | meas_type_5 => 'NONE', | ||
| 818 | meas_source_5 => 'CH1', | ||
| 819 | meas_units_5 => undef, | ||
| 820 | |||
| 821 | meas_type_imm => 'PERIOD', | ||
| 822 | meas_source_imm => 'CH1', | ||
| 823 | meas_units_imm => 'S', | ||
| 824 | |||
| 825 | math_definition => 'CH1 - CH2', | ||
| 826 | math_position => 0.0E0, | ||
| 827 | math_scale => 2.0E0, | ||
| 828 | fft_xposition => 5.0E1, | ||
| 829 | fft_xscale => 1.0E0, | ||
| 830 | fft_position => 0.0E0, | ||
| 831 | fft_scale => 1.0E0, | ||
| 832 | |||
| 833 | trig_mode => 'AUTO', | ||
| 834 | trig_type => 'EDGE', | ||
| 835 | trig_holdoff => 5.0E-7, | ||
| 836 | trig_level => 0.0E0, | ||
| 837 | |||
| 838 | etrig_source => 'CH1', | ||
| 839 | trig_coupling => 'DC', | ||
| 840 | trig_slope => 'RISE', | ||
| 841 | |||
| 842 | vtrig_source => 'CH1', | ||
| 843 | trig_vid_sync => 'LINE', | ||
| 844 | trig_vid_polarity => 'NORMAL', | ||
| 845 | trig_vid_line => 1, | ||
| 846 | trig_vid_standard => 'NTSC', | ||
| 847 | |||
| 848 | ptrig_source => 'CH1', | ||
| 849 | trig_pulse_polarity => 'POSITIVE', | ||
| 850 | trig_pulse_width => 1.0E-3, | ||
| 851 | trig_pulse_when => 'EQUAL', | ||
| 852 | |||
| 853 | }; | ||
| 854 | |||
| 855 | sub _reset_cache { | ||
| 856 | my $self = shift; | ||
| 857 | |||
| 858 | for my $k ( keys( %{$_rst_state} ) ) { | ||
| 859 | $self->{device_cache}->{$k} = $_rst_state->{$k}; | ||
| 860 | for ( my $ch = 1; $ch <= 4; $ch++ ) { | ||
| 861 | $self->{chan_cache}->{"CH$ch"}->{select} = ( $ch == 1 ? 1 : 0 ); | ||
| 862 | next if "CH$ch" eq $self->{channel}; | ||
| 863 | $self->{chan_cache}->{"CH$ch"}->{$k} = $_rst_state->{$k}; | ||
| 864 | } | ||
| 865 | } | ||
| 866 | $self->{device_cache}->{select} = ( $self->{channel} eq 'CH1' ? 1 : 0 ); | ||
| 867 | foreach my $wfm (qw(MATH REFA REFB REFC REFD)) { | ||
| 868 | $self->{chan_cache}->{$wfm}->{select} = 0; | ||
| 869 | } | ||
| 870 | } | ||
| 871 | |||
| 872 | # print error queue; meant to be called at end of routine | ||
| 873 | # so uses 'caller' info to label the subroutine | ||
| 874 | sub _debug { | ||
| 875 | return unless $DEBUG; | ||
| 876 | my $self = shift; | ||
| 877 | my ( $p, $f, $l, $subr ) = caller(1); | ||
| 878 | while (1) { | ||
| 879 | my ( $code, $msg ) = $self->get_error(); | ||
| 880 | last if $code == 0; | ||
| 881 | print "$subr\t$code: $msg\n"; | ||
| 882 | } | ||
| 883 | } | ||
| 884 | |||
| 885 | |||
| 886 | sub get_error { | ||
| 887 | my $self = shift; | ||
| 888 | |||
| 889 | my $err = $self->query("*ESR?"); | ||
| 890 | if ( $err == 0 ) { | ||
| 891 | return ( 0, "No events to report - queue empty" ); | ||
| 892 | } | ||
| 893 | my $msg = $self->query("EVM?"); | ||
| 894 | |||
| 895 | if ( $msg =~ /^([\w:]+\s+)?(\d+),(.*)$/i ) { | ||
| 896 | my $code = $2; | ||
| 897 | $msg = $3; | ||
| 898 | $msg =~ s/^\"//; | ||
| 899 | $msg =~ s/\"$//; | ||
| 900 | $msg =~ s/\"\"/"/g; | ||
| 901 | return ( $code, $msg ); | ||
| 902 | } | ||
| 903 | else { | ||
| 904 | return ( -1, $msg ); | ||
| 905 | } | ||
| 906 | |||
| 907 | # (:EVMSG 110, "command head") | ||
| 908 | } | ||
| 909 | |||
| 910 | |||
| 911 | our $sbits = [qw(OPC RQC QYE DDE EXE CME URQ PON)]; | ||
| 912 | |||
| 913 | sub get_status { | ||
| 914 | my $self = shift; | ||
| 915 | my $bit = shift; | ||
| 916 | my $s = {}; | ||
| 917 | |||
| 918 | my $r = $self->query('*ESR?'); | ||
| 919 | $self->_debug(); | ||
| 920 | |||
| 921 | for ( my $j = 0; $j < 7; $j++ ) { | ||
| 922 | $s->{ $sbits->[$j] } = ( $r >> $j ) & 0x01; | ||
| 923 | } | ||
| 924 | $s->{ERROR} = $s->{CME} | $s->{EXE} | $s->{DDE} | $s->{QYE}; | ||
| 925 | |||
| 926 | return $s->{ uc($bit) } if defined $bit; | ||
| 927 | return $s; | ||
| 928 | } | ||
| 929 | |||
| 930 | |||
| 931 | sub get_datetime { | ||
| 932 | my $self = shift; | ||
| 933 | my $d = $self->query("DATE?"); | ||
| 934 | $d = $self->_parseReply($d); | ||
| 935 | |||
| 936 | my $t = $self->query("TIM?"); | ||
| 937 | $t = $self->_parseReply($t); | ||
| 938 | return "$d $t"; | ||
| 939 | } | ||
| 940 | |||
| 941 | |||
| 942 | sub set_datetime { | ||
| 943 | my $self = shift; | ||
| 944 | my $unixtime = shift; | ||
| 945 | $unixtime = time() unless defined $unixtime; | ||
| 946 | |||
| 947 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = | ||
| 948 | localtime($unixtime); | ||
| 949 | |||
| 950 | my $date = sprintf('%04d-%02d-%02d',$year+1900,$mon+1,$mday); | ||
| 951 | my $time = sprintf('%02d:%02d:%02d',$hour,$min,$sec); | ||
| 952 | |||
| 953 | $self->write("DATE \"$date\""); | ||
| 954 | $self->write("TIME \"$time\""); | ||
| 955 | |||
| 956 | return "$date $time"; | ||
| 957 | } | ||
| 958 | |||
| 959 | |||
| 960 | |||
| 961 | sub wait_done { | ||
| 962 | my $self = shift; | ||
| 963 | my ( $time, $dt, $tail ) | ||
| 964 | = $self->_check_args( \@_, qw(timeout checkinterval) ); | ||
| 965 | |||
| 966 | my $tmax; | ||
| 967 | |||
| 968 | $time = '10s' unless defined $time; | ||
| 969 | |||
| 970 | if ( $time =~ /\s*(INF|MAX)/i ) { | ||
| 971 | $tmax = -1; | ||
| 972 | } | ||
| 973 | else { | ||
| 974 | $tmax = _parseNRf( $time, 's' ); | ||
| 975 | if ( $time =~ /(ERR|MIN|MAX)/ || $tmax <= 0 ) { | ||
| 976 | Lab::Exception::CorruptParameter->throw( | ||
| 977 | "Invalid time input '$time'\n"); | ||
| 978 | return; | ||
| 979 | } | ||
| 980 | } | ||
| 981 | |||
| 982 | my $dtcheck; | ||
| 983 | $dt = '500ms' unless defined $dt; | ||
| 984 | $dtcheck = _parseNRf( $dt, 's' ); | ||
| 985 | if ( $dtcheck =~ /(ERR|MIN|MAX)/ || $dtcheck <= 0 ) { | ||
| 986 | Lab::Exception::CorruptParameter->throw( | ||
| 987 | "Invalid time check interval input '$dt'\n"); | ||
| 988 | return; | ||
| 989 | } | ||
| 990 | |||
| 991 | my $n; | ||
| 992 | if ( $tmax == -1 ) { | ||
| 993 | $n = -1; | ||
| 994 | } | ||
| 995 | else { | ||
| 996 | $n = $tmax / $dtcheck; | ||
| 997 | |||
| 998 | $n = int( $n + 0.5 ); | ||
| 999 | $n = 1 if $n < 1; | ||
| 1000 | $n++; | ||
| 1001 | } | ||
| 1002 | |||
| 1003 | while (1) { | ||
| 1004 | return 1 if $self->query('BUSY?') =~ /^(:BUSY )?\s*0/i; | ||
| 1005 | return 0 if $n-- == 0; | ||
| 1006 | sleep($dtcheck); | ||
| 1007 | } | ||
| 1008 | } | ||
| 1009 | |||
| 1010 | |||
| 1011 | sub test_busy { | ||
| 1012 | my $self = shift; | ||
| 1013 | return 1 if $self->query('BUSY?') =~ /^(:BUSY )?\s*1/i; | ||
| 1014 | return 0; | ||
| 1015 | } | ||
| 1016 | |||
| 1017 | |||
| 1018 | sub get_id { | ||
| 1019 | my $self = shift; | ||
| 1020 | my ($tail) = $self->_check_args( \@_ ); | ||
| 1021 | |||
| 1022 | $tail->{read_mode} = $self->{config}->{default_read_mode} | ||
| 1023 | unless exists( $tail->{read_mode} ) && defined( $tail->{read_mode} ); | ||
| 1024 | |||
| 1025 | if ( $tail->{read_mode} ne 'cache' | ||
| 1026 | || !defined( $self->{device_cache}->{ID} ) ) { | ||
| 1027 | $self->{device_cache}->{ID} = $self->query('*IDN?'); | ||
| 1028 | $self->_debug(); | ||
| 1029 | } | ||
| 1030 | return $self->{device_cache}->{ID}; | ||
| 1031 | } | ||
| 1032 | |||
| 1033 | |||
| 1034 | sub get_header { | ||
| 1035 | my $self = shift; | ||
| 1036 | |||
| 1037 | my ($tail) = $self->_check_args( \@_ ); | ||
| 1038 | |||
| 1039 | $tail->{read_mode} = $self->{config}->{default_read_mode} | ||
| 1040 | unless exists( $tail->{read_mode} ) && defined( $tail->{read_mode} ); | ||
| 1041 | |||
| 1042 | if ( $tail->{read_mode} ne 'cache' | ||
| 1043 | || !defined( $self->{device_cache}->{HEADER} ) ) { | ||
| 1044 | my $r = $self->query('HEAD?'); | ||
| 1045 | $self->_debug(); | ||
| 1046 | |||
| 1047 | # can't use the _parseReply here... | ||
| 1048 | if ( $r =~ /HEAD(er)?\s+([\w]+)/i ) { | ||
| 1049 | $r = $2; | ||
| 1050 | } | ||
| 1051 | if ( $r =~ /(1|ON)/i ) { | ||
| 1052 | $self->{device_cache}->{HEADER} = 1; | ||
| 1053 | } | ||
| 1054 | else { | ||
| 1055 | $self->{device_cache}->{HEADER} = 0; | ||
| 1056 | } | ||
| 1057 | } | ||
| 1058 | return $self->{device_cache}->{HEADER}; | ||
| 1059 | } | ||
| 1060 | |||
| 1061 | |||
| 1062 | sub save { | ||
| 1063 | my $self = shift; | ||
| 1064 | my ($in) = $self->_check_args_strict( \@_, 'setup' ); | ||
| 1065 | |||
| 1066 | if ( $in !~ /^s*\d+\s*$/ || $in < 1 || $in > 10 || int($in) != $in ) { | ||
| 1067 | Lab::Exception::CorruptParameter->throw( | ||
| 1068 | "Invalid save setup number '$in'\n"); | ||
| 1069 | return; | ||
| 1070 | } | ||
| 1071 | |||
| 1072 | $self->write("*SAV $in"); | ||
| 1073 | $self->_debug(); | ||
| 1074 | } | ||
| 1075 | |||
| 1076 | |||
| 1077 | sub recall { | ||
| 1078 | my $self = shift; | ||
| 1079 | my ($in) = $self->_check_args_strict( \@_, 'setup' ); | ||
| 1080 | |||
| 1081 | if ( $in !~ /^\s*\d+\s*$/ || $in < 1 || $in > 10 || $in != int($in) ) { | ||
| 1082 | Lab::Exception::CorruptParameter->throw( | ||
| 1083 | "Invalid setup save location '$in'\n"); | ||
| 1084 | return; | ||
| 1085 | } | ||
| 1086 | $self->write("*RCL $in"); | ||
| 1087 | $self->_debug(); | ||
| 1088 | } | ||
| 1089 | |||
| 1090 | |||
| 1091 | sub set_header { | ||
| 1092 | my $self = shift; | ||
| 1093 | my ($in) = $self->_check_args_strict( \@_, 'header' ); | ||
| 1094 | my $h; | ||
| 1095 | |||
| 1096 | if ( $in =~ /^\s*([1-9]|on|y|t)/i ) { | ||
| 1097 | $h = 1; | ||
| 1098 | } | ||
| 1099 | elsif ( $in =~ /^\s*(0|off|n|f)/i ) { | ||
| 1100 | $h = 0; | ||
| 1101 | } | ||
| 1102 | else { | ||
| 1103 | Lab::Exception::CorruptParameter->throw( | ||
| 1104 | "Invalid boolean input '$in'\n"); | ||
| 1105 | return; | ||
| 1106 | } | ||
| 1107 | return | ||
| 1108 | if defined( $self->{device_cache}->{HEADER} ) | ||
| 1109 | && $self->{device_cache}->{HEADER} == $h; | ||
| 1110 | |||
| 1111 | $self->write("HEAD $h"); | ||
| 1112 | $self->{device_cache}->{HEADER} = $h; | ||
| 1113 | $self->_debug(); | ||
| 1114 | } | ||
| 1115 | |||
| 1116 | |||
| 1117 | sub get_verbose { | ||
| 1118 | my $self = shift; | ||
| 1119 | my ($tail) = $self->_check_args( \@_ ); | ||
| 1120 | |||
| 1121 | $tail->{read_mode} = $self->{config}->{default_read_mode} | ||
| 1122 | unless exists( $tail->{read_mode} ) && defined( $tail->{read_mode} ); | ||
| 1123 | |||
| 1124 | if ( $tail->{read_mode} ne 'cache' | ||
| 1125 | || !defined( $self->{device_cache}->{VERBOSE} ) ) { | ||
| 1126 | my $r = $self->query('VERB?'); | ||
| 1127 | $self->_debug(); | ||
| 1128 | |||
| 1129 | # can't use the _parseReply here... | ||
| 1130 | if ( $r =~ /VERB(ose)?\s+([\w]+)/i ) { | ||
| 1131 | $r = $2; | ||
| 1132 | } | ||
| 1133 | if ( $r =~ /(1|ON)/i ) { | ||
| 1134 | $self->{device_cache}->{VERBOSE} = 1; | ||
| 1135 | } | ||
| 1136 | else { | ||
| 1137 | $self->{device_cache}->{VERBOSE} = 0; | ||
| 1138 | } | ||
| 1139 | } | ||
| 1140 | return $self->{device_cache}->{VERBOSE}; | ||
| 1141 | } | ||
| 1142 | |||
| 1143 | |||
| 1144 | sub set_verbose { | ||
| 1145 | my $self = shift; | ||
| 1146 | my ($in) = $self->_check_args_strict( \@_, 'verbose' ); | ||
| 1147 | my $v; | ||
| 1148 | |||
| 1149 | if ( $in =~ /^\s*(1|on|y|t)/i ) { | ||
| 1150 | $v = 1; | ||
| 1151 | } | ||
| 1152 | elsif ( $in =~ /^\s*(0|off|n|f)/i ) { | ||
| 1153 | $v = 0; | ||
| 1154 | } | ||
| 1155 | else { | ||
| 1156 | Lab::Exception::CorruptParameter->throw( | ||
| 1157 | "Invalid boolean input '$in'\n"); | ||
| 1158 | return; | ||
| 1159 | } | ||
| 1160 | return | ||
| 1161 | if defined( $self->{device_cache}->{VERBOSE} ) | ||
| 1162 | && $self->{device_cache}->{VERBOSE} == $v; | ||
| 1163 | $self->write("VERB $v"); | ||
| 1164 | $self->{device_cache}->{VERBOSE} = $v; | ||
| 1165 | $self->_debug(); | ||
| 1166 | } | ||
| 1167 | |||
| 1168 | |||
| 1169 | sub get_locked { | ||
| 1170 | my $self = shift; | ||
| 1171 | my ($tail) = $self->_check_args( \@_ ); | ||
| 1172 | |||
| 1173 | $tail->{read_mode} = $self->{config}->{default_read_mode} | ||
| 1174 | unless exists( $tail->{read_mode} ) && defined( $tail->{read_mode} ); | ||
| 1175 | |||
| 1176 | if ( $tail->{read_mode} ne 'cache' | ||
| 1177 | || !defined( $self->{device_cache}->{LOCKED} ) ) { | ||
| 1178 | my $r = $self->query('LOC?'); | ||
| 1179 | $self->_debug(); | ||
| 1180 | |||
| 1181 | # can't use the _parseReply here... | ||
| 1182 | if ( $r =~ /LOC(k)?\s+([\w]+)/i ) { | ||
| 1183 | $r = $2; | ||
| 1184 | } | ||
| 1185 | if ( $r =~ /(1|ON|ALL)/i ) { | ||
| 1186 | $self->{device_cache}->{LOCKED} = 1; | ||
| 1187 | $self->{config}->{no_cache} = 0; | ||
| 1188 | } | ||
| 1189 | else { | ||
| 1190 | $self->{device_cache}->{LOCKED} = 0; | ||
| 1191 | $self->{config}->{no_cache} = 1; | ||
| 1192 | } | ||
| 1193 | } | ||
| 1194 | return $self->{device_cache}->{LOCKED}; | ||
| 1195 | } | ||
| 1196 | |||
| 1197 | |||
| 1198 | sub set_locked { | ||
| 1199 | my $self = shift; | ||
| 1200 | my ($in) = $self->_check_args_strict( \@_, 'locked' ); | ||
| 1201 | |||
| 1202 | my $lock; | ||
| 1203 | if ( $in =~ /^\s*(1|y|t|on|all)/i ) { | ||
| 1204 | $lock = 'ALL'; | ||
| 1205 | } | ||
| 1206 | elsif ( $in =~ /^\s*(0|n|f|off|non)/i ) { | ||
| 1207 | $lock = 'NON'; | ||
| 1208 | } | ||
| 1209 | else { | ||
| 1210 | Lab::Exception::CorruptParameter->throw( | ||
| 1211 | "Invalid lock setting '$in'\n"); | ||
| 1212 | return; | ||
| 1213 | } | ||
| 1214 | return | ||
| 1215 | if defined( $self->{device_cache}->{LOCKED} ) | ||
| 1216 | && $self->{device_cache}->{LOCKED} eq $lock; | ||
| 1217 | |||
| 1218 | $self->write("LOC $lock"); | ||
| 1219 | $self->_debug(); | ||
| 1220 | |||
| 1221 | if ( $lock eq 'ALL' ) { # locking clears cache | ||
| 1222 | $self->_ClearCache() if $self->{config}->{no_cache}; | ||
| 1223 | $self->{config}->{no_cache} = 0; | ||
| 1224 | $self->{device_cache}->{LOCKED} = 1; | ||
| 1225 | } | ||
| 1226 | else { | ||
| 1227 | $self->{config}->{no_cache} = 1; | ||
| 1228 | $self->{device_cache}->{LOCKED} = 0; | ||
| 1229 | } | ||
| 1230 | } | ||
| 1231 | |||
| 1232 | # clear cache of all but the "not front panel" (NFP) entries | ||
| 1233 | |||
| 1234 | sub _ClearCache { | ||
| 1235 | my $self = shift; | ||
| 1236 | my (%nfp); | ||
| 1237 | foreach my $k ( @{ $self->{NFP} } ) { | ||
| 1238 | $nfp{$k} = 1; | ||
| 1239 | } | ||
| 1240 | |||
| 1241 | foreach my $ch (qw(CH1 CH2 CH3 CH4 MATH REFA REFB REFC REFD)) { | ||
| 1242 | foreach my $k ( keys( %{ $self->{chan_cache}->{$ch} } ) ) { | ||
| 1243 | next if exists( $nfp{$k} ); | ||
| 1244 | $self->{chan_cache}->{$ch}->{$k} = undef; | ||
| 1245 | } | ||
| 1246 | } | ||
| 1247 | } | ||
| 1248 | |||
| 1249 | |||
| 1250 | # these give the mappings between SCPI codes and cache entries | ||
| 1251 | |||
| 1252 | our $_ccache = { # per-channel caches | ||
| 1253 | 'CH1:BANDWID' => 'chan_bwlimit', | ||
| 1254 | 'CH1:COUP' => 'chan_coupling', | ||
| 1255 | 'CH1:CURRENTPRO' => 'chan_current_probe', | ||
| 1256 | 'CH1:INV' => 'chan_invert', | ||
| 1257 | 'CH1:POS' => 'chan_position', | ||
| 1258 | 'CH1:PRO' => 'chan_probe', | ||
| 1259 | 'CH1:SCA' => 'chan_scale', | ||
| 1260 | 'CH1:YUN' => 'chan_yunit', | ||
| 1261 | }; | ||
| 1262 | |||
| 1263 | our $_lcache = { # shared cache | ||
| 1264 | 'ACQ:MODE' => 'acquire_mode', | ||
| 1265 | 'ACQ:NUMAV' => 'acquire_numavg', | ||
| 1266 | |||
| 1267 | #'ACQ:STAT' => ' ', | ||
| 1268 | 'ACQ:STOPA' => 'acquire_stopafter', | ||
| 1269 | |||
| 1270 | 'AUT:SETT' => 'autorange_settings', | ||
| 1271 | |||
| 1272 | 'CURS:FUNC' => 'cursor_type', | ||
| 1273 | 'CURS:HBA:POSITION1' => 'cursor_y1', | ||
| 1274 | 'CURS:HBA:POSITION2' => 'cursor_y2', | ||
| 1275 | 'CURS:SEL:SOU' => 'cursor_source', | ||
| 1276 | 'CURS:VBA:POSITION1' => 'cursor_x1', | ||
| 1277 | 'CURS:VBA:POSITION2' => 'cursor_x2', | ||
| 1278 | 'CURS:VBA:UNI' => 'cursor_xunits', | ||
| 1279 | |||
| 1280 | 'DAT:DEST' => 'data_destination', | ||
| 1281 | 'DAT:ENC' => 'data_encoding', | ||
| 1282 | 'DAT:SOU' => 'data_source', | ||
| 1283 | 'DAT:STAR' => 'data_start', | ||
| 1284 | 'DAT:STOP' => 'data_stop', | ||
| 1285 | 'DAT:WID' => 'data_width', | ||
| 1286 | |||
| 1287 | 'DIS:CONTR' => 'display_contrast', | ||
| 1288 | 'DIS:FORM' => 'display_format', | ||
| 1289 | |||
| 1290 | #'DIS:INV' => ' ', | ||
| 1291 | 'DIS:PERS' => 'display_persist', | ||
| 1292 | 'DIS:STY' => 'display_style', | ||
| 1293 | |||
| 1294 | #'HARDC:BUTT' => ' ', | ||
| 1295 | 'HARDC:FORM' => 'hardcopy_format', | ||
| 1296 | |||
| 1297 | #'HARDC:INKS' => ' ', | ||
| 1298 | 'HARDC:LAY' => 'hardcopy_layout', | ||
| 1299 | 'HARDC:PORT' => 'hardcopy_port', | ||
| 1300 | 'HOR:DEL:POS' => 'delay_position', | ||
| 1301 | 'HOR:DEL:SCA' => 'delay_scale', | ||
| 1302 | 'HOR:MAI:POS' => 'horiz_position', | ||
| 1303 | 'HOR:MAI:SCA' => 'horiz_scale', | ||
| 1304 | 'HOR:VIEW' => 'horiz_view', | ||
| 1305 | 'MATH:DEFINE' => 'math_definition', | ||
| 1306 | 'MATH:FFT:HOR:POS' => 'fft_xposition', | ||
| 1307 | 'MATH:FFT:HOR:SCA' => 'fft_xscale', | ||
| 1308 | 'MATH:FFT:VER:POS' => 'fft_position', | ||
| 1309 | 'MATH:FFT:VER:SCA' => 'fft_scale', | ||
| 1310 | 'MATH:VER:POS' => 'math_position', | ||
| 1311 | 'MATH:VER:SCA' => 'math_scale', | ||
| 1312 | |||
| 1313 | 'MEASU:IMM:SOU1' => 'meas_source_imm', | ||
| 1314 | 'MEASU:IMM:TYP' => 'meas_type_imm', | ||
| 1315 | 'MEASU:MEAS1:SOU' => 'meas_source_1', | ||
| 1316 | 'MEASU:MEAS1:TYP' => 'meas_type_1', | ||
| 1317 | 'MEASU:MEAS2:SOU' => 'meas_source_2', | ||
| 1318 | 'MEASU:MEAS2:TYP' => 'meas_type_2', | ||
| 1319 | 'MEASU:MEAS3:SOU' => 'meas_source_3', | ||
| 1320 | 'MEASU:MEAS3:TYP' => 'meas_type_3', | ||
| 1321 | 'MEASU:MEAS4:SOU' => 'meas_source_4', | ||
| 1322 | 'MEASU:MEAS4:TYP' => 'meas_type_4', | ||
| 1323 | 'MEASU:MEAS5:SOU' => 'meas_source_5', | ||
| 1324 | 'MEASU:MEAS5:TYP' => 'meas_type_5', | ||
| 1325 | |||
| 1326 | # 'PICT:DAT' => ' ', | ||
| 1327 | # 'PICT:IDPR' => ' ', | ||
| 1328 | # 'PICT:IMAG' => ' ', | ||
| 1329 | # 'PICT:PAP' => ' ', | ||
| 1330 | # 'PICT:PRIN' => ' ', | ||
| 1331 | |||
| 1332 | # 'SAV:IMA:FIL' => ' ', | ||
| 1333 | |||
| 1334 | 'TRIG:MAI:EDGE:COUP' => 'trig_coupling', | ||
| 1335 | 'TRIG:MAI:EDGE:SLO' => 'trig_slope', | ||
| 1336 | 'TRIG:MAI:EDGE:SOU' => 'etrig_source', | ||
| 1337 | 'TRIG:MAI:HOLDO:VAL' => 'trig_holdoff', | ||
| 1338 | 'TRIG:MAI:LEV' => 'trig_level', | ||
| 1339 | 'TRIG:MAI:MOD' => 'trig_mode', | ||
| 1340 | 'TRIG:MAI:PUL:SOU' => 'ptrig_source', | ||
| 1341 | 'TRIG:MAI:PUL:WID:POL' => 'trig_pulse_polarity', | ||
| 1342 | 'TRIG:MAI:PUL:WID:WHEN' => 'trig_pulse_when', | ||
| 1343 | 'TRIG:MAI:PUL:WID:WID' => 'trig_pulse_width', | ||
| 1344 | 'TRIG:MAI:TYP' => 'trig_type', | ||
| 1345 | 'TRIG:MAI:VID:LINE' => 'trig_vid_line', | ||
| 1346 | 'TRIG:MAI:VID:POL' => 'trig_vid_polarity', | ||
| 1347 | 'TRIG:MAI:VID:SOU' => 'vtrig_source', | ||
| 1348 | 'TRIG:MAI:VID:STAN' => 'trig_vid_standard', | ||
| 1349 | 'TRIG:MAI:VID:SYNC' => 'trig_vid_sync', | ||
| 1350 | }; | ||
| 1351 | |||
| 1352 | sub get_setup { | ||
| 1353 | my $self = shift; | ||
| 1354 | |||
| 1355 | if ( $self->query("*STB?") & 0x20 ) { | ||
| 1356 | $self->_debug(); | ||
| 1357 | $self->write('*CLS'); | ||
| 1358 | } | ||
| 1359 | |||
| 1360 | my $v = $self->get_verbose(); | ||
| 1361 | $self->set_verbose(1) if !$v; | ||
| 1362 | my $r = $self->query( "SET?", read_length => -1, timeout => 60 ); | ||
| 1363 | my $post_status = $self->query("*STB?"); | ||
| 1364 | |||
| 1365 | # print Dumper($r),"\n"; | ||
| 1366 | |||
| 1367 | my $h = scpi_flat( scpi_parse($r), $self->{scpi_override} ); | ||
| 1368 | |||
| 1369 | #print Dumper($h),"\n"; | ||
| 1370 | |||
| 1371 | # special cases | ||
| 1372 | |||
| 1373 | if ( exists( $h->{'TRIG:MAI:EDGE:SOU'} ) | ||
| 1374 | && $h->{'TRIG:MAI:EDGE:SOU'} eq 'LINE' ) { | ||
| 1375 | |||
| 1376 | if ( $post_status & 0x20 ) { | ||
| 1377 | my ( $ec, $em ) = $self->get_error(); | ||
| 1378 | if ( ( $ec != 0 && $ec != 300 ) | ||
| 1379 | || ( $ec == 300 && $em !~ /no\s*alternate/i ) ) { | ||
| 1380 | if ($DEBUG) { | ||
| 1381 | my ( $p, $f, $l, $subr ) = caller(0); | ||
| 1382 | print "$subr\t$ec: $em\n"; | ||
| 1383 | } | ||
| 1384 | } | ||
| 1385 | } | ||
| 1386 | } | ||
| 1387 | |||
| 1388 | $self->_debug(); | ||
| 1389 | |||
| 1390 | $self->set_verbose(0) if !$v; | ||
| 1391 | $h->{VERB} = $v; | ||
| 1392 | |||
| 1393 | $self->{device_cache}->{HEADER} = $h->{HEAD} if exists $h->{HEAD}; | ||
| 1394 | $self->{device_cache}->{VERBOSE} = $h->{VERB} if exists $h->{VERB}; | ||
| 1395 | if ( exists( $h->{LOC} ) ) { | ||
| 1396 | $self->{device_cache}->{LOCKED} = ( $h->{LOC} eq 'ALL' ? 1 : 0 ); | ||
| 1397 | } | ||
| 1398 | |||
| 1399 | if ( $self->{device_cache}->{LOCKED} ) { | ||
| 1400 | |||
| 1401 | #per-channel values | ||
| 1402 | |||
| 1403 | foreach my $wfm (qw(CH1 CH2 CH3 CH4 MATH REFA REFB REFC REFD)) { | ||
| 1404 | $self->{chan_cache}->{$wfm}->{select} = $h->{"SEL:$wfm"} | ||
| 1405 | if exists $h->{"SEL:$wfm"}; | ||
| 1406 | |||
| 1407 | next unless $wfm =~ /^CH/i; | ||
| 1408 | |||
| 1409 | foreach my $k ( keys( %{$_ccache} ) ) { | ||
| 1410 | my $ck = $k; | ||
| 1411 | $ck =~ s/^CH1/$wfm/; | ||
| 1412 | next unless exists $h->{$ck}; | ||
| 1413 | $self->{chan_cache}->{$wfm}->{ $_ccache->{$k} } = $h->{$ck}; | ||
| 1414 | } | ||
| 1415 | } | ||
| 1416 | |||
| 1417 | # shared cache values | ||
| 1418 | |||
| 1419 | foreach my $k ( keys( %{$_lcache} ) ) { | ||
| 1420 | next unless exists $h->{$k}; | ||
| 1421 | next if $_lcache->{$k} =~ /^\s*$/; | ||
| 1422 | $self->{device_cache}->{ $_lcache->{$k} } = $h->{$k}; | ||
| 1423 | } | ||
| 1424 | } | ||
| 1425 | return $r; | ||
| 1426 | } | ||
| 1427 | |||
| 1428 | |||
| 1429 | sub set_setup { | ||
| 1430 | my $self = shift; | ||
| 1431 | my ( $setup, $args ) = $self->_check_args_strict( \@_, 'setup' ); | ||
| 1432 | |||
| 1433 | my $cmdlist | ||
| 1434 | = scpi_flat( scpi_parse_sequence($setup), $self->{scpi_override} ); | ||
| 1435 | foreach my $hcmd ( @{$cmdlist} ) { | ||
| 1436 | foreach my $cmd ( keys( %{$hcmd} ) ) { | ||
| 1437 | my $v = $hcmd->{$cmd}; | ||
| 1438 | $cmd .= ' ' . $v if defined($v) && $v ne ''; | ||
| 1439 | $self->write( $cmd, $args ); | ||
| 1440 | $self->_debug(); | ||
| 1441 | } | ||
| 1442 | } | ||
| 1443 | } | ||
| 1444 | |||
| 1445 | |||
| 1446 | sub get_acquire_mode { | ||
| 1447 | my $self = shift; | ||
| 1448 | my $amode = $self->query("ACQ:MODE?"); | ||
| 1449 | $amode = $self->_parseReply( $amode, qw(SAM PEAK AVE) ); | ||
| 1450 | $amode = _bloat( | ||
| 1451 | $amode, | ||
| 1452 | { SAM => 'SAMPLE', PEAK => 'PEAKDETECT', AVE => 'AVERAGE' } | ||
| 1453 | ); | ||
| 1454 | $self->_debug(); | ||
| 1455 | return $amode; | ||
| 1456 | } | ||
| 1457 | |||
| 1458 | |||
| 1459 | sub set_acquire_mode { | ||
| 1460 | my $self = shift; | ||
| 1461 | my ($in) = $self->_check_args_strict( \@_, 'mode' ); | ||
| 1462 | |||
| 1463 | my $m; | ||
| 1464 | if ( $in =~ /^\s*(SAM|NOR)/i ) { | ||
| 1465 | $m = 'SAM'; | ||
| 1466 | } | ||
| 1467 | elsif ( $in =~ /^\s*(PE|PK)/i ) { | ||
| 1468 | $m = 'PEAK'; | ||
| 1469 | } | ||
| 1470 | elsif ( $in =~ /^\s*AV/i ) { | ||
| 1471 | $m = 'AVE'; | ||
| 1472 | } | ||
| 1473 | else { | ||
| 1474 | Lab::Exception::CorruptParameter->throw( | ||
| 1475 | "Invalid aquire mode '$in'\n"); | ||
| 1476 | } | ||
| 1477 | $self->write("ACQ:MODE $m"); | ||
| 1478 | $self->_debug(); | ||
| 1479 | } | ||
| 1480 | |||
| 1481 | |||
| 1482 | sub get_acquire_numacq { | ||
| 1483 | my $self = shift; | ||
| 1484 | my $ans = $self->query("ACQ:NUMAC?"); | ||
| 1485 | $self->_debug(); | ||
| 1486 | return $self->_parseReply($ans); | ||
| 1487 | } | ||
| 1488 | |||
| 1489 | |||
| 1490 | sub get_acquire_numavg { | ||
| 1491 | my $self = shift; | ||
| 1492 | my $ans = $self->query("ACQ:NUMAV?"); | ||
| 1493 | $self->_debug(); | ||
| 1494 | return $self->_parseReply($ans); | ||
| 1495 | } | ||
| 1496 | |||
| 1497 | |||
| 1498 | sub set_acquire_numavg { | ||
| 1499 | my $self = shift; | ||
| 1500 | my ($in) = $self->_check_args_strict( \@_, 'average' ); | ||
| 1501 | |||
| 1502 | # $in =~ s/\D//g; | ||
| 1503 | # $in += 0; | ||
| 1504 | |||
| 1505 | if ( $in == 4 || $in == 16 || $in == 64 || $in == 128 ) { | ||
| 1506 | $self->write("ACQ:NUMAV $in"); | ||
| 1507 | $self->_debug(); | ||
| 1508 | } | ||
| 1509 | else { | ||
| 1510 | Lab::Exception::CorruptParameter->throw( | ||
| 1511 | "Invalid number to average '$in' [4,16,64,128]\n"); | ||
| 1512 | } | ||
| 1513 | } | ||
| 1514 | |||
| 1515 | |||
| 1516 | sub get_acquire_state { | ||
| 1517 | my $self = shift; | ||
| 1518 | my $st = $self->query("ACQ:STATE?"); | ||
| 1519 | $self->_debug(); | ||
| 1520 | |||
| 1521 | $st = $self->_parseReply($st); | ||
| 1522 | return 'RUN' if $st =~ /(1|RUN)/i; | ||
| 1523 | return 'STOP'; | ||
| 1524 | } | ||
| 1525 | |||
| 1526 | |||
| 1527 | # note: do not cache, since "single-shot ACQ" can change value asynchronously | ||
| 1528 | |||
| 1529 | sub set_acquire_state { | ||
| 1530 | my $self = shift; | ||
| 1531 | my ($in) = $self->_check_args_strict( \@_, 'state' ); | ||
| 1532 | my $st; | ||
| 1533 | if ( $in =~ /^\s*(on|run|Y|t|[1-9])/i ) { | ||
| 1534 | $st = 1; | ||
| 1535 | } | ||
| 1536 | elsif ( $in =~ /^\s*(off|stop|n|f|0)/i ) { | ||
| 1537 | $st = 0; | ||
| 1538 | } | ||
| 1539 | else { | ||
| 1540 | Lab::Exception::CorruptParameter->throw("Invalid ACQ state '$in' \n"); | ||
| 1541 | return; | ||
| 1542 | } | ||
| 1543 | $self->write("ACQ:STATE $st"); | ||
| 1544 | $self->_debug(); | ||
| 1545 | } | ||
| 1546 | |||
| 1547 | |||
| 1548 | sub get_acquire_stopafter { | ||
| 1549 | my $self = shift; | ||
| 1550 | my $ans = $self->query("ACQ:STOPA?"); | ||
| 1551 | $ans = $self->_parseReply( $ans, qw(RUNST SEQ) ); | ||
| 1552 | $ans = _bloat( $ans, { RUNST => 'RUNSTOP', SEQ => 'SEQUENCE' } ); | ||
| 1553 | $self->_debug(); | ||
| 1554 | return $ans; | ||
| 1555 | } | ||
| 1556 | |||
| 1557 | |||
| 1558 | sub set_acquire_stopafter { | ||
| 1559 | my $self = shift; | ||
| 1560 | my ($in) = $self->_check_args_strict( \@_, 'mode' ); | ||
| 1561 | |||
| 1562 | my $m; | ||
| 1563 | if ( $in =~ /^\s*RU/i ) { | ||
| 1564 | $m = 'RUNST'; | ||
| 1565 | } | ||
| 1566 | elsif ( $in =~ /^\s*(SE|SQ)/i ) { | ||
| 1567 | $m = 'SEQ'; | ||
| 1568 | } | ||
| 1569 | else { | ||
| 1570 | Lab::Exception::CorruptParameter->throw( | ||
| 1571 | "Invalid stopafter setting '$in' [4,16,64,128]\n"); | ||
| 1572 | } | ||
| 1573 | $self->write("ACQ:STOPA $m"); | ||
| 1574 | $self->_debug(); | ||
| 1575 | } | ||
| 1576 | |||
| 1577 | |||
| 1578 | sub get_acquire { | ||
| 1579 | my $self = shift; | ||
| 1580 | my ($tail) = $self->_check_args( \@_ ); | ||
| 1581 | my $h = {}; | ||
| 1582 | |||
| 1583 | $h->{mode} = $self->get_acquire_mode($tail); | ||
| 1584 | $h->{numacq} = $self->get_acquire_numacq($tail); | ||
| 1585 | $h->{numavg} = $self->get_acquire_numavg($tail); | ||
| 1586 | $h->{state} = $self->get_acquire_state($tail); | ||
| 1587 | $h->{stopafter} = $self->get_acquire_stopafter($tail); | ||
| 1588 | return $h; | ||
| 1589 | } | ||
| 1590 | |||
| 1591 | |||
| 1592 | sub set_acquire { | ||
| 1593 | my $self = shift; | ||
| 1594 | my ($tail) = $self->_check_args( \@_ ); | ||
| 1595 | $self->set_acquire_mode($tail) if exists $tail->{mode}; | ||
| 1596 | $self->set_acquire_stopafter($tail) if exists $tail->{stopafter}; | ||
| 1597 | $self->set_acquire_numavg($tail) if exists $tail->{average}; | ||
| 1598 | $self->set_acquire_state($tail) if exists $tail->{state}; | ||
| 1599 | } | ||
| 1600 | |||
| 1601 | |||
| 1602 | sub get_autorange_state { | ||
| 1603 | my $self = shift; | ||
| 1604 | my $ars = $self->query("AUTOR:STATE?"); | ||
| 1605 | $self->_debug(); | ||
| 1606 | return $self->_parseReply($ars); | ||
| 1607 | } | ||
| 1608 | |||
| 1609 | |||
| 1610 | sub set_autorange_state { | ||
| 1611 | my $self = shift; | ||
| 1612 | my ($in) = $self->_check_args_strict( \@_, 'state' ); | ||
| 1613 | my $b; | ||
| 1614 | if ( $in =~ /^s*([1-9]|t|y|on)/i ) { | ||
| 1615 | $b = 1; | ||
| 1616 | } | ||
| 1617 | elsif ( $in =~ /^s*(0|f|n|off)/i ) { | ||
| 1618 | $b = 0; | ||
| 1619 | } | ||
| 1620 | else { | ||
| 1621 | Lab::Exception::CorruptParameter->throw("Invalid boolean '$in' \n"); | ||
| 1622 | return; | ||
| 1623 | } | ||
| 1624 | |||
| 1625 | $self->write("AUTOR:STATE $b"); | ||
| 1626 | $self->_debug(); | ||
| 1627 | } | ||
| 1628 | |||
| 1629 | |||
| 1630 | sub get_autorange_settings { | ||
| 1631 | my $self = shift; | ||
| 1632 | my $ars = $self->query("AUTOR:SETT?"); | ||
| 1633 | $ars = $self->_parseReply( $ars, qw(HOR VERT BOTH) ); | ||
| 1634 | $ars = _bloat( | ||
| 1635 | $ars, | ||
| 1636 | { HOR => 'HORIZONTAL', VERT => 'VERTICAL', BOTH => 'BOTH' } | ||
| 1637 | ); | ||
| 1638 | |||
| 1639 | $self->_debug(); | ||
| 1640 | return $ars; | ||
| 1641 | } | ||
| 1642 | |||
| 1643 | |||
| 1644 | sub set_autorange_settings { | ||
| 1645 | my $self = shift; | ||
| 1646 | my ($in) = $self->_check_args_strict( \@_, 'set' ); | ||
| 1647 | my $ars; | ||
| 1648 | if ( $in =~ /^\s*(H|X)/i ) { | ||
| 1649 | $ars = 'HOR'; | ||
| 1650 | } | ||
| 1651 | elsif ( $in =~ /^\s*(V|Y)/i ) { | ||
| 1652 | $ars = 'VERT'; | ||
| 1653 | } | ||
| 1654 | elsif ( $in =~ /^\s*B/i ) { | ||
| 1655 | $ars = 'BOTH'; | ||
| 1656 | } | ||
| 1657 | else { | ||
| 1658 | Lab::Exception::CorruptParameter->throw( | ||
| 1659 | "Invalid autorange setting '$in' \n"); | ||
| 1660 | } | ||
| 1661 | $self->write("AUTOR:SETT $ars"); | ||
| 1662 | $self->_debug(); | ||
| 1663 | } | ||
| 1664 | |||
| 1665 | |||
| 1666 | sub do_autorange { | ||
| 1667 | my $self = shift; | ||
| 1668 | $self->write("AUTOS EXEC"); | ||
| 1669 | $self->_debug(); | ||
| 1670 | } | ||
| 1671 | |||
| 1672 | |||
| 1673 | sub get_autorange_signal { | ||
| 1674 | my $self = shift; | ||
| 1675 | my $sig = $self->query("AUTOS:SIGNAL?"); | ||
| 1676 | $sig = $self->_parseReply( | ||
| 1677 | $sig, | ||
| 1678 | qw(LEVEL SINE SQUARE VIDPAL VIDNTSC OTHER NON) | ||
| 1679 | ); | ||
| 1680 | $sig = 'NONE' if $sig eq 'NON'; | ||
| 1681 | $self->_debug(); | ||
| 1682 | return $sig; | ||
| 1683 | } | ||
| 1684 | |||
| 1685 | |||
| 1686 | sub get_autorange_view { | ||
| 1687 | my $self = shift; | ||
| 1688 | my $r = $self->query("AUTOS:VIEW?"); | ||
| 1689 | |||
| 1690 | $r = $self->_parseReply( | ||
| 1691 | $r, | ||
| 1692 | qw(MULTICY SINGLECY FFT RISING FALLING FIELD ODD EVEN LINE LINEN DCLI DEF NONE) | ||
| 1693 | ); | ||
| 1694 | $r = _bloat( | ||
| 1695 | $r, { | ||
| 1696 | MULTICY => 'MULTICYCLE', SINGLECY => 'SINGLECYCLE', | ||
| 1697 | FFT => 'FFT', RISING => 'RISINGEDGE', | ||
| 1698 | FALLING => 'FALLINGEDGE', FIELD => 'FIELD', ODD => 'ODD', | ||
| 1699 | EVEN => 'EVEN', LINE => 'LINE', LINEN => 'LINENUM', | ||
| 1700 | DCLI => 'DCLINE', DEF => 'DEFAULT', NON => 'NONE' | ||
| 1701 | } | ||
| 1702 | ); | ||
| 1703 | $self->_debug(); | ||
| 1704 | return $r; | ||
| 1705 | } | ||
| 1706 | |||
| 1707 | |||
| 1708 | sub set_autorange_view { | ||
| 1709 | my $self = shift; | ||
| 1710 | my ($in) = $self->_check_args_strict( \@_, 'view' ); | ||
| 1711 | my $kw; | ||
| 1712 | $in =~ s/^\s*//; | ||
| 1713 | |||
| 1714 | if ( $in =~ /^MUL/i ) { | ||
| 1715 | $kw = 'MULTICY'; | ||
| 1716 | } | ||
| 1717 | elsif ( $in =~ /^(SING|1)/i ) { | ||
| 1718 | $kw = 'SINGLECY'; | ||
| 1719 | } | ||
| 1720 | elsif ( $in =~ /^FF/i ) { | ||
| 1721 | $kw = 'FFT'; | ||
| 1722 | } | ||
| 1723 | elsif ( $in =~ /^(R|\+)/i ) { | ||
| 1724 | $kw = 'RISING'; | ||
| 1725 | } | ||
| 1726 | elsif ( $in =~ /^(FA|\-)/i ) { | ||
| 1727 | $kw = 'FALLING'; | ||
| 1728 | } | ||
| 1729 | elsif ( $in =~ /^FIE/i ) { | ||
| 1730 | $kw = 'FIELD'; | ||
| 1731 | } | ||
| 1732 | elsif ( $in =~ /^OD/i ) { | ||
| 1733 | $kw = 'ODD'; | ||
| 1734 | } | ||
| 1735 | elsif ( $in =~ /^EV/i ) { | ||
| 1736 | $kw = 'EVEN'; | ||
| 1737 | } | ||
| 1738 | elsif ( $in =~ /^LINEN/i ) { | ||
| 1739 | $kw = 'LINEN'; | ||
| 1740 | } | ||
| 1741 | elsif ( $in =~ /^LI/i ) { | ||
| 1742 | $kw = 'LINE'; | ||
| 1743 | } | ||
| 1744 | elsif ( $in =~ /^DC/i ) { | ||
| 1745 | $kw = 'DCLI'; | ||
| 1746 | } | ||
| 1747 | elsif ( $in =~ /^DE/i ) { | ||
| 1748 | $kw = 'DEF'; | ||
| 1749 | } | ||
| 1750 | elsif ( $in =~ /^(NO|0|OF)/i ) { | ||
| 1751 | $kw = 'NONE'; | ||
| 1752 | } | ||
| 1753 | else { | ||
| 1754 | Lab::Exception::CorruptParameter->throw( | ||
| 1755 | "Invalid autorange view '$in' \n"); | ||
| 1756 | } | ||
| 1757 | |||
| 1758 | $self->write("AUTOS:VIEW $kw"); | ||
| 1759 | |||
| 1760 | my ( $c, $m ) = $self->get_error(); | ||
| 1761 | return if $c == 0; | ||
| 1762 | carp("error in set_autorange_view: $c,'$m'"); | ||
| 1763 | } | ||
| 1764 | |||
| 1765 | |||
| 1766 | sub get_autorange { | ||
| 1767 | my $self = shift; | ||
| 1768 | my ($tail) = $self->_check_args( \@_ ); | ||
| 1769 | |||
| 1770 | my $h = {}; | ||
| 1771 | $h->{state} = $self->get_autorange_state($tail); | ||
| 1772 | $h->{settings} = $self->get_autorange_settings($tail); | ||
| 1773 | $h->{signal} = $self->get_autorange_signal($tail); | ||
| 1774 | $h->{view} = $self->get_autorange_view($tail); | ||
| 1775 | return $h; | ||
| 1776 | } | ||
| 1777 | |||
| 1778 | |||
| 1779 | sub get_channel { | ||
| 1780 | my $self = shift; | ||
| 1781 | return $self->{channel}; | ||
| 1782 | } | ||
| 1783 | |||
| 1784 | |||
| 1785 | sub set_channel { | ||
| 1786 | my $self = shift; | ||
| 1787 | my ($ch) = $self->_check_args_strict( \@_, 'channel' ); | ||
| 1788 | |||
| 1789 | if ( $ch =~ /^\s*MAT/i ) { | ||
| 1790 | $ch = 'MATH'; | ||
| 1791 | } | ||
| 1792 | elsif ( $ch =~ /^\s*(CH[1-4])\s*$/i ) { | ||
| 1793 | $ch = uc($1); | ||
| 1794 | } | ||
| 1795 | elsif ( $ch =~ /^\s*([1-4])\s*$/ ) { | ||
| 1796 | $ch = "CH${1}"; | ||
| 1797 | } | ||
| 1798 | else { | ||
| 1799 | Lab::Exception::CorruptParameter->throw( | ||
| 1800 | "Invalid channel '$ch' should be CH1..4 or MATH \n"); | ||
| 1801 | return; | ||
| 1802 | } | ||
| 1803 | return if $ch eq $self->{channel}; # already set to that channel | ||
| 1804 | |||
| 1805 | # store the shared cache entries | ||
| 1806 | foreach my $k ( keys( %{ $self->{shared_cache} } ) ) { | ||
| 1807 | $self->{shared_cache}->{$k} = $self->{device_cache}->{$k}; | ||
| 1808 | } | ||
| 1809 | |||
| 1810 | # switch to the per-channel cache of selected channel | ||
| 1811 | $self->{device_cache} = $self->{chan_cache}->{$ch}; | ||
| 1812 | |||
| 1813 | # update from shared cache | ||
| 1814 | foreach my $k ( keys( %{ $self->{shared_cache} } ) ) { | ||
| 1815 | $self->{device_cache}->{$k} = $self->{shared_cache}->{$k}; | ||
| 1816 | } | ||
| 1817 | |||
| 1818 | $self->{channel} = $ch; | ||
| 1819 | } | ||
| 1820 | |||
| 1821 | |||
| 1822 | sub get_vertical_settings { | ||
| 1823 | my $self = shift; | ||
| 1824 | my ($ch) = $self->_check_args_strict( \@_ ,'channel'); | ||
| 1825 | |||
| 1826 | if ( $ch =~ /^\s*(CH[1-4])\s*$/i ) { | ||
| 1827 | $ch = uc($1); | ||
| 1828 | } | ||
| 1829 | elsif ( $ch =~ /^\s*([1-4])\s*$/ ) { | ||
| 1830 | $ch = "CH${1}"; | ||
| 1831 | } | ||
| 1832 | elsif ( $ch =~ /^\s*MA/i) { | ||
| 1833 | $ch = 'MATH'; | ||
| 1834 | } | ||
| 1835 | else { | ||
| 1836 | Lab::Exception::CorruptParameter->throw( | ||
| 1837 | "Invalid channel '$ch' should be CH1..4 or MATH \n"); | ||
| 1838 | return; | ||
| 1839 | } | ||
| 1840 | |||
| 1841 | |||
| 1842 | my $v = $self->get_verbose(); | ||
| 1843 | $self->set_verbose(1) if !$v; | ||
| 1844 | my $hd = $self->get_header(); | ||
| 1845 | $self->set_header(1) if !$hd; | ||
| 1846 | |||
| 1847 | my $reply = $self->query("${ch}?"); | ||
| 1848 | $self->set_verbose(0) if !$v; | ||
| 1849 | $self->set_header(0) if !$hd; | ||
| 1850 | return scpi_flat(scpi_parse($reply)); | ||
| 1851 | } | ||
| 1852 | |||
| 1853 | |||
| 1854 | |||
| 1855 | |||
| 1856 | sub set_visible { | ||
| 1857 | my $self = shift; | ||
| 1858 | my ( $ch, $ivis ) = $self->_check_args( \@_, qw(channel visible) ); | ||
| 1859 | |||
| 1860 | $ch = $self->{channel} unless defined $ch; | ||
| 1861 | $ivis = 1 unless defined $ivis; | ||
| 1862 | |||
| 1863 | if ( $ch =~ /^\s*(ch[1-4])\s*$/i ) { | ||
| 1864 | $ch = uc($1); | ||
| 1865 | } | ||
| 1866 | elsif ( $ch =~ /^\s*math\s*$/i ) { | ||
| 1867 | $ch = 'MATH'; | ||
| 1868 | } | ||
| 1869 | elsif ( $ch =~ /^\s*(ref[a-d])\s*$/i ) { | ||
| 1870 | $ch = uc($1); | ||
| 1871 | } | ||
| 1872 | elsif ( $ch =~ /^\s*([1-4])\s*$/ ) { | ||
| 1873 | $ch = "CH$1"; | ||
| 1874 | } | ||
| 1875 | elsif ( $ch =~ /^\s*([a-d])\s*$/i ) { | ||
| 1876 | $ch = "REF$1"; | ||
| 1877 | } | ||
| 1878 | else { | ||
| 1879 | Lab::Exception::CorruptParameter->throw( | ||
| 1880 | "Invalid channel input '$ch'\n"); | ||
| 1881 | return; | ||
| 1882 | } | ||
| 1883 | |||
| 1884 | my $vis; | ||
| 1885 | if ( $ivis =~ /\s*(T|Y|ON|[1-9])/i ) { | ||
| 1886 | $vis = 1; | ||
| 1887 | } | ||
| 1888 | elsif ( $ivis =~ /\s*(F|N|OF|0)/i ) { | ||
| 1889 | $vis = 0; | ||
| 1890 | } | ||
| 1891 | else { | ||
| 1892 | Lab::Exception::CorruptParameter->throw( | ||
| 1893 | "Invalid boolean input '$ivis'\n"); | ||
| 1894 | return; | ||
| 1895 | } | ||
| 1896 | |||
| 1897 | my $cache; | ||
| 1898 | if ( $self->{device_cache}->{LOCKED} ) { | ||
| 1899 | if ( $ch eq $self->{channel} ) { | ||
| 1900 | $cache = $self->{device_channel}; | ||
| 1901 | } | ||
| 1902 | else { | ||
| 1903 | $cache = $self->{chan_cache}->{$ch}; | ||
| 1904 | } | ||
| 1905 | return if defined( $cache->{select} ) && $vis == $cache->{select}; | ||
| 1906 | } | ||
| 1907 | |||
| 1908 | $self->write("SEL:$ch $vis"); | ||
| 1909 | $self->_debug(); | ||
| 1910 | $cache->{select} = $vis if defined $cache; | ||
| 1911 | } | ||
| 1912 | |||
| 1913 | |||
| 1914 | sub get_visible { | ||
| 1915 | my $self = shift; | ||
| 1916 | my ( $ch, $tail ) = $self->_check_args( \@_, qw(channel) ); | ||
| 1917 | |||
| 1918 | $tail->{read_mode} = $self->{config}->{default_read_mode} | ||
| 1919 | unless exists( $tail->{read_mode} ) && defined( $tail->{read_mode} ); | ||
| 1920 | |||
| 1921 | $ch = $self->{channel} unless defined $ch; | ||
| 1922 | |||
| 1923 | if ( $ch =~ /^\s*(ch[1-4])\s*$/i ) { | ||
| 1924 | $ch = uc($1); | ||
| 1925 | } | ||
| 1926 | elsif ( $ch =~ /^\s*math\s*$/i ) { | ||
| 1927 | $ch = 'MATH'; | ||
| 1928 | } | ||
| 1929 | elsif ( $ch =~ /^\s*(ref[a-d])\s*$/i ) { | ||
| 1930 | $ch = uc($1); | ||
| 1931 | } | ||
| 1932 | elsif ( $ch =~ /^\s*([1-4])\s*$/ ) { | ||
| 1933 | $ch = "CH$1"; | ||
| 1934 | } | ||
| 1935 | elsif ( $ch =~ /^\s*([a-d])\s*$/i ) { | ||
| 1936 | $ch = "REF$1"; | ||
| 1937 | } | ||
| 1938 | else { | ||
| 1939 | Lab::Exception::CorruptParameter->throw( | ||
| 1940 | "Invalid channel input '$ch'\n"); | ||
| 1941 | return; | ||
| 1942 | } | ||
| 1943 | |||
| 1944 | my $cache; | ||
| 1945 | if ( $self->{device_cache}->{LOCKED} ) { | ||
| 1946 | my $v; | ||
| 1947 | if ( $ch eq $self->{channel} ) { | ||
| 1948 | $cache = $self->{device_cache}; | ||
| 1949 | } | ||
| 1950 | else { | ||
| 1951 | $cache = $self->{chan_cache}->{$ch}; | ||
| 1952 | } | ||
| 1953 | $v = $cache->{select} | ||
| 1954 | if defined( $cache->{select} ); | ||
| 1955 | return $v if defined($v) && $tail->{read_mode} eq 'cache'; | ||
| 1956 | } | ||
| 1957 | my $r = $self->query("SEL:$ch?"); | ||
| 1958 | $self->_debug(); | ||
| 1959 | $r = $self->_parseReply($r); | ||
| 1960 | |||
| 1961 | $cache->{select} = $r if defined $cache; | ||
| 1962 | return $r; | ||
| 1963 | } | ||
| 1964 | |||
| 1965 | |||
| 1966 | sub get_chan_bwlimit { | ||
| 1967 | my $self = shift; | ||
| 1968 | my $ch = $self->{channel}; | ||
| 1969 | |||
| 1970 | return 0 if $ch eq 'MATH'; | ||
| 1971 | |||
| 1972 | my $r = $self->query("${ch}:BANDWID?"); | ||
| 1973 | $self->_debug(); | ||
| 1974 | return $self->_parseReply($r); | ||
| 1975 | } | ||
| 1976 | |||
| 1977 | |||
| 1978 | sub set_chan_bwlimit { | ||
| 1979 | my $self = shift; | ||
| 1980 | my ($in) = $self->_check_args_strict( \@_, 'limit' ); | ||
| 1981 | my $ch = $self->{channel}; | ||
| 1982 | return if $ch eq 'MATH'; | ||
| 1983 | |||
| 1984 | my $b; | ||
| 1985 | if ( $in =~ /^\s*([1-9]|y|t|on)/i ) { | ||
| 1986 | $b = 'ON'; | ||
| 1987 | } | ||
| 1988 | elsif ( $in =~ /^\s*(0|n|f|off)/i ) { | ||
| 1989 | $b = 'OFF'; | ||
| 1990 | } | ||
| 1991 | else { | ||
| 1992 | Lab::Exception::CorruptParameter->throw( | ||
| 1993 | "Invalid limit boolean, should be ON|OFF \n"); | ||
| 1994 | return; | ||
| 1995 | } | ||
| 1996 | $self->write("${ch}:BANDWID $b"); | ||
| 1997 | $self->_debug(); | ||
| 1998 | } | ||
| 1999 | |||
| 2000 | |||
| 2001 | sub get_chan_coupling { | ||
| 2002 | my $self = shift; | ||
| 2003 | my $ch = $self->{channel}; | ||
| 2004 | |||
| 2005 | return 'GND' if $ch eq 'MATH'; | ||
| 2006 | my $r = $self->query("${ch}:COUP?"); | ||
| 2007 | $self->_debug(); | ||
| 2008 | return $self->_parseReply($r); | ||
| 2009 | } | ||
| 2010 | |||
| 2011 | |||
| 2012 | sub set_chan_coupling { | ||
| 2013 | my $self = shift; | ||
| 2014 | my ($in) = $self->_check_args_strict( \@_, 'coupling' ); | ||
| 2015 | my $ch = $self->{channel}; | ||
| 2016 | |||
| 2017 | return if $ch eq 'MATH'; | ||
| 2018 | $in = _keyword( $in, qw(AC DC GND) ); | ||
| 2019 | $self->write("${ch}:COUP $in"); | ||
| 2020 | $self->_debug(); | ||
| 2021 | } | ||
| 2022 | |||
| 2023 | |||
| 2024 | sub get_chan_current_probe { | ||
| 2025 | my $self = shift; | ||
| 2026 | my $ch = $self->{channel}; | ||
| 2027 | |||
| 2028 | return 1 if $ch eq 'MATH'; | ||
| 2029 | my $r = $self->query("${ch}:CURRENTPRO?"); | ||
| 2030 | $self->_debug(); | ||
| 2031 | return $self->_parseReply($r); | ||
| 2032 | } | ||
| 2033 | |||
| 2034 | |||
| 2035 | sub set_chan_current_probe { | ||
| 2036 | my $self = shift; | ||
| 2037 | my ($in) = $self->_check_args_strict( \@_, 'factor' ); | ||
| 2038 | my $ch = $self->{channel}; | ||
| 2039 | |||
| 2040 | return if $ch eq 'MATH'; | ||
| 2041 | my $fact = _parseNRf( $in, 'X' ); # '10x', for example | ||
| 2042 | |||
| 2043 | if ( $fact =~ /^ERR/i || $fact eq 'MIN' || $fact eq 'MAX' ) { | ||
| 2044 | Lab::Exception::CorruptParameter->throw( | ||
| 2045 | "Error parsing probe factor '$in' \n"); | ||
| 2046 | return; | ||
| 2047 | } | ||
| 2048 | $fact = int( $fact * 10 + 0.5 ) * 0.1; | ||
| 2049 | if ( $fact != 0.2 | ||
| 2050 | && $fact != 1 | ||
| 2051 | && $fact != 2 | ||
| 2052 | && $fact != 5 | ||
| 2053 | && $fact != 10 | ||
| 2054 | && $fact != 50 | ||
| 2055 | && $fact != 100 | ||
| 2056 | && $fact != 1000 ) { | ||
| 2057 | Lab::Exception::CorruptParameter->throw("Invalid factor '$fact' \n"); | ||
| 2058 | return; | ||
| 2059 | } | ||
| 2060 | $self->write("${ch}:CURRENTPRO $fact"); | ||
| 2061 | $self->_debug(); | ||
| 2062 | } | ||
| 2063 | |||
| 2064 | |||
| 2065 | sub get_chan_invert { | ||
| 2066 | my $self = shift; | ||
| 2067 | my $ch = $self->{channel}; | ||
| 2068 | |||
| 2069 | return 0 if $ch eq 'MATH'; | ||
| 2070 | |||
| 2071 | my $r = $self->query("${ch}:INV?"); | ||
| 2072 | $r = $self->_parseReply($r); | ||
| 2073 | $r = 1 if $r eq 'ON'; | ||
| 2074 | $r = 0 if $r eq 'OFF'; | ||
| 2075 | $self->_debug(); | ||
| 2076 | return $r; | ||
| 2077 | } | ||
| 2078 | |||
| 2079 | |||
| 2080 | sub set_chan_invert { | ||
| 2081 | my $self = shift; | ||
| 2082 | my ($in) = $self->_check_args_strict( \@_, 'invert' ); | ||
| 2083 | my $ch = $self->{channel}; | ||
| 2084 | return if $ch eq 'MATH'; | ||
| 2085 | |||
| 2086 | if ( $in =~ /^\s*(on|[1-9]|t|y)/i ) { | ||
| 2087 | $in = 'ON'; | ||
| 2088 | } | ||
| 2089 | elsif ( $in =~ /^\s*(off|0|f|n)/i ) { | ||
| 2090 | $in = 'OFF'; | ||
| 2091 | } | ||
| 2092 | else { | ||
| 2093 | Lab::Exception::CorruptParameter->throw( | ||
| 2094 | "Error parsing boolean '$in' \n"); | ||
| 2095 | return; | ||
| 2096 | } | ||
| 2097 | |||
| 2098 | $self->write("${ch}:INV $in"); | ||
| 2099 | $self->_debug(); | ||
| 2100 | } | ||
| 2101 | |||
| 2102 | |||
| 2103 | sub get_chan_position { | ||
| 2104 | my $self = shift; | ||
| 2105 | my $ch = $self->{channel}; | ||
| 2106 | |||
| 2107 | $ch = 'MATH:VER' if $ch eq 'MATH'; | ||
| 2108 | my $r = $self->query("${ch}:POS?"); | ||
| 2109 | $self->_debug(); | ||
| 2110 | return $self->_parseReply($r); | ||
| 2111 | } | ||
| 2112 | |||
| 2113 | |||
| 2114 | sub set_chan_position { | ||
| 2115 | my $self = shift; | ||
| 2116 | my ($in) = $self->_check_args_strict( \@_, 'position' ); | ||
| 2117 | my $ch = $self->{channel}; | ||
| 2118 | |||
| 2119 | my $p = _parseNRf( $in, 'div' ); | ||
| 2120 | |||
| 2121 | if ( $p =~ /ERR/ || $p eq 'MIN' || $p eq 'MAX' ) { | ||
| 2122 | Lab::Exception::CorruptParameter->throw( | ||
| 2123 | "Error parsing number '$in' \n"); | ||
| 2124 | return; | ||
| 2125 | } | ||
| 2126 | |||
| 2127 | $p = sprintf( '%.2e', $p ); | ||
| 2128 | my $scale = $self->get_chan_scale(); | ||
| 2129 | my $maxv = 2; | ||
| 2130 | $maxv = 50 if $scale >= 0.5; | ||
| 2131 | |||
| 2132 | if ( abs( $p * $scale ) > $maxv ) { | ||
| 2133 | Lab::Exception::CorruptParameter->throw( | ||
| 2134 | "Channel position '$p' out of range\n"); | ||
| 2135 | return; | ||
| 2136 | } | ||
| 2137 | |||
| 2138 | $ch = 'MATH:VER' if $ch eq 'MATH'; | ||
| 2139 | $self->write("${ch}:POS $p"); | ||
| 2140 | $self->_debug(); | ||
| 2141 | } | ||
| 2142 | |||
| 2143 | |||
| 2144 | sub get_chan_probe { | ||
| 2145 | my $self = shift; | ||
| 2146 | my $ch = $self->{channel}; | ||
| 2147 | |||
| 2148 | return 1 if $ch eq 'MATH'; | ||
| 2149 | my $r = $self->query("${ch}:PRO?"); | ||
| 2150 | $self->_debug(); | ||
| 2151 | return $self->_parseReply($r); | ||
| 2152 | } | ||
| 2153 | |||
| 2154 | |||
| 2155 | sub set_chan_probe { | ||
| 2156 | my $self = shift; | ||
| 2157 | my ($in) = $self->_check_args_strict( \@_, 'factor' ); | ||
| 2158 | my $ch = $self->{channel}; | ||
| 2159 | |||
| 2160 | return if $ch eq 'MATH'; | ||
| 2161 | my $fact = _parseNRf( $in, 'x' ); | ||
| 2162 | |||
| 2163 | if ( $fact =~ /ERR/ || $fact eq 'MIN' || $fact eq 'MAX' ) { | ||
| 2164 | Lab::Exception::CorruptParameter->throw( | ||
| 2165 | "Error parsing probe attenuation '$in' \n"); | ||
| 2166 | return; | ||
| 2167 | } | ||
| 2168 | |||
| 2169 | $fact = int( $fact + 0.2 ); | ||
| 2170 | if ( $fact != 1 | ||
| 2171 | && $fact != 10 | ||
| 2172 | && $fact != 20 | ||
| 2173 | && $fact != 50 | ||
| 2174 | && $fact != 100 | ||
| 2175 | && $fact != 500 | ||
| 2176 | && $fact != 1000 ) { | ||
| 2177 | Lab::Exception::CorruptParameter->throw("Invalid factor '$fact' \n"); | ||
| 2178 | return; | ||
| 2179 | } | ||
| 2180 | $self->write("${ch}:PRO $fact"); | ||
| 2181 | $self->_debug(); | ||
| 2182 | } | ||
| 2183 | |||
| 2184 | |||
| 2185 | sub get_chan_scale { | ||
| 2186 | my $self = shift; | ||
| 2187 | my $ch = $self->{channel}; | ||
| 2188 | |||
| 2189 | $ch = 'MATH:VER' if $ch eq 'MATH'; | ||
| 2190 | my $r = $self->query("${ch}:SCA?"); | ||
| 2191 | $self->_debug(); | ||
| 2192 | return $self->_parseReply($r); | ||
| 2193 | } | ||
| 2194 | |||
| 2195 | |||
| 2196 | sub set_chan_scale { | ||
| 2197 | my $self = shift; | ||
| 2198 | my ($in) = $self->_check_args_strict( \@_, 'scale' ); | ||
| 2199 | my $ch = $self->{channel}; | ||
| 2200 | |||
| 2201 | my $gain = _parseNRf( $in, 'v/div', 'a/div', 'v', 'a' ); | ||
| 2202 | |||
| 2203 | if ( $gain =~ /ERR/ || $gain eq 'MIN' || $gain eq 'MAX' ) { | ||
| 2204 | Lab::Exception::CorruptParameter->throw( | ||
| 2205 | "Error parsing probe attenuation '$in' \n"); | ||
| 2206 | return; | ||
| 2207 | } | ||
| 2208 | |||
| 2209 | if ( $ch ne 'MATH' ) { | ||
| 2210 | my $vmin = 2e-3; | ||
| 2211 | my $vmax = 5; | ||
| 2212 | my $probe; | ||
| 2213 | my $y = $self->get_chan_yunit(); | ||
| 2214 | if ( $y eq 'V' ) { | ||
| 2215 | $probe = $self->get_chan_probe(); | ||
| 2216 | } | ||
| 2217 | else { | ||
| 2218 | $probe = $self->get_chan_currentprobe(); | ||
| 2219 | } | ||
| 2220 | $vmin *= $probe; | ||
| 2221 | $vmax *= $probe; | ||
| 2222 | $gain = sprintf( '%.3e', $gain ); | ||
| 2223 | |||
| 2224 | if ( $gain > $vmax || $gain < $vmin ) { | ||
| 2225 | Lab::Exception::CorruptParameter->throw( | ||
| 2226 | "Vertical scale '$in' out of range\n"); | ||
| 2227 | return; | ||
| 2228 | } | ||
| 2229 | } | ||
| 2230 | else { | ||
| 2231 | if ( $gain <= 0 ) { | ||
| 2232 | Lab::Exception::CorruptParameter->throw( | ||
| 2233 | "Vertical scale '$in' out of range\n"); | ||
| 2234 | return; | ||
| 2235 | } | ||
| 2236 | } | ||
| 2237 | |||
| 2238 | $ch = 'MATH:VER' if $ch eq 'MATH'; | ||
| 2239 | $self->write("${ch}:SCA $gain"); | ||
| 2240 | $self->_debug(); | ||
| 2241 | } | ||
| 2242 | |||
| 2243 | |||
| 2244 | sub get_chan_yunit { | ||
| 2245 | my $self = shift; | ||
| 2246 | my $ch = $self->{channel}; | ||
| 2247 | return 'V' if $ch eq 'MATH'; | ||
| 2248 | |||
| 2249 | my $r = $self->query("${ch}:YUN?"); | ||
| 2250 | $self->_debug(); | ||
| 2251 | return $self->_parseReply($r); | ||
| 2252 | } | ||
| 2253 | |||
| 2254 | |||
| 2255 | sub set_chan_yunit { | ||
| 2256 | my $self = shift; | ||
| 2257 | my ($in) = $self->_check_args_strict( \@_, 'unit' ); | ||
| 2258 | my $ch = $self->{channel}; | ||
| 2259 | |||
| 2260 | return if $ch eq 'MATH'; | ||
| 2261 | my $y; | ||
| 2262 | if ( $in =~ /^\s*V/i ) { | ||
| 2263 | $y = 'V'; | ||
| 2264 | } | ||
| 2265 | elsif ( $in =~ /^\s*A/i ) { | ||
| 2266 | $y = 'A'; | ||
| 2267 | } | ||
| 2268 | else { | ||
| 2269 | Lab::Exception::CorruptParameter->throw("Invalid yunit '$in' \n"); | ||
| 2270 | return; | ||
| 2271 | } | ||
| 2272 | |||
| 2273 | $self->write("${ch}:YUN $y"); | ||
| 2274 | $self->_debug(); | ||
| 2275 | } | ||
| 2276 | |||
| 2277 | |||
| 2278 | sub get_chan_setup { | ||
| 2279 | my $self = shift; | ||
| 2280 | |||
| 2281 | my ($tail) = $self->_check_args( \@_ ); | ||
| 2282 | |||
| 2283 | $self->set_channel($tail) if exists( $tail->{channel} ); | ||
| 2284 | |||
| 2285 | my $ch = $self->{channel}; | ||
| 2286 | my $h = {}; | ||
| 2287 | $h->{channel} = $ch; | ||
| 2288 | $h->{scale} = $self->get_scale($tail); | ||
| 2289 | $h->{position} = $self->get_position($tail); | ||
| 2290 | $h->{invert} = $self->get_invert($tail); | ||
| 2291 | $h->{coupling} = $self->get_coupling($tail); | ||
| 2292 | $h->{bandwidth} = $self->get_bandwidth($tail); | ||
| 2293 | $h->{yunit} = $self->get_yunit($tail); | ||
| 2294 | $h->{probe} = $self->get_probe($tail); | ||
| 2295 | $h->{currentprobe} = $self->get_current_probe($tail); | ||
| 2296 | $h->{definition} = $self->get_math_definition($tail) if $ch eq 'MATH'; | ||
| 2297 | |||
| 2298 | return $h; | ||
| 2299 | } | ||
| 2300 | |||
| 2301 | |||
| 2302 | sub set_chan_setup { | ||
| 2303 | my $self = shift; | ||
| 2304 | |||
| 2305 | my ($tail) = $self->_check_args( \@_ ); | ||
| 2306 | |||
| 2307 | $self->set_channel($tail) if exits( $tail->{channel} ); | ||
| 2308 | |||
| 2309 | $self->set_chan_coupling($tail) | ||
| 2310 | if exists( $tail->{coupling} ); | ||
| 2311 | $self->set_chan_invert($tail) | ||
| 2312 | if exists( $tail->{invert} ); | ||
| 2313 | $self->set_chan_yunit($tail) | ||
| 2314 | if exists( $tail->{yunit} ); | ||
| 2315 | $self->set_chan_probe($tail) | ||
| 2316 | if exists( $tail->{probe} ); | ||
| 2317 | $self->set_chan_currentprobe($tail) | ||
| 2318 | if exists( $tail->{currentprobe} ); | ||
| 2319 | $self->set_chan_scale($tail) | ||
| 2320 | if exists( $tail->{scale} ); | ||
| 2321 | $self->set_chan_position($tail) | ||
| 2322 | if exists( $tail->{position} ); | ||
| 2323 | $self->set_math_definition($tail) | ||
| 2324 | if exists( $tail->{math_definition} ); | ||
| 2325 | |||
| 2326 | } | ||
| 2327 | |||
| 2328 | |||
| 2329 | sub get_cursor_type { | ||
| 2330 | my $self = shift; | ||
| 2331 | my ($opt) = $self->_check_args( \@_, ['option'] ); | ||
| 2332 | $opt = '' unless defined($opt); | ||
| 2333 | $opt = 'XY' if $opt =~ /\s*x/i; | ||
| 2334 | |||
| 2335 | my $r = $self->query("CURS:FUNC?"); | ||
| 2336 | $r = $self->_parseReply( $r, qw(OFF HBA VBA) ); | ||
| 2337 | |||
| 2338 | if ( $opt eq 'XY' ) { | ||
| 2339 | $r = _bloat( $r, { OFF => 'OFF', HBA => 'Y', VBA => 'X' } ); | ||
| 2340 | } | ||
| 2341 | else { | ||
| 2342 | $r = _bloat( $r, { OFF => 'OFF', HBA => 'HBARS', VBA => 'VBARS' } ); | ||
| 2343 | } | ||
| 2344 | $self->_debug(); | ||
| 2345 | return $r; | ||
| 2346 | } | ||
| 2347 | |||
| 2348 | |||
| 2349 | sub set_cursor_type { | ||
| 2350 | my $self = shift; | ||
| 2351 | my ($in) = $self->_check_args_strict( \@_, 'type' ); | ||
| 2352 | |||
| 2353 | my $dform = $self->get_display_format(); | ||
| 2354 | |||
| 2355 | my $c; | ||
| 2356 | if ( $in =~ /^\s*(OFF|N|F|0)/i ) { | ||
| 2357 | $c = 'OFF'; | ||
| 2358 | } | ||
| 2359 | elsif ( $in =~ /^\s*(H|y)/i ) { | ||
| 2360 | $c = 'HBA'; | ||
| 2361 | } | ||
| 2362 | elsif ( $in =~ /^\s*(V|x)/i ) { | ||
| 2363 | $c = 'VBA'; | ||
| 2364 | } | ||
| 2365 | else { | ||
| 2366 | Lab::Exception::CorruptParameter->throw( | ||
| 2367 | "Invalid cursor selection '$in' \n"); | ||
| 2368 | return; | ||
| 2369 | } | ||
| 2370 | if ( $dform eq 'XY' && $c ne 'OFF' ) { | ||
| 2371 | Lab::Exception::CorruptParameter->throw( | ||
| 2372 | "Invalid cursor selection '$in' for XY display\n"); | ||
| 2373 | return; | ||
| 2374 | } | ||
| 2375 | |||
| 2376 | $self->write("CURS:FUNC $c"); | ||
| 2377 | $self->_debug(); | ||
| 2378 | } | ||
| 2379 | |||
| 2380 | |||
| 2381 | sub get_cursor_xunits { | ||
| 2382 | my $self = shift; | ||
| 2383 | |||
| 2384 | # trigger view error | ||
| 2385 | |||
| 2386 | my $r = ''; | ||
| 2387 | $r = $self->query("CURS:VBA:UNI?"); | ||
| 2388 | $r = $self->_parseReply( $r, qw(SECO HER) ); | ||
| 2389 | $r = _bloat( $r, { SECO => 'SECONDS', HER => 'HERTZ' } ); | ||
| 2390 | |||
| 2391 | $self->_debug(); | ||
| 2392 | return $r; | ||
| 2393 | } | ||
| 2394 | |||
| 2395 | |||
| 2396 | sub get_cursor_yunits { | ||
| 2397 | my $self = shift; | ||
| 2398 | |||
| 2399 | # trigger view error | ||
| 2400 | |||
| 2401 | my $r = ''; | ||
| 2402 | $r = $self->query("CURS:HBA:UNI?"); | ||
| 2403 | $r = $self->_parseReply( | ||
| 2404 | $r, qw(VOL DIV DECIBELS UNKNOWN AMPS | ||
| 2405 | VOLTSSQUARED AMPSSQUARED VOLTSAMPS) | ||
| 2406 | ); | ||
| 2407 | $r = _bloat( $r, { VOL => 'VOLTS', DIV => 'DIVISIONS' } ); | ||
| 2408 | $self->_debug(); | ||
| 2409 | return $r; | ||
| 2410 | } | ||
| 2411 | |||
| 2412 | |||
| 2413 | sub get_cursor_source { | ||
| 2414 | my $self = shift; | ||
| 2415 | my $r = $self->query("CURS:SEL:SOU?"); | ||
| 2416 | $self->_debug(); | ||
| 2417 | return $self->_parseReply($r); | ||
| 2418 | } | ||
| 2419 | |||
| 2420 | |||
| 2421 | sub set_cursor_source { | ||
| 2422 | my $self = shift; | ||
| 2423 | my ($ich) = $self->_check_args_strict( \@_, ['channel'] ); | ||
| 2424 | |||
| 2425 | my $ch = $ich; | ||
| 2426 | $ch =~ s/^\s+//; | ||
| 2427 | if ( $ich =~ /^([\d\.]+)/i ) { | ||
| 2428 | $ch = "CH$1"; | ||
| 2429 | } | ||
| 2430 | |||
| 2431 | if ( $ch !~ /^CH[1-4]$/i | ||
| 2432 | && $ch !~ /^MATH$/i | ||
| 2433 | && $ch !~ /^REF[a-d]$/i ) { | ||
| 2434 | Lab::Exception::CorruptParameter->throw("Invalid channel '$ch'\n"); | ||
| 2435 | return; | ||
| 2436 | } | ||
| 2437 | $ch = uc($ch); | ||
| 2438 | |||
| 2439 | $self->write("CURS:SEL:SOU $ch"); | ||
| 2440 | $self->_debug(); | ||
| 2441 | } | ||
| 2442 | |||
| 2443 | |||
| 2444 | sub set_cursor_xunits { | ||
| 2445 | my $self = shift; | ||
| 2446 | my ($in) = $self->_check_args_strict( \@_, 'unit' ); | ||
| 2447 | |||
| 2448 | my $u; | ||
| 2449 | if ( $in =~ /^\s*s/i ) { | ||
| 2450 | $u = 'SECO'; | ||
| 2451 | } | ||
| 2452 | elsif ( $in =~ /^\s*her/i || $in =~ /^\s*Hz/i ) { | ||
| 2453 | $u = 'HER'; | ||
| 2454 | } | ||
| 2455 | else { | ||
| 2456 | Lab::Exception::CorruptParameter->throw( | ||
| 2457 | "Invalid cursor unit selection '$in' \n"); | ||
| 2458 | return; | ||
| 2459 | } | ||
| 2460 | $self->write("CURS:VBA:UNI $u"); | ||
| 2461 | $self->_debug(); | ||
| 2462 | } | ||
| 2463 | |||
| 2464 | |||
| 2465 | sub get_cursor_dx { | ||
| 2466 | my $self = shift; | ||
| 2467 | |||
| 2468 | # trigger view error | ||
| 2469 | |||
| 2470 | my $r = $self->query("CURS:VBA:DELT?"); | ||
| 2471 | $self->_debug(); | ||
| 2472 | return $self->_parseReply($r); | ||
| 2473 | } | ||
| 2474 | |||
| 2475 | |||
| 2476 | sub get_cursor_dy { | ||
| 2477 | my $self = shift; | ||
| 2478 | |||
| 2479 | # trigger view error | ||
| 2480 | |||
| 2481 | my $r = $self->query("CURS:HBA:DELT?"); | ||
| 2482 | $self->_debug(); | ||
| 2483 | return $self->_parseReply($r); | ||
| 2484 | } | ||
| 2485 | |||
| 2486 | |||
| 2487 | sub get_cursor_x1 { | ||
| 2488 | my $self = shift; | ||
| 2489 | |||
| 2490 | my $r = $self->query("CURS:VBA:POSITION1?"); | ||
| 2491 | $self->_debug(); | ||
| 2492 | return $self->_parseReply($r); | ||
| 2493 | } | ||
| 2494 | |||
| 2495 | |||
| 2496 | sub get_cursor_x2 { | ||
| 2497 | my $self = shift; | ||
| 2498 | |||
| 2499 | my $r = $self->query("CURS:VBA:POSITION2?"); | ||
| 2500 | $self->_debug(); | ||
| 2501 | return $self->_parseReply($r); | ||
| 2502 | } | ||
| 2503 | |||
| 2504 | |||
| 2505 | sub get_cursor_y1 { | ||
| 2506 | my $self = shift; | ||
| 2507 | |||
| 2508 | # error if trigger view active | ||
| 2509 | my $r = $self->query("CURS:HBA:POSITION1?"); | ||
| 2510 | $self->_debug(); | ||
| 2511 | return $self->_parseReply($r); | ||
| 2512 | } | ||
| 2513 | |||
| 2514 | |||
| 2515 | sub get_cursor_y2 { | ||
| 2516 | my $self = shift; | ||
| 2517 | |||
| 2518 | # error trigger view | ||
| 2519 | my $r = $self->query("CURS:HBA:POSITION2?"); | ||
| 2520 | $self->_debug(); | ||
| 2521 | return $self->_parseReply($r); | ||
| 2522 | } | ||
| 2523 | |||
| 2524 | |||
| 2525 | sub set_cursor_x1 { | ||
| 2526 | my $self = shift; | ||
| 2527 | my ($ipos) = $self->_check_args_strict( \@_, ['position'] ); | ||
| 2528 | $self->_set_cursor( 'VBA', 1, $ipos ); | ||
| 2529 | } | ||
| 2530 | |||
| 2531 | |||
| 2532 | sub set_cursor_x2 { | ||
| 2533 | my $self = shift; | ||
| 2534 | my ($ipos) = $self->_check_args_strict( \@_, ['position'] ); | ||
| 2535 | $self->_set_cursor( 'VBA', 2, $ipos ); | ||
| 2536 | } | ||
| 2537 | |||
| 2538 | |||
| 2539 | sub set_cursor_y1 { | ||
| 2540 | my $self = shift; | ||
| 2541 | my ($ipos) = $self->_check_args_strict( \@_, ['position'] ); | ||
| 2542 | $self->_set_cursor( 'HBA', 1, $ipos ); | ||
| 2543 | } | ||
| 2544 | |||
| 2545 | |||
| 2546 | sub set_cursor_y2 { | ||
| 2547 | my $self = shift; | ||
| 2548 | my ($ipos) = $self->_check_args_strict( \@_, ['position'] ); | ||
| 2549 | $self->_set_cursor( 'HBA', 2, $ipos ); | ||
| 2550 | } | ||
| 2551 | |||
| 2552 | # setting cursors has a lot of 'common' code, so | ||
| 2553 | # do it here | ||
| 2554 | # $self->_set_cursor(VBA|HBA,1|2,position); | ||
| 2555 | # | ||
| 2556 | |||
| 2557 | sub _set_cursor { | ||
| 2558 | my $self = shift; | ||
| 2559 | my $t = shift; | ||
| 2560 | my $c = shift; | ||
| 2561 | my $ipos = shift; | ||
| 2562 | |||
| 2563 | my $pos; | ||
| 2564 | |||
| 2565 | if ( $t eq 'HBA' ) { | ||
| 2566 | my $u = $self->get_cursor_units(); | ||
| 2567 | |||
| 2568 | # VOL, AMPS , DECIBELS, DIV, UNKNOWN, VOLTSSQUARE, ampssquared, voltsamps | ||
| 2569 | my $u2 = ''; | ||
| 2570 | my $u3 = ''; | ||
| 2571 | $u2 = 'V' if $u eq 'VOL'; | ||
| 2572 | $u2 = 'A' if $u eq 'AMPS'; | ||
| 2573 | $u2 = 'dB' if $u eq 'DECIBELS'; | ||
| 2574 | $u3 = 'dBV' if $u eq 'DECIBELS'; | ||
| 2575 | $u2 = 'V.V' if $u eq 'VOLTSSQUARED'; | ||
| 2576 | $u2 = 'A.A' if $u eq 'AMPSSQUARED'; | ||
| 2577 | $u2 = 'W' if $u eq 'VOLTSAMPS'; | ||
| 2578 | $u3 = 'V.A' if $u eq 'VOLTSAMPS'; | ||
| 2579 | |||
| 2580 | $pos = _parseNRf( $ipos, $u, $u2, $u3 ); | ||
| 2581 | } | ||
| 2582 | else { | ||
| 2583 | my $u = $self->get_cursor_units(); | ||
| 2584 | |||
| 2585 | # SECO HER | ||
| 2586 | my $u2 = ''; | ||
| 2587 | my $u3 = ''; | ||
| 2588 | $u2 = 'seconds' if $u eq 'SECO'; | ||
| 2589 | $u3 = 's' if $u eq 'SECO'; | ||
| 2590 | $u2 = 'hertz' if $u eq 'HER'; | ||
| 2591 | $u3 = 'hz' if $u eq 'HER'; | ||
| 2592 | $pos = _parseNRf( $ipos, $u, $u2, $u3 ); | ||
| 2593 | } | ||
| 2594 | if ( $pos =~ /ERR/ || $pos eq 'MIN' || $pos eq 'MAX' ) { | ||
| 2595 | Lab::Exception::CorruptParameter->throw( | ||
| 2596 | "Error parsing position '$ipos' \n"); | ||
| 2597 | return; | ||
| 2598 | } | ||
| 2599 | $self->write("CURS:${t}:POSITION${c} $pos"); | ||
| 2600 | $self->_debug(); | ||
| 2601 | } | ||
| 2602 | |||
| 2603 | |||
| 2604 | sub get_cursor_v1 { | ||
| 2605 | my $self = shift; | ||
| 2606 | |||
| 2607 | my $r = $self->query("CURS:VBA:HPOS1?"); | ||
| 2608 | $self->_debug(); | ||
| 2609 | return $self->_parseReply($r); | ||
| 2610 | } | ||
| 2611 | |||
| 2612 | |||
| 2613 | sub get_cursor_v2 { | ||
| 2614 | my $self = shift; | ||
| 2615 | |||
| 2616 | my $r = $self->query("CURS:VBA:HPOS2?"); | ||
| 2617 | $self->_debug(); | ||
| 2618 | return $self->_parseReply($r); | ||
| 2619 | } | ||
| 2620 | |||
| 2621 | |||
| 2622 | sub get_cursor_dv { | ||
| 2623 | my $self = shift; | ||
| 2624 | my $r = $self->query("CURS:VBA:VDELT?"); | ||
| 2625 | $self->_debug(); | ||
| 2626 | return $self->_parseReply($r); | ||
| 2627 | } | ||
| 2628 | |||
| 2629 | |||
| 2630 | sub get_cursor { | ||
| 2631 | my $self = shift; | ||
| 2632 | my ($tail) = $self->_check_args( \@_ ); | ||
| 2633 | my $h = {}; | ||
| 2634 | |||
| 2635 | # errors if trigger view active... | ||
| 2636 | $h->{type} = $self->get_cursor_type($tail); | ||
| 2637 | $h->{xunits} = $self->get_cursor_xunits($tail); | ||
| 2638 | $h->{yunits} = $self->get_cursor_yunits($tail); | ||
| 2639 | $h->{source} = $self->get_cursor_source($tail); | ||
| 2640 | $h->{dx} = $self->get_cursor_dx($tail); | ||
| 2641 | $h->{dy} = $self->get_cursor_dy($tail); | ||
| 2642 | $h->{dv} = $self->get_cursor_dv($tail); | ||
| 2643 | $h->{x1} = $self->get_cursor_x1($tail); | ||
| 2644 | $h->{y1} = $self->get_cursor_y1($tail); | ||
| 2645 | $h->{x2} = $self->get_cursor_x2($tail); | ||
| 2646 | $h->{y2} = $self->get_cursor_y2($tail); | ||
| 2647 | $h->{v1} = $self->get_cursor_v1($tail); | ||
| 2648 | $h->{v2} = $self->get_cursor_v2($tail); | ||
| 2649 | return $h; | ||
| 2650 | } | ||
| 2651 | |||
| 2652 | |||
| 2653 | sub set_cursor { | ||
| 2654 | my $self = shift; | ||
| 2655 | my ($tail) = $self->_check_args( \@_ ); | ||
| 2656 | |||
| 2657 | $self->set_cursor_type($tail) if exists( $tail->{type} ); | ||
| 2658 | $self->set_cursor_yunits($tail) if exists( $tail->{yunits} ); | ||
| 2659 | $self->set_cursor_source($tail) if exists( $tail->{source} ); | ||
| 2660 | $self->set_cursor_x1($tail) if exists( $tail->{x1} ); | ||
| 2661 | $self->set_cursor_x2($tail) if exists( $tail->{x2} ); | ||
| 2662 | $self->set_cursor_y1($tail) if exists( $tail->{y1} ); | ||
| 2663 | $self->set_cursor_y2($tail) if exists( $tail->{y2} ); | ||
| 2664 | } | ||
| 2665 | |||
| 2666 | |||
| 2667 | sub get_display_contrast { | ||
| 2668 | my $self = shift; | ||
| 2669 | my $r = $self->query("DIS:CONTR?"); | ||
| 2670 | $self->_debug(); | ||
| 2671 | return $self->_parseReply($r); | ||
| 2672 | } | ||
| 2673 | |||
| 2674 | |||
| 2675 | sub set_display_contrast { | ||
| 2676 | my $self = shift; | ||
| 2677 | my ($cont) = $self->_check_args_strict( \@_, 'contrast' ); | ||
| 2678 | $cont = int( $cont + 0.5 ); | ||
| 2679 | if ( $cont < 1 || $cont > 100 ) { | ||
| 2680 | Lab::Exception::CorruptParameter->throw( | ||
| 2681 | "Contrast out of range 1..100 \n"); | ||
| 2682 | return; | ||
| 2683 | } | ||
| 2684 | $self->write("DIS:CONTR $cont"); | ||
| 2685 | $self->_debug(); | ||
| 2686 | } | ||
| 2687 | |||
| 2688 | |||
| 2689 | sub get_display_format { | ||
| 2690 | my $self = shift; | ||
| 2691 | my $f = $self->query("DIS:FORM?"); | ||
| 2692 | $self->_debug(); | ||
| 2693 | return $f; | ||
| 2694 | } | ||
| 2695 | |||
| 2696 | |||
| 2697 | sub set_display_format { | ||
| 2698 | my $self = shift; | ||
| 2699 | my ($f) = $self->_check_args_strict( \@_, 'format' ); | ||
| 2700 | $f = _keyword( $f, qw(XY YT) ); | ||
| 2701 | $self->write("DIS:FORM $f"); | ||
| 2702 | $self->_debug(); | ||
| 2703 | |||
| 2704 | if ( $f eq 'XY' ) { | ||
| 2705 | $self->{device_cache}->{cursor_type} = 'OFF'; | ||
| 2706 | } | ||
| 2707 | } | ||
| 2708 | |||
| 2709 | |||
| 2710 | sub get_display_persist { | ||
| 2711 | my $self = shift; | ||
| 2712 | my $r = $self->query("DIS:PERS?"); | ||
| 2713 | $r = $self->_parseReply($r); | ||
| 2714 | $r = 'OFF' if $r eq '0'; | ||
| 2715 | $r = 'INF' if $r eq '99'; | ||
| 2716 | $self->_debug(); | ||
| 2717 | return $r; | ||
| 2718 | } | ||
| 2719 | |||
| 2720 | |||
| 2721 | sub set_display_persist { | ||
| 2722 | my $self = shift; | ||
| 2723 | my ($pers) = $self->_check_args_strict( \@_, 'persist' ); | ||
| 2724 | my $p; | ||
| 2725 | |||
| 2726 | if ( $pers =~ /^\s*(INF|MAX)/i ) { | ||
| 2727 | $p = 'INF'; | ||
| 2728 | } | ||
| 2729 | elsif ( $pers =~ /^\s*(OFF|MIN|F|N|0)/i ) { | ||
| 2730 | $p = 'OFF'; | ||
| 2731 | } | ||
| 2732 | else { | ||
| 2733 | $p = _parseNRf( $pers, 's' ); | ||
| 2734 | if ( $p =~ /ERR/i || ( $p != 1 && $p != 2 && $p != 5 ) ) { | ||
| 2735 | Lab::Exception::CorruptParameter->throw( | ||
| 2736 | "Invalid persistance '$pers'\n"); | ||
| 2737 | return; | ||
| 2738 | } | ||
| 2739 | } | ||
| 2740 | $self->write("DIS:PERS $p"); | ||
| 2741 | $self->_debug(); | ||
| 2742 | } | ||
| 2743 | |||
| 2744 | |||
| 2745 | sub get_display_style { | ||
| 2746 | my $self = shift; | ||
| 2747 | my $r = $self->query("DIS:STY?"); | ||
| 2748 | $r = $self->_parseReply( $r, qw(DOT VEC) ); | ||
| 2749 | $r = _bloat( $r, { DOT => 'DOTS', VEC => 'VECTORS' } ); | ||
| 2750 | $self->_debug(); | ||
| 2751 | return $r; | ||
| 2752 | } | ||
| 2753 | |||
| 2754 | |||
| 2755 | sub set_display_style { | ||
| 2756 | my $self = shift; | ||
| 2757 | my ($st) = $self->_check_args_strict( \@_, 'style' ); | ||
| 2758 | $st = _keyword( $st, qw(DOT VEC) ); | ||
| 2759 | $self->write("DIS:STY $st"); | ||
| 2760 | $self->_debug(); | ||
| 2761 | } | ||
| 2762 | |||
| 2763 | |||
| 2764 | sub get_display { | ||
| 2765 | my $self = shift; | ||
| 2766 | my ($tail) = $self->_check_args( \@_ ); | ||
| 2767 | my $h = {}; | ||
| 2768 | $h->{contrast} = $self->get_display_contrast($tail); | ||
| 2769 | $h->{format} = $self->get_display_format($tail); | ||
| 2770 | $h->{persist} = $self->get_display_persist($tail); | ||
| 2771 | $h->{style} = $self->get_display_style($tail); | ||
| 2772 | return $h; | ||
| 2773 | } | ||
| 2774 | |||
| 2775 | |||
| 2776 | sub set_display { | ||
| 2777 | my $self = shift; | ||
| 2778 | my ($tail) = $self->_check_args( \@_ ); | ||
| 2779 | $self->set_display_contrast($tail) if exists $tail->{contrast}; | ||
| 2780 | $self->set_display_format($tail) if exists $tail->{format}; | ||
| 2781 | $self->set_display_persist($tail) if exists $tail->{persist}; | ||
| 2782 | $self->set_display_style($tail) if exists $tail->{style}; | ||
| 2783 | } | ||
| 2784 | |||
| 2785 | |||
| 2786 | sub get_cwd { | ||
| 2787 | my $self = shift; | ||
| 2788 | my $r = $self->query("FILES:CWD?"); | ||
| 2789 | $self->_debug(); | ||
| 2790 | return $self->_parseReply($r); | ||
| 2791 | } | ||
| 2792 | |||
| 2793 | |||
| 2794 | sub set_cwd { | ||
| 2795 | my $self = shift; | ||
| 2796 | my ($icwd) = $self->_check_args_strict( \@_, ['cwd'] ); | ||
| 2797 | |||
| 2798 | my $cwd = $icwd; | ||
| 2799 | $cwd =~ s/\//\\/g; | ||
| 2800 | $self->write("FILES:CWD $cwd"); | ||
| 2801 | $self->_debug(); | ||
| 2802 | } | ||
| 2803 | |||
| 2804 | |||
| 2805 | sub delete { | ||
| 2806 | my $self = shift; | ||
| 2807 | my ($file) = $self->_check_args_strict( \@_, ['file'] ); | ||
| 2808 | |||
| 2809 | $file =~ tr{/}{\\}; | ||
| 2810 | |||
| 2811 | $self->write("FILES:DELE \"$file\""); | ||
| 2812 | $self->_debug(); | ||
| 2813 | } | ||
| 2814 | |||
| 2815 | |||
| 2816 | sub get_dir { | ||
| 2817 | my $self = shift; | ||
| 2818 | my $r = $self->query("FILES:DIR?"); | ||
| 2819 | $r = $self->_parseReply($r); | ||
| 2820 | $self->_debug(); | ||
| 2821 | return _parseStrings($r); | ||
| 2822 | } | ||
| 2823 | |||
| 2824 | sub _parseStrings { | ||
| 2825 | my $str = shift; | ||
| 2826 | my (@results) = (); | ||
| 2827 | return (@results) unless defined $str; | ||
| 2828 | $str =~ s/^\s+//; | ||
| 2829 | $str .= ' ,' if $str !~ /,\s*$/; | ||
| 2830 | my $x; | ||
| 2831 | |||
| 2832 | while ( $str ne '' ) { | ||
| 2833 | last if $str =~ /^\s*,?\s*$/; | ||
| 2834 | if ( $str =~ /^\"(([^\"]|\"\")+)\"\s*,/i ) { | ||
| 2835 | $x = $1; | ||
| 2836 | $x =~ s/\"\"/"/g; | ||
| 2837 | $str = $POSTMATCH; | ||
| 2838 | push( @results, $x ); | ||
| 2839 | } | ||
| 2840 | elsif ( $str =~ /^\'(([^\']|\'\')+)\'\s*,/i ) { | ||
| 2841 | $x = $1; | ||
| 2842 | $x =~ s/\'\'/'/g; | ||
| 2843 | $str = $POSTMATCH; | ||
| 2844 | push( @results, $x ); | ||
| 2845 | } | ||
| 2846 | elsif ( $str =~ /^([^,]*[^,\s])\s*,/i ) { | ||
| 2847 | $x = $1; | ||
| 2848 | $str = $POSTMATCH; | ||
| 2849 | push( @results, $x ); | ||
| 2850 | } | ||
| 2851 | else { | ||
| 2852 | carp("problems parsing strings '$str'"); | ||
| 2853 | last; | ||
| 2854 | } | ||
| 2855 | $str =~ s/^\s+//; | ||
| 2856 | } | ||
| 2857 | return (@results); | ||
| 2858 | } | ||
| 2859 | |||
| 2860 | |||
| 2861 | sub get_freespace { | ||
| 2862 | my $self = shift; | ||
| 2863 | my $r = $self->query("FILES:FREES?"); | ||
| 2864 | $self->_debug(); | ||
| 2865 | return $self->parseReply($r); | ||
| 2866 | } | ||
| 2867 | |||
| 2868 | |||
| 2869 | sub mkdir { | ||
| 2870 | my $self = shift; | ||
| 2871 | my ($d) = $self->_check_args_strict( \@_, ['directory'] ); | ||
| 2872 | |||
| 2873 | $d =~ tr{/}{\\}; | ||
| 2874 | |||
| 2875 | $self->write("FILES:MKD \"$d\""); | ||
| 2876 | $self->_debug(); | ||
| 2877 | } | ||
| 2878 | |||
| 2879 | |||
| 2880 | sub rename { | ||
| 2881 | my $self = shift; | ||
| 2882 | my ( $old, $new ) = $self->_check_args_strict( \@_, qw(old new) ); | ||
| 2883 | |||
| 2884 | $old =~ tr{/}{\\}; | ||
| 2885 | $new =~ tr{/}{\\}; | ||
| 2886 | |||
| 2887 | $self->write("FILES:REN \"$old\",\"$new\""); | ||
| 2888 | $self->_debug(); | ||
| 2889 | } | ||
| 2890 | |||
| 2891 | |||
| 2892 | sub rmdir { | ||
| 2893 | my $self = shift; | ||
| 2894 | my ($d) = $self->_check_args_strict( \@_, ['directory'] ); | ||
| 2895 | |||
| 2896 | $d =~ tr{/}{\\}; | ||
| 2897 | $self->write("FILES:RMD \"$d\""); | ||
| 2898 | $self->_debug(); | ||
| 2899 | } | ||
| 2900 | |||
| 2901 | |||
| 2902 | sub get_hardcopy_format { | ||
| 2903 | my $self = shift; | ||
| 2904 | |||
| 2905 | my $r = $self->query("HARDC:FORM?"); | ||
| 2906 | $r = $self->_parseReply( | ||
| 2907 | $r, qw( BMP BUBBLEJ DESKJ DPU3445 | ||
| 2908 | DPU411 DPU412 EPSC60 EPSC80 EPSIMAGE EPSO INTERLEAF | ||
| 2909 | JPEG LASERJ PCX RLE THINK TIFF) | ||
| 2910 | ); | ||
| 2911 | $self->_debug(); | ||
| 2912 | return _bloat( | ||
| 2913 | $r, { | ||
| 2914 | BUBBLEJ => 'BUBBLEJET', DESKJ => 'DESKJET', | ||
| 2915 | EPSO => 'EPSON', THINK => 'THINKJET' | ||
| 2916 | } | ||
| 2917 | ); | ||
| 2918 | } | ||
| 2919 | |||
| 2920 | |||
| 2921 | sub set_hardcopy_format { | ||
| 2922 | my $self = shift; | ||
| 2923 | my ($in) = $self->_check_args_strict( \@_, ['format'] ); | ||
| 2924 | my $f; | ||
| 2925 | |||
| 2926 | $in =~ s/^\s*//; | ||
| 2927 | if ( $in =~ /^BMP/i ) { | ||
| 2928 | $f = 'BMP'; | ||
| 2929 | } | ||
| 2930 | elsif ( $in =~ /^(BUB|BJ)/i ) { | ||
| 2931 | $f = 'BUBBLEJ'; | ||
| 2932 | } | ||
| 2933 | elsif ( $in =~ /^(DESKJ|DJ)/i ) { | ||
| 2934 | $f = 'DESKJ'; | ||
| 2935 | } | ||
| 2936 | elsif ( $in =~ /^DPU3/i ) { | ||
| 2937 | $f = 'DPU3445'; | ||
| 2938 | } | ||
| 2939 | elsif ( $in =~ /^DPU411/i ) { | ||
| 2940 | $f = 'DPU411'; | ||
| 2941 | } | ||
| 2942 | elsif ( $in =~ /^DPU412/i ) { | ||
| 2943 | $f = 'DPU412'; | ||
| 2944 | } | ||
| 2945 | elsif ( $in =~ /^(EPSC6|EPSON\s*(S(TYLUS)?)?\s*C6)/i ) { | ||
| 2946 | $f = 'EPSC60'; | ||
| 2947 | } | ||
| 2948 | elsif ( $in =~ /^(EPSC8|EPSON\s*(S(TYLUS)?)?\s*C8)/i ) { | ||
| 2949 | $f = 'EPSC80'; | ||
| 2950 | } | ||
| 2951 | elsif ( $in =~ /^epso/i ) { | ||
| 2952 | $f = 'EPSO'; | ||
| 2953 | } | ||
| 2954 | elsif ( $in =~ /^(eps|post)/i ) { | ||
| 2955 | $f = 'EPSIMAGE'; | ||
| 2956 | } | ||
| 2957 | elsif ( $in =~ /^INTER/i ) { | ||
| 2958 | $f = 'INTERLEAF'; | ||
| 2959 | } | ||
| 2960 | elsif ( $in =~ /^JP/i ) { | ||
| 2961 | $f = 'JPEG'; | ||
| 2962 | } | ||
| 2963 | elsif ( $in =~ /^(LASER|LJ)/i ) { | ||
| 2964 | $f = 'LASERJ'; | ||
| 2965 | } | ||
| 2966 | elsif ( $in =~ /^PCX/i ) { | ||
| 2967 | $f = 'PCX'; | ||
| 2968 | } | ||
| 2969 | elsif ( $in =~ /^RLE/i ) { | ||
| 2970 | $f = 'RLE'; | ||
| 2971 | } | ||
| 2972 | elsif ( $in =~ /^THIN/i ) { | ||
| 2973 | $f = 'THINK'; | ||
| 2974 | } | ||
| 2975 | elsif ( $in =~ /^TIF/i ) { | ||
| 2976 | $f = 'TIFF'; | ||
| 2977 | } | ||
| 2978 | else { | ||
| 2979 | Lab::Exception::CorruptParameter->throw( | ||
| 2980 | "Invalid hardcopy format '$in'\n"); | ||
| 2981 | return; | ||
| 2982 | } | ||
| 2983 | |||
| 2984 | $self->write("HARDC:FORM $f"); | ||
| 2985 | $self->_debug(); | ||
| 2986 | } | ||
| 2987 | |||
| 2988 | |||
| 2989 | sub get_hardcopy_layout { | ||
| 2990 | my $self = shift; | ||
| 2991 | my $r = $self->query("HARDC:LAY?"); | ||
| 2992 | $r = $self->_parseResponse( $r, qw(PORTR LAN) ); | ||
| 2993 | $self->_debug(); | ||
| 2994 | return _bloat( $r, { PORTR => 'PORTRAIT', LAN => 'LANDSCAPE' } ); | ||
| 2995 | } | ||
| 2996 | |||
| 2997 | |||
| 2998 | sub set_hardcopy_layout { | ||
| 2999 | my $self = shift; | ||
| 3000 | my ($in) = $self->_check_args_strict( \@_, ['layout'] ); | ||
| 3001 | my $lay; | ||
| 3002 | |||
| 3003 | if ( $in =~ /^\s*(P|N)/i ) { | ||
| 3004 | $lay = 'PORTR'; | ||
| 3005 | } | ||
| 3006 | elsif ( $in =~ /^\s*(L|R)/i ) { | ||
| 3007 | $lay = 'LAN'; | ||
| 3008 | } | ||
| 3009 | else { | ||
| 3010 | Lab::Exception::CorruptParameter->throw( | ||
| 3011 | "Invalid hardcopy layout '$in'\n"); | ||
| 3012 | return; | ||
| 3013 | } | ||
| 3014 | $self->write("HARDC:LAY $lay"); | ||
| 3015 | $self->_debug(); | ||
| 3016 | } | ||
| 3017 | |||
| 3018 | |||
| 3019 | sub get_hardcopy_port { | ||
| 3020 | my $self = shift; | ||
| 3021 | my $r = $self->query("HARDC:PORT?"); | ||
| 3022 | $self->_debug(); | ||
| 3023 | return $self->_parseReply($r); | ||
| 3024 | } | ||
| 3025 | |||
| 3026 | |||
| 3027 | sub set_hardcopy_port { | ||
| 3028 | my $self = shift; | ||
| 3029 | my ($in) = $self->_check_args_strict( \@_, ['port'] ); | ||
| 3030 | my $p = _keyword( $in, qw(USB CEN RS232 GPI) ); | ||
| 3031 | if ( $p ne 'USB' ) { | ||
| 3032 | Lab::Exception::CorruptParameter->throw( | ||
| 3033 | "Invalid hardcopy port '$in'\n"); | ||
| 3034 | return; | ||
| 3035 | } | ||
| 3036 | $self->write("HARDC:PORT $p"); | ||
| 3037 | $self->_debug(); | ||
| 3038 | } | ||
| 3039 | |||
| 3040 | |||
| 3041 | sub get_hardcopy { | ||
| 3042 | my $self = shift; | ||
| 3043 | |||
| 3044 | my $h = {}; | ||
| 3045 | $h->{format} = $self->get_hardcopy_format(); | ||
| 3046 | $h->{layout} = $self->get_hardcopy_layout(); | ||
| 3047 | $h->{port} = $self->get_hardcopy_port(); | ||
| 3048 | return $h; | ||
| 3049 | } | ||
| 3050 | |||
| 3051 | |||
| 3052 | sub set_hardcopy { | ||
| 3053 | my $self = shift; | ||
| 3054 | my ($tail) = $self->_check_args( \@_ ); | ||
| 3055 | $self->set_hardcopy_format($tail) if exists $tail->{format}; | ||
| 3056 | $self->set_hardcopy_layout($tail) if exists $tail->{layout}; | ||
| 3057 | $self->set_hardcopy_port($tail) if exists $tail->{port}; | ||
| 3058 | } | ||
| 3059 | |||
| 3060 | |||
| 3061 | sub get_image { | ||
| 3062 | my $self = shift; | ||
| 3063 | my ( $file, $force, $tail ) = $self->_check_args( \@_, qw(file force) ); | ||
| 3064 | |||
| 3065 | my $ovr = 0; | ||
| 3066 | if ( defined($force) ) { | ||
| 3067 | if ( $force =~ /^\s*(T|[1-9]|Y)/i ) { | ||
| 3068 | $ovr = 1; | ||
| 3069 | } | ||
| 3070 | elsif ( $force =~ /^s*(F|0|N)/i ) { | ||
| 3071 | $ovr = 0; | ||
| 3072 | } | ||
| 3073 | else { | ||
| 3074 | Lab::Exception::CorruptParameter->throw( | ||
| 3075 | "Invalid 'force overwrite' flag '$force'\n"); | ||
| 3076 | return; | ||
| 3077 | } | ||
| 3078 | } | ||
| 3079 | |||
| 3080 | # do file check before image transfer | ||
| 3081 | if ( defined($file) ) { | ||
| 3082 | |||
| 3083 | if ( -e $file && ( !$ovr || !-w $file ) ) { | ||
| 3084 | Lab::Exception::CorruptParameter->throw( | ||
| 3085 | "Output file $file exists, not writable, force overwrite not set\n" | ||
| 3086 | ); | ||
| 3087 | return; | ||
| 3088 | } | ||
| 3089 | } | ||
| 3090 | |||
| 3091 | $self->set_hardcopy($tail); | ||
| 3092 | my $head = $self->get_header(); | ||
| 3093 | $self->set_header(0); | ||
| 3094 | |||
| 3095 | # default 30s timeout, unlimited length, maybe no \n at end | ||
| 3096 | # note that we really need READ_BUFFER to be set correctly | ||
| 3097 | # for efficient image reading. | ||
| 3098 | my $args = {}; | ||
| 3099 | $args->{timeout} = 30; | ||
| 3100 | $args->{read_length} = -1; | ||
| 3101 | $args->{timeout} = $tail->{timeout} if exists( $tail->{timeout} ); | ||
| 3102 | |||
| 3103 | $args->{brutal} = 1; # read to the very end | ||
| 3104 | $args->{no_LF} = 1; | ||
| 3105 | |||
| 3106 | my $r; | ||
| 3107 | $self->write("HARDC STAR"); | ||
| 3108 | $r = $self->read($args); | ||
| 3109 | $self->set_header($head); | ||
| 3110 | |||
| 3111 | carp("No image data read") unless defined($r); | ||
| 3112 | if ( defined($file) && defined($r) ) { | ||
| 3113 | open( IMG, ">$file" ) || croak("unable to open $file for writing"); | ||
| 3114 | print IMG $r; | ||
| 3115 | close(IMG); | ||
| 3116 | } | ||
| 3117 | |||
| 3118 | return $r; | ||
| 3119 | } | ||
| 3120 | |||
| 3121 | |||
| 3122 | sub get_horiz_view { | ||
| 3123 | my $self = shift; | ||
| 3124 | my $r = $self->query("HOR:VIEW?"); | ||
| 3125 | $self->_debug(); | ||
| 3126 | $r = $self->_parseReply( $r, qw(MAI WINDOW ZONE) ); | ||
| 3127 | return _bloat( $r, { MAI => 'MAIN' } ); | ||
| 3128 | } | ||
| 3129 | |||
| 3130 | |||
| 3131 | sub set_horiz_view { | ||
| 3132 | my $self = shift; | ||
| 3133 | my ($v) = $self->_check_args_strict( \@_, ['view'] ); | ||
| 3134 | $v = _keyword( $v, qw(MAI WIN ZON) ); | ||
| 3135 | $v = _bloat( $v, { WIN => 'WINDOW', ZON => 'ZONE' } ); | ||
| 3136 | $self->write("HOR:VIEW $v"); | ||
| 3137 | $self->_debug(); | ||
| 3138 | } | ||
| 3139 | |||
| 3140 | |||
| 3141 | sub get_horiz_position { | ||
| 3142 | my $self = shift; | ||
| 3143 | my $r = $self->query("HOR:POS?"); | ||
| 3144 | $self->_debug(); | ||
| 3145 | |||
| 3146 | return $self->_parseReply($r); | ||
| 3147 | } | ||
| 3148 | |||
| 3149 | |||
| 3150 | sub set_horiz_position { | ||
| 3151 | my $self = shift; | ||
| 3152 | my ($in) = $self->_check_args_strict( \@_, ['time'] ); | ||
| 3153 | |||
| 3154 | my $t = _parseNRf( $in, 's' ); | ||
| 3155 | if ( $t eq 'MIN' || $t eq 'MAX' || $t =~ /ERR/ ) { | ||
| 3156 | Lab::Exception::CorruptParameter->throw("Invalid time input '$in'\n"); | ||
| 3157 | return; | ||
| 3158 | } | ||
| 3159 | $t = sprintf( '%.3e', $t ); | ||
| 3160 | |||
| 3161 | $self->write("HOR:POS $t"); | ||
| 3162 | $self->_debug(); | ||
| 3163 | } | ||
| 3164 | |||
| 3165 | |||
| 3166 | sub get_delay_position { | ||
| 3167 | my $self = shift; | ||
| 3168 | my $r = $self->query("HOR:DEL:POS?"); | ||
| 3169 | $self->_debug(); | ||
| 3170 | $r = $self->_parseReply($r); | ||
| 3171 | return $r; | ||
| 3172 | } | ||
| 3173 | |||
| 3174 | |||
| 3175 | sub set_delay_position { | ||
| 3176 | my $self = shift; | ||
| 3177 | my ($in) = $self->_check_args_strict( \@_, ['delaytime'] ); | ||
| 3178 | my $t = _parseNRf( $in, 's' ); | ||
| 3179 | if ( $t eq 'MIN' || $t eq 'MAX' || $t =~ /ERR/ ) { | ||
| 3180 | Lab::Exception::CorruptParameter->throw("Invalid time input '$in'\n"); | ||
| 3181 | return; | ||
| 3182 | } | ||
| 3183 | $t = sprintf( '%.3e', $t ); | ||
| 3184 | $self->write("HOR:DEL:POS $t"); | ||
| 3185 | $self->_debug(); | ||
| 3186 | } | ||
| 3187 | |||
| 3188 | |||
| 3189 | sub get_horiz_scale { | ||
| 3190 | my $self = shift; | ||
| 3191 | my $r = $self->query("HOR:SCA?"); | ||
| 3192 | $self->_debug(); | ||
| 3193 | $r = $self->_parseReply($r); | ||
| 3194 | return $r; | ||
| 3195 | } | ||
| 3196 | |||
| 3197 | |||
| 3198 | sub set_horiz_scale { | ||
| 3199 | my $self = shift; | ||
| 3200 | my ($in) = $self->_check_args_strict( \@_, ['scale'] ); | ||
| 3201 | |||
| 3202 | my $s = _parseNRf( $in, 's', 's/div', 'Hz', 'Hz/div' ); | ||
| 3203 | |||
| 3204 | if ( $s eq 'MIN' || $s eq 'MAX' || $s =~ /ERR/ || $s <= 0 ) { | ||
| 3205 | Lab::Exception::CorruptParameter->throw( | ||
| 3206 | "Invalid time scale input '$in'\n"); | ||
| 3207 | return; | ||
| 3208 | } | ||
| 3209 | |||
| 3210 | $s = sprintf( '%.2e', $s ); | ||
| 3211 | my $ss = substr( $s, 0, 4 ); | ||
| 3212 | if ( $ss ne '1.00' && $ss ne '2.50' && $ss ne '5.00' ) { | ||
| 3213 | carp("warning: $s will be rounded to nearest acceptable value"); | ||
| 3214 | } | ||
| 3215 | |||
| 3216 | $self->write("HOR:SCA $s"); | ||
| 3217 | $self->_debug(); | ||
| 3218 | } | ||
| 3219 | |||
| 3220 | |||
| 3221 | sub get_delay_scale { | ||
| 3222 | my $self = shift; | ||
| 3223 | my $r = $self->query("HOR:DEL:SCA?"); | ||
| 3224 | $self->_debug(); | ||
| 3225 | $r = $self->_parseReply($r); | ||
| 3226 | return $r; | ||
| 3227 | } | ||
| 3228 | |||
| 3229 | |||
| 3230 | sub set_del_scale { | ||
| 3231 | my $self = shift; | ||
| 3232 | my ($in) = $self->_check_args_strict( \@_, ['delayscale'] ); | ||
| 3233 | |||
| 3234 | my $s = _parseNRf( $in, 's', 's/div', 'Hz', 'Hz/div' ); | ||
| 3235 | |||
| 3236 | if ( $s eq 'MIN' || $s eq 'MAX' || $s =~ /ERR/ || $s <= 0 ) { | ||
| 3237 | Lab::Exception::CorruptParameter->throw( | ||
| 3238 | "Invalid time scale input '$in'\n"); | ||
| 3239 | return; | ||
| 3240 | } | ||
| 3241 | |||
| 3242 | $s = sprintf( '%.2e', $s ); | ||
| 3243 | my $ss = substr( $s, 0, 4 ); | ||
| 3244 | if ( $ss ne '1.00' && $ss ne '2.50' && $ss ne '5.00' ) { | ||
| 3245 | carp("warning: $s will be rounded to nearest acceptable value"); | ||
| 3246 | } | ||
| 3247 | |||
| 3248 | $self->write("HOR:DEL:SCA $s"); | ||
| 3249 | $self->_debug(); | ||
| 3250 | } | ||
| 3251 | |||
| 3252 | |||
| 3253 | sub get_recordlength { | ||
| 3254 | return 2500; | ||
| 3255 | } | ||
| 3256 | |||
| 3257 | |||
| 3258 | sub get_horizontal { | ||
| 3259 | my $self = shift; | ||
| 3260 | my ($tail) = $self->_check_args( \@_ ); | ||
| 3261 | |||
| 3262 | my $h = {}; | ||
| 3263 | |||
| 3264 | $h->{view} = $self->get_horiz_view($tail); | ||
| 3265 | $h->{time} = $self->get_horiz_position($tail); | ||
| 3266 | $h->{delaytime} = $self->get_delay_position($tail); | ||
| 3267 | $h->{scale} = $self->get_horiz_scale($tail); | ||
| 3268 | $h->{delayscale} = $self->get_delay_scale($tail); | ||
| 3269 | $h->{recordlength} = $self->get_recordlength($tail); | ||
| 3270 | |||
| 3271 | return $h; | ||
| 3272 | } | ||
| 3273 | |||
| 3274 | |||
| 3275 | sub set_horizontal { | ||
| 3276 | my $self = shift; | ||
| 3277 | my ($tail) = $self->_check_args( \@_ ); | ||
| 3278 | |||
| 3279 | $self->set_horiz_view($tail) if exists $tail->{view}; | ||
| 3280 | $self->set_horiz_position($tail) if exists $tail->{time}; | ||
| 3281 | $self->set_horiz_scale($tail) if exists $tail->{scale}; | ||
| 3282 | $self->set_delay_position($tail) if exists $tail->{delaytime}; | ||
| 3283 | $self->set_delay_scale($tail) if exists $tail->{delayscale}; | ||
| 3284 | } | ||
| 3285 | |||
| 3286 | |||
| 3287 | sub get_math_definition { | ||
| 3288 | my $self = shift; | ||
| 3289 | my $r = $self->query("MATH:DEFINE?"); | ||
| 3290 | $self->_debug(); | ||
| 3291 | |||
| 3292 | if ( $r =~ /^\"/ ) { | ||
| 3293 | $r =~ s/^\"//; | ||
| 3294 | $r =~ s/\"$//; | ||
| 3295 | $r =~ s/\"\"/"/g; | ||
| 3296 | } | ||
| 3297 | elsif ( $r =~ /^\'/ ) { | ||
| 3298 | $r =~ s/^\'//; | ||
| 3299 | $r =~ s/\'$//; | ||
| 3300 | $r =~ s/\'\'/'/g; | ||
| 3301 | } | ||
| 3302 | else { | ||
| 3303 | croak("quoted string error"); | ||
| 3304 | } | ||
| 3305 | return $r; | ||
| 3306 | } | ||
| 3307 | |||
| 3308 | |||
| 3309 | sub set_math_definition { | ||
| 3310 | my $self = shift; | ||
| 3311 | my ($in) = $self->_check_args_strict( \@_, ['math'] ); | ||
| 3312 | |||
| 3313 | $in =~ s/\s+//g; | ||
| 3314 | $in = uc($in); | ||
| 3315 | |||
| 3316 | if ( $in =~ /^FFT\(CH(\d)(,\w+)?\)/i ) { | ||
| 3317 | my $ch = $1; | ||
| 3318 | my $w = ''; | ||
| 3319 | $w = substr( $2, 1 ) if defined($2) && $2 ne ''; | ||
| 3320 | $w = ',' . _keyword( $w, qw(HAN FLAT RECT) ) if $w ne ''; | ||
| 3321 | $self->write("MATH:DEFINE \"FFT(CH${ch}${w})\""); | ||
| 3322 | $self->set_channel('MATH'); | ||
| 3323 | $self->{device_channel}->{select} | ||
| 3324 | = $self->{chan_cache}->{MATH}->{select} | ||
| 3325 | = $self->{chan_cache}->{"CH${ch}"}->{select}; | ||
| 3326 | $self->{chan_cache}->{"CH${ch}"}->{select} = 0; | ||
| 3327 | } | ||
| 3328 | else { | ||
| 3329 | my $c = _keyword( | ||
| 3330 | $in, qw(CH1+CH2 CH3+CH4 CH1–CH2 CH2–CH1 | ||
| 3331 | CH3–CH4 CH4–CH3 CH1*CH2 CH3*CH4) | ||
| 3332 | ); | ||
| 3333 | $self->write("MATH:DEFINE \"${c}\""); | ||
| 3334 | } | ||
| 3335 | $self->_debug(); | ||
| 3336 | } | ||
| 3337 | |||
| 3338 | |||
| 3339 | sub get_math_position { | ||
| 3340 | my $self = shift; | ||
| 3341 | my $r = $self->query("MATH:VER:POS?"); | ||
| 3342 | $self->_debug(); | ||
| 3343 | $r = $self->_parseReply($r); | ||
| 3344 | return _parseNRf($r); | ||
| 3345 | } | ||
| 3346 | |||
| 3347 | |||
| 3348 | sub set_math_position { | ||
| 3349 | my $self = shift; | ||
| 3350 | my ($in) = $self->_check_args_strict( \@_, ['position'] ); | ||
| 3351 | |||
| 3352 | my $y; | ||
| 3353 | $y = _parseNRf( $in, 'div', 'divs' ); | ||
| 3354 | if ( $y =~ /ERR/ || $y eq 'MIN' || $y eq 'MAX' ) { | ||
| 3355 | Lab::Exception::CorruptParameter->throw( | ||
| 3356 | "Invalid MATH position input '$in'\n"); | ||
| 3357 | return; | ||
| 3358 | } | ||
| 3359 | $self->write("MATH:VER:POS $y"); | ||
| 3360 | $self->_debug(); | ||
| 3361 | } | ||
| 3362 | |||
| 3363 | |||
| 3364 | sub get_fft_xposition { | ||
| 3365 | my $self = shift; | ||
| 3366 | my $r = $self->query("MATH:FFT:HOR:POS?"); | ||
| 3367 | $self->_debug(); | ||
| 3368 | return $self->_parseReply($r); | ||
| 3369 | } | ||
| 3370 | |||
| 3371 | |||
| 3372 | sub set_fft_xposition { | ||
| 3373 | my $self = shift; | ||
| 3374 | my ($in) = $self->_check_args_strict( \@_, ['fft_xposition'] ); | ||
| 3375 | |||
| 3376 | my $p = _parseNRf( $in, '%', 'pct', 'percent' ); | ||
| 3377 | $p = 0 if $p eq 'MIN'; | ||
| 3378 | $p = 100 if $p eq 'MAX'; | ||
| 3379 | $p = sprintf( '%d', $p ) if $p !~ /ERR/; | ||
| 3380 | if ( $p =~ /ERR/ || $p < 0 || $p > 100 ) { | ||
| 3381 | Lab::Exception::CorruptParameter->throw( | ||
| 3382 | "Invalid FFT position input '$in'\n"); | ||
| 3383 | return; | ||
| 3384 | } | ||
| 3385 | $self->write("MATH:FFT:HOR:POS $p"); | ||
| 3386 | $self->_debug(); | ||
| 3387 | } | ||
| 3388 | |||
| 3389 | |||
| 3390 | sub get_fft_xscale { | ||
| 3391 | my $self = shift; | ||
| 3392 | my $r = $self->query("MATH:FFT:HOR:SCA?"); | ||
| 3393 | $self->_debug(); | ||
| 3394 | return $self->_parseReply($r); | ||
| 3395 | } | ||
| 3396 | |||
| 3397 | |||
| 3398 | sub set_fft_xscale { | ||
| 3399 | my $self = shift; | ||
| 3400 | my ($in) = $self->_check_args_strict( \@_, ['fft_xscale'] ); | ||
| 3401 | my $z = _parseNRf( $in, 'x' ); | ||
| 3402 | $z = 1 if $z eq 'MIN'; | ||
| 3403 | $z = 10 if $z eq 'MAX'; | ||
| 3404 | |||
| 3405 | if ( $z =~ /ERR/ || $z <= 0 ) { | ||
| 3406 | Lab::Exception::CorruptParameter->throw( | ||
| 3407 | "Invalid FFT xscale input '$in'\n"); | ||
| 3408 | return; | ||
| 3409 | } | ||
| 3410 | |||
| 3411 | my $zoom; | ||
| 3412 | if ( $z < 1.5 ) { | ||
| 3413 | $zoom = 1; | ||
| 3414 | } | ||
| 3415 | elsif ( $z < 3.5 ) { | ||
| 3416 | $zoom = 2; | ||
| 3417 | } | ||
| 3418 | elsif ( $z < 7.5 ) { | ||
| 3419 | $zoom = 5; | ||
| 3420 | } | ||
| 3421 | else { | ||
| 3422 | $zoom = 10; | ||
| 3423 | } | ||
| 3424 | |||
| 3425 | carp("FFT scale rounded to valid value") if abs( $z - $zoom ) > 0.01; | ||
| 3426 | $self->write("MATH:FFT:HOR:SCA $zoom"); | ||
| 3427 | $self->_debug(); | ||
| 3428 | } | ||
| 3429 | |||
| 3430 | |||
| 3431 | sub get_fft_position { | ||
| 3432 | my $self = shift; | ||
| 3433 | my $r = $self->query("MATH:FFT:VER:POS?"); | ||
| 3434 | $self->_debug(); | ||
| 3435 | return _parseReply($r); | ||
| 3436 | } | ||
| 3437 | |||
| 3438 | |||
| 3439 | sub set_fft_position { | ||
| 3440 | my $self = shift; | ||
| 3441 | my ($in) = $self->_check_args_strict( \@_, ['fft_position'] ); | ||
| 3442 | my $p = _parseNRf( $in, 'div', 'divs' ); | ||
| 3443 | |||
| 3444 | if ( $p eq 'MIN' || $p eq 'MAX' || $p =~ /ERR/ ) { | ||
| 3445 | Lab::Exception::CorruptParameter->throw( | ||
| 3446 | "Invalid FFT yposition '$in'\n"); | ||
| 3447 | return; | ||
| 3448 | } | ||
| 3449 | $self->write("MATH:FFT:VER:POS $p"); | ||
| 3450 | $self->_debug(); | ||
| 3451 | } | ||
| 3452 | |||
| 3453 | |||
| 3454 | sub get_fft_scale { | ||
| 3455 | my $self = shift; | ||
| 3456 | my $r = $self->query("MATH:FFT:VER:SCA?"); | ||
| 3457 | $self->_debug(); | ||
| 3458 | return _parseReply($r); | ||
| 3459 | } | ||
| 3460 | |||
| 3461 | |||
| 3462 | sub set_fft_scale { | ||
| 3463 | my $self = shift; | ||
| 3464 | my ($in) = $self->_check_args_strict( \@_, ['fft_scale'] ); | ||
| 3465 | my $z = _parseNRf( $in, 'x' ); | ||
| 3466 | |||
| 3467 | $z = 0.5 if $z eq 'MIN'; | ||
| 3468 | $z = 10 if $z eq 'MAX'; | ||
| 3469 | |||
| 3470 | if ( $z =~ /ERR/ || $z <= 0 ) { | ||
| 3471 | Lab::Exception::CorruptParameter->throw( | ||
| 3472 | "Invalid fft y scale input '$in'\n"); | ||
| 3473 | return; | ||
| 3474 | } | ||
| 3475 | |||
| 3476 | my $zoom; | ||
| 3477 | if ( $z < 0.75 ) { | ||
| 3478 | $zoom = 0.5; | ||
| 3479 | } | ||
| 3480 | elsif ( $z < 1.5 ) { | ||
| 3481 | $zoom = 1; | ||
| 3482 | } | ||
| 3483 | elsif ( $z < 3.5 ) { | ||
| 3484 | $zoom = 2; | ||
| 3485 | } | ||
| 3486 | elsif ( $z < 7.5 ) { | ||
| 3487 | $zoom = 5; | ||
| 3488 | } | ||
| 3489 | else { | ||
| 3490 | $zoom = 10; | ||
| 3491 | } | ||
| 3492 | |||
| 3493 | carp("fft_scale adjusted to valid value") if abs( $z - $zoom ) > 0.01; | ||
| 3494 | $self->write("MATH:FFT:VER:POS $zoom"); | ||
| 3495 | $self->_debug(); | ||
| 3496 | } | ||
| 3497 | |||
| 3498 | |||
| 3499 | # do our own cache handling, doesn't fit the normal scheme | ||
| 3500 | |||
| 3501 | sub get_measurement_type { | ||
| 3502 | my $self = shift; | ||
| 3503 | my ( $in, $tail ) = $self->_check_args( \@_, ['measurement'] ); | ||
| 3504 | $in = 'IMM' unless defined($in); | ||
| 3505 | |||
| 3506 | my $n; | ||
| 3507 | if ( $in =~ /^\s*imm/i || $in =~ /^\s*$/ ) { | ||
| 3508 | $n = 'imm'; | ||
| 3509 | } | ||
| 3510 | elsif ( $in =~ /^\s*(\d)\s*$/ ) { | ||
| 3511 | $n = $1; | ||
| 3512 | $n = undef if $n < 1 || $n > 5; | ||
| 3513 | } | ||
| 3514 | |||
| 3515 | if ( !defined($n) ) { | ||
| 3516 | Lab::Exception::CorruptParameter->throw( | ||
| 3517 | "invalid measurement# '$in' \n"); | ||
| 3518 | return; | ||
| 3519 | } | ||
| 3520 | |||
| 3521 | $tail->{read_mode} = $self->{config}->{default_read_mode} | ||
| 3522 | unless exists( $tail->{read_mode} ) && defined( $tail->{read_mode} ); | ||
| 3523 | $tail->{read_mode} = 'device' if $self->{config}->{no_cache}; | ||
| 3524 | |||
| 3525 | if ( $tail->{read_mode} eq 'cache' | ||
| 3526 | && defined( $self->{device_cache}->{"meas_type_$n"} ) ) { | ||
| 3527 | return $self->{device_cache}->{"meas_type_$n"}; | ||
| 3528 | } | ||
| 3529 | |||
| 3530 | my $nm; | ||
| 3531 | if ( $n eq 'imm' ) { | ||
| 3532 | $nm = 'IMM'; | ||
| 3533 | } | ||
| 3534 | else { | ||
| 3535 | $nm = "MEAS$n"; | ||
| 3536 | } | ||
| 3537 | |||
| 3538 | my $r = $self->query("MEASU:${nm}:TYP?"); | ||
| 3539 | $self->_debug(); | ||
| 3540 | $r = _parseReply( | ||
| 3541 | $r, | ||
| 3542 | qw(FREQ MEAN PERI PHA PK2 CRM MINI MAXI RIS FALL PW NWI NONE) | ||
| 3543 | ); | ||
| 3544 | |||
| 3545 | $r = _bloat( | ||
| 3546 | $r, { | ||
| 3547 | FREQ => 'FREQUENCY', PERI => 'PERIOD', PHA => 'PHASE', | ||
| 3548 | PK2 => 'PK2PK', CRM => 'CRMS', MINI => 'MINIMUM', | ||
| 3549 | MAXI => 'MAXIMUM', RIS => 'RISE', PWD => 'PWIDTH', | ||
| 3550 | NWI => 'NWIDTH' | ||
| 3551 | } | ||
| 3552 | ); | ||
| 3553 | $self->{device_cache}->{"meas_type_$n"} = $r; | ||
| 3554 | return $r; | ||
| 3555 | } | ||
| 3556 | |||
| 3557 | |||
| 3558 | sub set_measurement_type { | ||
| 3559 | my $self = shift; | ||
| 3560 | my ( $in, $type, $tail ) | ||
| 3561 | = $self->_check_args( \@_, qw(measurement measurement_type) ); | ||
| 3562 | |||
| 3563 | if ( !defined($in) || $in =~ /^\s*$/ ) { | ||
| 3564 | $in = 'IMM'; | ||
| 3565 | } | ||
| 3566 | elsif ( !defined($type) ) { | ||
| 3567 | $type = $in; | ||
| 3568 | $in = 'IMM'; | ||
| 3569 | } | ||
| 3570 | |||
| 3571 | my $n; | ||
| 3572 | my $nm; | ||
| 3573 | if ( $in =~ /^\s*imm/i ) { | ||
| 3574 | $n = 'imm'; | ||
| 3575 | $nm = 'IMM'; | ||
| 3576 | } | ||
| 3577 | elsif ( $in =~ /^\s*(\d)\s*$/ ) { | ||
| 3578 | $n = $1; | ||
| 3579 | $nm = "MEAS${n}"; | ||
| 3580 | } | ||
| 3581 | else { | ||
| 3582 | Lab::Exception::CorruptParameter->throw( | ||
| 3583 | "invalid measurement# '$in' \n"); | ||
| 3584 | return; | ||
| 3585 | } | ||
| 3586 | |||
| 3587 | my $ty; | ||
| 3588 | if ( $n ne 'imm' && $type =~ /^\s*NONE/i ) { | ||
| 3589 | $ty = 'NONE'; | ||
| 3590 | } | ||
| 3591 | else { | ||
| 3592 | $ty = _keyword( | ||
| 3593 | $type, | ||
| 3594 | qw(FREQ MEAN PERI PHA PK2 CRM MINI MAXI RIS FALL PW NWI) | ||
| 3595 | ); | ||
| 3596 | } | ||
| 3597 | $self->write("MEASU:${nm}:TYP $ty"); | ||
| 3598 | $self->_debug(); | ||
| 3599 | $self->get_measurement_type( measurement => $n ); | ||
| 3600 | } | ||
| 3601 | |||
| 3602 | |||
| 3603 | sub get_measurement_units { | ||
| 3604 | my $self = shift; | ||
| 3605 | my ( $in, $tail ) = $self->_check_args( \@_, ['measurement'] ); | ||
| 3606 | |||
| 3607 | my $n; | ||
| 3608 | my $nm; | ||
| 3609 | if ( !defined($in) || $in =~ /^\s*imm/i || $in =~ /^\s*$/ ) { | ||
| 3610 | $n = 'imm'; | ||
| 3611 | $nm = 'IMM'; | ||
| 3612 | } | ||
| 3613 | elsif ( $in =~ /^\s*(\d)\s*$/ ) { | ||
| 3614 | $n = $1; | ||
| 3615 | $nm = "MEAS${n}"; | ||
| 3616 | } | ||
| 3617 | else { | ||
| 3618 | Lab::Exception::CorruptParameter->throw( | ||
| 3619 | "invalid measurement# '$in' \n"); | ||
| 3620 | return; | ||
| 3621 | } | ||
| 3622 | |||
| 3623 | $tail->{read_mode} = $self->{config}->{default_read_mode} | ||
| 3624 | unless exists( $tail->{read_mode} ) && defined( $tail->{read_mode} ); | ||
| 3625 | $tail->{read_mode} = 'device' if $self->{config}->{no_cache}; | ||
| 3626 | |||
| 3627 | if ( $tail->{read_mode} eq 'cache' | ||
| 3628 | && defined( $self->{device_cache}->{"meas_units_${n}"} ) ) { | ||
| 3629 | return $self->{device_cache}->{"meas_units_${n}"}; | ||
| 3630 | } | ||
| 3631 | |||
| 3632 | my $r = $self->query("MEASU:${nm}:UNI?"); | ||
| 3633 | $self->_debug(); | ||
| 3634 | $r = $self->_parseReply($r); | ||
| 3635 | $self->{device_cache}->{"meas_units_${n}"} = $r; | ||
| 3636 | return $r; | ||
| 3637 | } | ||
| 3638 | |||
| 3639 | |||
| 3640 | sub get_measurement_source { | ||
| 3641 | my $self = shift; | ||
| 3642 | my ( $in, $tail ) = $self->_check_args( \@_, ['measurement'] ); | ||
| 3643 | |||
| 3644 | my $n; | ||
| 3645 | my $nm; | ||
| 3646 | if ( !defined($in) || $in =~ /^\s*imm/i || $in =~ /^\s*$/ ) { | ||
| 3647 | $n = 'imm'; | ||
| 3648 | $nm = 'IMM'; | ||
| 3649 | } | ||
| 3650 | elsif ( $in =~ /^\s*(\d)\s*$/ ) { | ||
| 3651 | $n = $1; | ||
| 3652 | $nm = "MEAS${n}"; | ||
| 3653 | } | ||
| 3654 | else { | ||
| 3655 | Lab::Exception::CorruptParameter->throw( | ||
| 3656 | "invalid measurement# '$in' \n"); | ||
| 3657 | return; | ||
| 3658 | } | ||
| 3659 | |||
| 3660 | $tail->{read_mode} = $self->{config}->{default_read_mode} | ||
| 3661 | unless exists( $tail->{read_mode} ) && defined( $tail->{read_mode} ); | ||
| 3662 | $tail->{read_mode} = 'device' if $self->{config}->{no_cache}; | ||
| 3663 | |||
| 3664 | if ( $tail->{read_mode} eq 'cache' | ||
| 3665 | && defined( $self->{device_cache}->{"meas_source_${n}"} ) ) { | ||
| 3666 | return $self->{device_cache}->{"meas_source_${n}"}; | ||
| 3667 | } | ||
| 3668 | |||
| 3669 | my $j = ''; | ||
| 3670 | $j = 1 if $n eq 'imm'; | ||
| 3671 | |||
| 3672 | my $r = $self->query("MEASU:${nm}:SOU${j}?"); | ||
| 3673 | $self->_debug(); | ||
| 3674 | $r = $self->_parseReply($r); | ||
| 3675 | $self->{device_cache}->{"meas_source_${n}"} = $r; | ||
| 3676 | return $r; | ||
| 3677 | } | ||
| 3678 | |||
| 3679 | |||
| 3680 | sub set_measurement_source { | ||
| 3681 | my $self = shift; | ||
| 3682 | my ( $in, $inw ) | ||
| 3683 | = $self->_check_args( \@_, qw(measurement measurement_source) ); | ||
| 3684 | |||
| 3685 | if ( !defined($inw) ) { | ||
| 3686 | $inw = $in; | ||
| 3687 | $in = 'IMM'; | ||
| 3688 | } | ||
| 3689 | |||
| 3690 | my $n; | ||
| 3691 | my $nm; | ||
| 3692 | if ( !defined($in) || $in =~ /^\s*imm/i || $in =~ /^\s*$/ ) { | ||
| 3693 | $n = 'imm'; | ||
| 3694 | $nm = 'IMM'; | ||
| 3695 | } | ||
| 3696 | elsif ( $in =~ /^\s*(\d)\s*$/ ) { | ||
| 3697 | $n = $1; | ||
| 3698 | $nm = "MEAS${n}"; | ||
| 3699 | } | ||
| 3700 | else { | ||
| 3701 | Lab::Exception::CorruptParameter->throw( | ||
| 3702 | "invalid measurement# '$in' \n"); | ||
| 3703 | return; | ||
| 3704 | } | ||
| 3705 | |||
| 3706 | my $j = ''; | ||
| 3707 | $j = 1 if $n eq 'imm'; | ||
| 3708 | |||
| 3709 | my $wfm = _keyword( $inw, qw(CH1 CH2 CH3 CH4 MATH) ); | ||
| 3710 | $self->write("MEASU:${nm}:SOU${j} $wfm"); | ||
| 3711 | $self->_debug(); | ||
| 3712 | $self->{device_cache}->{"meas_source_$n"} = $wfm; | ||
| 3713 | } | ||
| 3714 | |||
| 3715 | |||
| 3716 | sub get_measurement_value { | ||
| 3717 | my $self = shift; | ||
| 3718 | my ($in) = $self->_check_args( \@_, 'measurement' ); | ||
| 3719 | |||
| 3720 | my $n; | ||
| 3721 | my $nm; | ||
| 3722 | if ( !defined($in) || $in =~ /^\s*imm/i || $in =~ /^\s*$/ ) { | ||
| 3723 | $n = 'imm'; | ||
| 3724 | $nm = 'IMM'; | ||
| 3725 | } | ||
| 3726 | elsif ( $in =~ /^\s*(\d)\s*$/ ) { | ||
| 3727 | $n = $1; | ||
| 3728 | $nm = "MEAS${n}"; | ||
| 3729 | } | ||
| 3730 | else { | ||
| 3731 | Lab::Exception::CorruptParameter->throw( | ||
| 3732 | "invalid measurement# '$in' \n"); | ||
| 3733 | return; | ||
| 3734 | } | ||
| 3735 | |||
| 3736 | if ( $n ne 'imm' ) { | ||
| 3737 | if ( $self->get_measurement_type( measurement => $n ) eq 'NONE' ) { | ||
| 3738 | Lab::Exception::CorruptParameter->throw( | ||
| 3739 | "Measurement $n type set to 'NONE'\n"); | ||
| 3740 | return; | ||
| 3741 | } | ||
| 3742 | } | ||
| 3743 | |||
| 3744 | my $wfm = $self->get_measurement_source( measurement => $n ); | ||
| 3745 | if ( !$self->get_visible( source => $wfm ) ) { | ||
| 3746 | Lab::Exception::CorruptParameter->throw( | ||
| 3747 | "Meaurement only avail on visible traces\n"); | ||
| 3748 | return; | ||
| 3749 | } | ||
| 3750 | |||
| 3751 | my $r = $self->query("MEASU:${nm}:VAL?"); | ||
| 3752 | $self->_debug(); | ||
| 3753 | return _parseNRf($r); | ||
| 3754 | } | ||
| 3755 | |||
| 3756 | |||
| 3757 | sub trigger { | ||
| 3758 | my $self = shift; | ||
| 3759 | $self->write("TRIG FORC"); | ||
| 3760 | $self->_debug(); | ||
| 3761 | } | ||
| 3762 | |||
| 3763 | |||
| 3764 | sub get_trig_coupling { | ||
| 3765 | my $self = shift; | ||
| 3766 | my $r = $self->query("TRIG:MAI:EDGE:COUP?"); | ||
| 3767 | $self->_debug(); | ||
| 3768 | $r = $self->_parseReply( $r, qw(AC DC HFR LFR NOISE) ); | ||
| 3769 | return _bloat( | ||
| 3770 | $r, | ||
| 3771 | { HFR => 'HFREJ', LFR => 'LFREJ', NOISE => 'NOISEREJ' } | ||
| 3772 | ); | ||
| 3773 | } | ||
| 3774 | |||
| 3775 | |||
| 3776 | sub set_trig_coupling { | ||
| 3777 | my $self = shift; | ||
| 3778 | my ($in) = $self->_check_args_strict( \@_, 'coupling' ); | ||
| 3779 | |||
| 3780 | my $c = _keyword( $in, qw(AC DC HFR LFR NOISE) ); | ||
| 3781 | |||
| 3782 | $self->write("TRIG:MAI:EDGE:COUP $c"); | ||
| 3783 | $self->_debug(); | ||
| 3784 | } | ||
| 3785 | |||
| 3786 | |||
| 3787 | sub get_trig_slope { | ||
| 3788 | my $self = shift; | ||
| 3789 | my $r = $self->query("TRIG:MAI:EDGE:SLO?"); | ||
| 3790 | $self->_debug(); | ||
| 3791 | $r = $self->_parseReply( $r, qw(FALL RIS) ); | ||
| 3792 | $r = 'RISE' if $r eq 'RIS'; | ||
| 3793 | return $r; | ||
| 3794 | } | ||
| 3795 | |||
| 3796 | |||
| 3797 | sub set_trig_slope { | ||
| 3798 | my $self = shift; | ||
| 3799 | my ($in) = $self->_check_args_strict( \@_, 'slope' ); | ||
| 3800 | |||
| 3801 | my $sl; | ||
| 3802 | if ( $in =~ /^\s*(ri|up|pos|\+)/i ) { | ||
| 3803 | $sl = 'RIS'; | ||
| 3804 | } | ||
| 3805 | elsif ( $in =~ /^\s*(fa|d|neg|\-)/i ) { | ||
| 3806 | $sl = 'FALL'; | ||
| 3807 | } | ||
| 3808 | else { | ||
| 3809 | Lab::Exception::CorruptParameter->throw( | ||
| 3810 | "invalid trigger slope '$in'\n"); | ||
| 3811 | return; | ||
| 3812 | } | ||
| 3813 | |||
| 3814 | $self->write("TRIG:MAI:EDGE:SLO $sl"); | ||
| 3815 | $self->_debug(); | ||
| 3816 | } | ||
| 3817 | |||
| 3818 | |||
| 3819 | sub get_trig_source { | ||
| 3820 | my $self = shift; | ||
| 3821 | my ( $in, $tail ) = $self->_check_args( \@_, 'type' ); | ||
| 3822 | my $type; | ||
| 3823 | |||
| 3824 | if ( defined($in) ) { | ||
| 3825 | $type = _keyword( $in, qw(EDGE PUL VID) ); | ||
| 3826 | } | ||
| 3827 | else { | ||
| 3828 | $type = $self->get_trig_type(); | ||
| 3829 | } | ||
| 3830 | |||
| 3831 | my $t = lc( substr( $type, 0, 1 ) ); | ||
| 3832 | |||
| 3833 | $tail->{read_mode} = $self->{config}->{default_read_mode} | ||
| 3834 | unless exists( $tail->{read_mode} ) && defined( $tail->{read_mode} ); | ||
| 3835 | $tail->{read_mode} = 'device' if $self->{config}->{no_cache}; | ||
| 3836 | |||
| 3837 | if ( $tail->{read_mode} eq 'cache' ) { | ||
| 3838 | return $self->{device_cache}->{"${t}trig_source"} | ||
| 3839 | if defined( $self->{device_cache}->{"${t}trig_source"} ); | ||
| 3840 | } | ||
| 3841 | |||
| 3842 | my $r = $self->query("TRIG:MAI:${type}:SOU?"); | ||
| 3843 | $self->_debug(); | ||
| 3844 | $r = $self->_parseReply($r); | ||
| 3845 | $self->{device_cache}->{"${t}trig_source"} = $r; | ||
| 3846 | return $r; | ||
| 3847 | } | ||
| 3848 | |||
| 3849 | |||
| 3850 | sub set_trig_source { | ||
| 3851 | my $self = shift; | ||
| 3852 | my ( $in, $tail ) = $self->_check_args_strict( \@_, 'source' ); | ||
| 3853 | |||
| 3854 | my $s; | ||
| 3855 | if ( $in =~ /^\s*(CH[1-4]|EXT5?)/i ) { | ||
| 3856 | $s = uc($1); | ||
| 3857 | } | ||
| 3858 | elsif ( $in =~ /^\s*(AC|LINE)/i ) { | ||
| 3859 | $s = 'LINE'; | ||
| 3860 | } | ||
| 3861 | elsif ( $in =~ /^\s*([1-4])\s*$/ ) { | ||
| 3862 | $s = "CH$1"; | ||
| 3863 | } | ||
| 3864 | else { | ||
| 3865 | Lab::Exception::CorruptParameter->throw( | ||
| 3866 | "Invalid trigger source '$in'\n"); | ||
| 3867 | return; | ||
| 3868 | } | ||
| 3869 | |||
| 3870 | my $type; | ||
| 3871 | $type = $tail->{type} if exists( $tail->{type} ); | ||
| 3872 | $type = $self->get_trig_type() | ||
| 3873 | unless defined $type; | ||
| 3874 | $type = _keyword( $type, qw(EDGE PUL VID) ); | ||
| 3875 | my $t = lc( substr( $type, 0, 1 ) ); | ||
| 3876 | |||
| 3877 | $self->write("TRIG:MAI:${type}:SOU $s"); | ||
| 3878 | $self->_debug(); | ||
| 3879 | $self->{device_cache}->{"${t}trig_source"} | ||
| 3880 | = _bloat( $type, { PUL => 'PULSE', VID => 'VIDEO' } ); | ||
| 3881 | } | ||
| 3882 | |||
| 3883 | |||
| 3884 | sub get_trig_frequency { | ||
| 3885 | my $self = shift; | ||
| 3886 | |||
| 3887 | my $type = $self->get_trig_type(); | ||
| 3888 | if ( $type eq 'VIDEO' ) { | ||
| 3889 | Lab::Exception::CorruptParameter->throw( | ||
| 3890 | "Trigger frequency not availible for 'VIDEO' type trigger\n"); | ||
| 3891 | return; | ||
| 3892 | } | ||
| 3893 | |||
| 3894 | my $r = $self->query("TRIG:MAI:FREQ?"); | ||
| 3895 | $r = $self->_parseReply($r); | ||
| 3896 | if ( $r > 1e37 ) { | ||
| 3897 | $r = 1; | ||
| 3898 | |||
| 3899 | #clear out error | ||
| 3900 | $self->get_error(); | ||
| 3901 | } | ||
| 3902 | $self->_debug(); | ||
| 3903 | return $r; | ||
| 3904 | } | ||
| 3905 | |||
| 3906 | |||
| 3907 | sub get_trig_holdoff { | ||
| 3908 | my $self = shift; | ||
| 3909 | my $r = $self->query("TRIG:MAI:HOLDO:VAL?"); | ||
| 3910 | $self->_debug(); | ||
| 3911 | return $self->_parseReply($r); | ||
| 3912 | } | ||
| 3913 | |||
| 3914 | |||
| 3915 | sub set_trig_holdoff { | ||
| 3916 | my $self = shift; | ||
| 3917 | my ($in) = $self->_check_args_strict( \@_, 'holdoff' ); | ||
| 3918 | my $t = _parseNRf( $in, 's', 'sec' ); | ||
| 3919 | |||
| 3920 | $t = '5E-07' if $t eq 'MIN'; | ||
| 3921 | $t = 10 if $t eq 'MAX'; | ||
| 3922 | |||
| 3923 | if ( $t =~ /ERR/ ) { | ||
| 3924 | Lab::Exception::CorruptParameter->throw( | ||
| 3925 | "Error parsing holdoff '$in'\n"); | ||
| 3926 | return; | ||
| 3927 | } | ||
| 3928 | |||
| 3929 | if ( $t < 5e-7 || $t > 10 ) { | ||
| 3930 | Lab::Exception::CorruptParameter->throw( | ||
| 3931 | "Holdoff '$in' out of range (500ns..10s)\n"); | ||
| 3932 | return; | ||
| 3933 | } | ||
| 3934 | $self->write("TRIG:MAI:HOLDO:VAL $t"); | ||
| 3935 | $self->_debug(); | ||
| 3936 | } | ||
| 3937 | |||
| 3938 | |||
| 3939 | sub get_trig_level { | ||
| 3940 | my $self = shift; | ||
| 3941 | my $r = $self->query("TRIG:MAI:LEV?"); | ||
| 3942 | $self->_debug(); | ||
| 3943 | return _parseReply($r); | ||
| 3944 | } | ||
| 3945 | |||
| 3946 | |||
| 3947 | sub set_trig_level { | ||
| 3948 | my $self = shift; | ||
| 3949 | my ($in) = $self->_check_args_strict( \@_, 'level' ); | ||
| 3950 | return if $self->get_trig_source() eq 'AC LINE'; | ||
| 3951 | |||
| 3952 | my $v = _parseNRf( $in, 'v' ); | ||
| 3953 | |||
| 3954 | if ( $v eq 'MIN' || $v eq 'MAX' || $v =~ /ERR/ ) { | ||
| 3955 | Lab::Exception::CorruptParameter->throw( | ||
| 3956 | "Invalid trigger level '$in'\n"); | ||
| 3957 | return; | ||
| 3958 | } | ||
| 3959 | $v = sprintf( '%.3e', $v ); | ||
| 3960 | $self->write("TRIG:MAI:LEV $v"); | ||
| 3961 | $self->_debug(); | ||
| 3962 | } | ||
| 3963 | |||
| 3964 | |||
| 3965 | sub get_trig_mode { | ||
| 3966 | my $self = shift; | ||
| 3967 | my $r = $self->query("TRIG:MAI:MOD?"); | ||
| 3968 | $self->_debug(); | ||
| 3969 | $r = $self->_parseReply( $r, qw(AUTO NORM) ); | ||
| 3970 | $r = 'NORMAL' if $r eq 'NORM'; | ||
| 3971 | return $r; | ||
| 3972 | } | ||
| 3973 | |||
| 3974 | |||
| 3975 | sub set_trig_mode { | ||
| 3976 | my $self = shift; | ||
| 3977 | my ($in) = $self->_check_args_strict( \@_, 'mode' ); | ||
| 3978 | |||
| 3979 | my $m = _keyword( $in, qw(AUTO NORM) ); | ||
| 3980 | $self->write("TRIG:MAI:MOD $m"); | ||
| 3981 | $self->_debug(); | ||
| 3982 | } | ||
| 3983 | |||
| 3984 | |||
| 3985 | sub get_trig_type { | ||
| 3986 | my $self = shift; | ||
| 3987 | my $r = $self->query("TRIG:MAI:TYP?"); | ||
| 3988 | $self->_debug(); | ||
| 3989 | $r = $self->_parseReply( $r, qw(EDGE PUL VID) ); | ||
| 3990 | return _bloat( $r, { PUL => 'PULSE', VID => 'VIDEO' } ); | ||
| 3991 | } | ||
| 3992 | |||
| 3993 | |||
| 3994 | sub set_trig_type { | ||
| 3995 | my $self = shift; | ||
| 3996 | my ($in) = $self->_check_args_strict( \@_, 'type' ); | ||
| 3997 | |||
| 3998 | my $t = _keyword( $in, qw(EDG PUL VID) ); | ||
| 3999 | $t = 'EDGE' if $t eq 'EDG'; | ||
| 4000 | $self->write("TRIG:MAI:TYP $t"); | ||
| 4001 | $self->_debug(); | ||
| 4002 | } | ||
| 4003 | |||
| 4004 | |||
| 4005 | sub get_trig_pulse_width { | ||
| 4006 | my $self = shift; | ||
| 4007 | |||
| 4008 | my $r = $self->query("TRIG:MAI:PUL:WID:WID?"); | ||
| 4009 | $self->_debug(); | ||
| 4010 | return $self->_parseReply($r); | ||
| 4011 | } | ||
| 4012 | |||
| 4013 | |||
| 4014 | sub set_trig_pulse_width { | ||
| 4015 | my $self = shift; | ||
| 4016 | my ($in) = $self->_check_args_strict( \@_, 'width' ); | ||
| 4017 | |||
| 4018 | my $w = _parseNRf( $in, 's', 'sec' ); | ||
| 4019 | $w = 33e-9 if $w eq 'MIN'; | ||
| 4020 | $w = 10 if $w eq 'MAX'; | ||
| 4021 | if ( $w =~ /ERR/ ) { | ||
| 4022 | Lab::Exception::CorruptParameter->throw( | ||
| 4023 | "Invalid trigger width '$in'\n"); | ||
| 4024 | return; | ||
| 4025 | } | ||
| 4026 | $w = sprintf( '%.3e', $w ); | ||
| 4027 | $self->write("TRIG:MAI:PUL:WID:WID $w"); | ||
| 4028 | $self->_debug(); | ||
| 4029 | } | ||
| 4030 | |||
| 4031 | |||
| 4032 | sub get_trig_pulse_polarity { | ||
| 4033 | my $self = shift; | ||
| 4034 | my $r = $self->query("TRIG:MAI:PUL:WID:POL?"); | ||
| 4035 | $self->_debug(); | ||
| 4036 | $r = $self->_parseReply( $r, qw(POS NEG) ); | ||
| 4037 | return _bloat( $r, { POS => 'POSITIVE', NEG => 'NEGATIVE' } ); | ||
| 4038 | } | ||
| 4039 | |||
| 4040 | |||
| 4041 | sub set_trig_pulse_polarity { | ||
| 4042 | my $self = shift; | ||
| 4043 | my ($in) = $self->_check_args_strict( \@_, 'pulse_polarity' ); | ||
| 4044 | my $pol; | ||
| 4045 | |||
| 4046 | if ( $in =~ /^\s*(P|\+)/i ) { | ||
| 4047 | $pol = 'POSITIV'; | ||
| 4048 | } | ||
| 4049 | elsif ( $in =~ /^\s*(N|M|\-)/i ) { | ||
| 4050 | $pol = 'NEGA'; | ||
| 4051 | } | ||
| 4052 | else { | ||
| 4053 | Lab::Exception::CorruptParameter->throw( | ||
| 4054 | "Invalid trigger polarity '$in'\n"); | ||
| 4055 | return; | ||
| 4056 | } | ||
| 4057 | $self->write("TRIG:MAI:PUL:WID:POL $pol"); | ||
| 4058 | $self->_debug(); | ||
| 4059 | } | ||
| 4060 | |||
| 4061 | |||
| 4062 | sub get_trig_pulse_when { | ||
| 4063 | my $self = shift; | ||
| 4064 | my $r = $self->query("TRIG:MAI:PUL:WID:WHEN?"); | ||
| 4065 | $self->_debug(); | ||
| 4066 | $r = $self->_parseReply( $r, qw(EQ NOTE IN OUT) ); | ||
| 4067 | return _bloat( | ||
| 4068 | $r, { | ||
| 4069 | EQ => 'EQUAL', NOTE => 'NOTEQUAL', | ||
| 4070 | IN => 'INSIDE', OUT => 'OUTSIDE' | ||
| 4071 | } | ||
| 4072 | ); | ||
| 4073 | } | ||
| 4074 | |||
| 4075 | |||
| 4076 | sub set_trig_pulse_when { | ||
| 4077 | my $self = shift; | ||
| 4078 | my ($in) = $self->_check_args_strict( \@_, 'pulse_when' ); | ||
| 4079 | |||
| 4080 | my $w; | ||
| 4081 | if ( $in =~ /^\s*(EQ|=)/i ) { | ||
| 4082 | $w = 'EQ'; | ||
| 4083 | } | ||
| 4084 | elsif ( $in =~ /^\s*(NO|NE|!=|<>)/i ) { | ||
| 4085 | $w = 'NOTE'; | ||
| 4086 | } | ||
| 4087 | elsif ( $in =~ /^\s*(IN|LT|<)/i ) { | ||
| 4088 | $w = 'IN'; | ||
| 4089 | } | ||
| 4090 | elsif ( $in =~ /^\s*(OU|GT|>)/i ) { | ||
| 4091 | $w = 'OUT'; | ||
| 4092 | } | ||
| 4093 | else { | ||
| 4094 | Lab::Exception::CorruptParameter->throw( | ||
| 4095 | "Invalid trigger 'when' parameter '$in'\n"); | ||
| 4096 | return; | ||
| 4097 | } | ||
| 4098 | $self->write("TRIG:MAI:PUL:WID:WHEN $w"); | ||
| 4099 | $self->_debug(); | ||
| 4100 | } | ||
| 4101 | |||
| 4102 | |||
| 4103 | sub get_trig_vid_line { | ||
| 4104 | my $self = shift; | ||
| 4105 | my $r = $self->query("TRIG:MAI:VID:LINE?"); | ||
| 4106 | $self->_debug(); | ||
| 4107 | return $self->_parseReply($r); | ||
| 4108 | } | ||
| 4109 | |||
| 4110 | |||
| 4111 | sub set_trig_vid_line { | ||
| 4112 | my $self = shift; | ||
| 4113 | my ($in) = $self->_check_args_strict( \@_, 'vid_line' ); | ||
| 4114 | |||
| 4115 | $in = 1 if $in eq 'MIN'; | ||
| 4116 | if ( $in eq 'MAX' ) { | ||
| 4117 | my $std = $self->get_trig_vid_standard(); | ||
| 4118 | $in = 525; | ||
| 4119 | $in = 625 if $std eq 'PAL'; | ||
| 4120 | } | ||
| 4121 | $in = int($in) if $in =~ /^\s*\d+/; | ||
| 4122 | |||
| 4123 | if ( $in =~ /ERR/ || $in < 1 || $in > 625 ) { | ||
| 4124 | Lab::Exception::CorruptParameter->throw( | ||
| 4125 | "Invalid video trigger line '$in'\n"); | ||
| 4126 | return; | ||
| 4127 | } | ||
| 4128 | |||
| 4129 | $self->write("TRIG:MAI:VID:LINE $in"); | ||
| 4130 | $self->_debug(); | ||
| 4131 | } | ||
| 4132 | |||
| 4133 | |||
| 4134 | sub get_trig_vid_polarity { | ||
| 4135 | my $self = shift; | ||
| 4136 | my $r = $self->query("TRIG:MAI:VID:POL?"); | ||
| 4137 | $self->_debug(); | ||
| 4138 | $r = $self->_parseReply( $r, qw(NORM INV) ); | ||
| 4139 | return _bloat( $r, { NORM => 'NORMAL', INV => 'INVERTED' } ); | ||
| 4140 | } | ||
| 4141 | |||
| 4142 | |||
| 4143 | sub set_trig_vid_polarity { | ||
| 4144 | my $self = shift; | ||
| 4145 | my ($in) = $self->_check_args_strict( \@_, 'vid_polarity' ); | ||
| 4146 | |||
| 4147 | my $p; | ||
| 4148 | if ( $in =~ /^\s*(N|\-)/i ) { | ||
| 4149 | $p = 'NORM'; | ||
| 4150 | } | ||
| 4151 | elsif ( $in =~ /^\s*(I|\+)/i ) { | ||
| 4152 | $p = 'INV'; | ||
| 4153 | } | ||
| 4154 | else { | ||
| 4155 | Lab::Exception::CorruptParameter->throw( | ||
| 4156 | "Invalid video trigger polarity '$in'\n"); | ||
| 4157 | return; | ||
| 4158 | } | ||
| 4159 | $self->write("TRIG:MAI:VID:POL $p"); | ||
| 4160 | $self->_debug(); | ||
| 4161 | } | ||
| 4162 | |||
| 4163 | |||
| 4164 | sub get_trig_vid_standard { | ||
| 4165 | my $self = shift; | ||
| 4166 | my $r = $self->query("TRIG:MAI:VID:STAND?"); | ||
| 4167 | $self->_debug(); | ||
| 4168 | $r = $self->_parseReply( $r, qw(NTS PAL) ); | ||
| 4169 | $r = 'NTSC' if $r eq 'NTS'; | ||
| 4170 | return $r; | ||
| 4171 | } | ||
| 4172 | |||
| 4173 | |||
| 4174 | sub set_trig_vid_standard { | ||
| 4175 | my $self = shift; | ||
| 4176 | my ($in) = $self->_check_args_strict( \@_, 'vid_standard' ); | ||
| 4177 | |||
| 4178 | my $s; | ||
| 4179 | if ( $in =~ /^\s*(NTS|US|JP)/i ) { | ||
| 4180 | $s = 'NTS'; | ||
| 4181 | } | ||
| 4182 | elsif ( $in =~ /^\s*(PAL|EU|UK|AU|SEC)/i ) { | ||
| 4183 | $s = 'PAL'; | ||
| 4184 | } | ||
| 4185 | else { | ||
| 4186 | Lab::Exception::CorruptParameter->throw( | ||
| 4187 | "Invalid video trigger standard '$in'\n"); | ||
| 4188 | return; | ||
| 4189 | } | ||
| 4190 | $self->write("TRIG:MAI:VID:STAND $s"); | ||
| 4191 | $self->_debug(); | ||
| 4192 | } | ||
| 4193 | |||
| 4194 | |||
| 4195 | sub get_trig_vid_sync { | ||
| 4196 | my $self = shift; | ||
| 4197 | my $r = $self->query("TRIG:MAI:VID:SYNC?"); | ||
| 4198 | $self->_debug(); | ||
| 4199 | $r = $self->_parseReply( $r, qw(FIELD LINE ODD EVEN LINEN) ); | ||
| 4200 | $r = 'LINENUM' if $r eq 'LINEN'; | ||
| 4201 | return $r; | ||
| 4202 | } | ||
| 4203 | |||
| 4204 | |||
| 4205 | sub set_trig_vid_sync { | ||
| 4206 | my $self = shift; | ||
| 4207 | my ($in) = $self->_check_args_strict( \@_, 'vid_sync' ); | ||
| 4208 | |||
| 4209 | my $s = _keyword( $in, qw(FIELD LINE ODD EVEN LINEN) ); | ||
| 4210 | $self->write("TRIG:MAI:VID:SYNC $s"); | ||
| 4211 | $self->_debug(); | ||
| 4212 | } | ||
| 4213 | |||
| 4214 | |||
| 4215 | sub get_trig_state { | ||
| 4216 | my $self = shift; | ||
| 4217 | my $r = $self->query("TRIG:STATE?"); | ||
| 4218 | $self->_debug(); | ||
| 4219 | $r = $self->_parseReply($r); | ||
| 4220 | } | ||
| 4221 | |||
| 4222 | |||
| 4223 | sub get_data_width { | ||
| 4224 | my $self = shift; | ||
| 4225 | my $r = $self->query("DAT:WID?"); | ||
| 4226 | $self->_debug(); | ||
| 4227 | return $self->_parseReply($r); | ||
| 4228 | } | ||
| 4229 | |||
| 4230 | |||
| 4231 | sub set_data_width { | ||
| 4232 | my $self = shift; | ||
| 4233 | my ($in) = $self->_check_args_strict( \@_, 'nbytes' ); | ||
| 4234 | my $n; | ||
| 4235 | |||
| 4236 | if ( $in =~ /^\s*1\s*$/ ) { | ||
| 4237 | $n = 1; | ||
| 4238 | } | ||
| 4239 | elsif ( $in =~ /^\s*2\s*$/ ) { | ||
| 4240 | $n = 2; | ||
| 4241 | } | ||
| 4242 | else { | ||
| 4243 | Lab::Exception::CorruptParameter->throw( | ||
| 4244 | "Invalid bytes/sample '$in' should be 1, 2\n"); | ||
| 4245 | return; | ||
| 4246 | } | ||
| 4247 | $self->write("DAT:WID $n"); | ||
| 4248 | $self->_debug(); | ||
| 4249 | } | ||
| 4250 | |||
| 4251 | |||
| 4252 | sub get_data_encoding { | ||
| 4253 | my $self = shift; | ||
| 4254 | my $r = $self->query("DAT:ENC?"); | ||
| 4255 | $self->_debug(); | ||
| 4256 | $r = $self->_parseReply( $r, qw(ASCI RIB RPB SRI SRP) ); | ||
| 4257 | return _bloat( | ||
| 4258 | $r, { | ||
| 4259 | ASCI => 'ASCII', RIB => 'RIBINARY', RPB => 'RPBINARY', | ||
| 4260 | SRI => 'SRIBINARY', SRP => 'SRPBINARY' | ||
| 4261 | } | ||
| 4262 | ); | ||
| 4263 | } | ||
| 4264 | |||
| 4265 | |||
| 4266 | sub set_data_encoding { | ||
| 4267 | my $self = shift; | ||
| 4268 | my ($in) = $self->_check_args_strict( \@_, 'encoding' ); | ||
| 4269 | my $e = _keyword( $in, qw(ASC RI RP SRI SRP) ); | ||
| 4270 | $e = _bloat( $e, { ASC => 'ASCI', RI => 'RIB', RP => 'RPB' } ); | ||
| 4271 | $self->write("DAT:ENC $e"); | ||
| 4272 | $self->_debug(); | ||
| 4273 | } | ||
| 4274 | |||
| 4275 | |||
| 4276 | sub get_data_start { | ||
| 4277 | my $self = shift; | ||
| 4278 | my $r = $self->query("DAT:STAR?"); | ||
| 4279 | $self->_debug(); | ||
| 4280 | return $self->_parseReply($r); | ||
| 4281 | } | ||
| 4282 | |||
| 4283 | |||
| 4284 | sub set_data_start { | ||
| 4285 | my $self = shift; | ||
| 4286 | my ($in) = $self->_check_args_strict( \@_, 'start' ); | ||
| 4287 | |||
| 4288 | $in = 1 if $in =~ /^\s*MIN/i; | ||
| 4289 | $in = 2500 - 1 if $in =~ /^\s*MAX/i; | ||
| 4290 | |||
| 4291 | if ( $in !~ /^\s*(\d+)\s*$/ ) { | ||
| 4292 | Lab::Exception::CorruptParameter->throw( | ||
| 4293 | "Invalid waveform start sample# '$in'; should be 1..2500\n"); | ||
| 4294 | return; | ||
| 4295 | } | ||
| 4296 | my $i = $in; | ||
| 4297 | if ( $i < 1 || $i >= 2500 ) { | ||
| 4298 | Lab::Exception::CorruptParameter->throw( | ||
| 4299 | "Invalid waveform start sample# '$in'; should be 1..2500\n"); | ||
| 4300 | return; | ||
| 4301 | } | ||
| 4302 | |||
| 4303 | $self->write("DAT:STAR $i"); | ||
| 4304 | $self->_debug(); | ||
| 4305 | } | ||
| 4306 | |||
| 4307 | |||
| 4308 | sub get_data_stop { | ||
| 4309 | my $self = shift; | ||
| 4310 | my $r = $self->query("DAT:STOP?"); | ||
| 4311 | $self->_debug(); | ||
| 4312 | return $self->_parseReply($r); | ||
| 4313 | } | ||
| 4314 | |||
| 4315 | |||
| 4316 | sub set_data_stop { | ||
| 4317 | my $self = shift; | ||
| 4318 | my ($in) = $self->_check_args_strict( \@_, 'stop' ); | ||
| 4319 | |||
| 4320 | $in = 2 if $in =~ /^\s*MIN/i; | ||
| 4321 | $in = 2500 if $in =~ /^\s*MAX/i; | ||
| 4322 | |||
| 4323 | if ( $in !~ /^\s*(\d+)\s*$/ ) { | ||
| 4324 | Lab::Exception::CorruptParameter->throw( | ||
| 4325 | "Invalid waveform stop sample# '$in'; should be 1..2500\n"); | ||
| 4326 | return; | ||
| 4327 | } | ||
| 4328 | my $i = $in; | ||
| 4329 | if ( $i < 2 || $i > 2500 ) { | ||
| 4330 | Lab::Exception::CorruptParameter->throw( | ||
| 4331 | "Invalid waveform stop sample# '$in'; should be 1..2500\n"); | ||
| 4332 | return; | ||
| 4333 | } | ||
| 4334 | |||
| 4335 | $self->write("DAT:STOP $i"); | ||
| 4336 | $self->_debug(); | ||
| 4337 | } | ||
| 4338 | |||
| 4339 | |||
| 4340 | sub get_data_destination { | ||
| 4341 | my $self = shift; | ||
| 4342 | my $r = $self->query("DAT:DEST?"); | ||
| 4343 | $self->_debug(); | ||
| 4344 | return $self->_parseReply($r); | ||
| 4345 | } | ||
| 4346 | |||
| 4347 | |||
| 4348 | sub set_data_destination { | ||
| 4349 | my $self = shift; | ||
| 4350 | my ($in) = $self->_check_args_strict( \@_, 'destination' ); | ||
| 4351 | |||
| 4352 | my $d; | ||
| 4353 | if ( $in =~ /^\s*(REF)?([A-D])\s*$/i ) { | ||
| 4354 | $d = "REF" . uc($2); | ||
| 4355 | } | ||
| 4356 | else { | ||
| 4357 | Lab::Exception::CorruptParameter->throw( | ||
| 4358 | "Invalid waveform destination '$in'; should be REFA..REFD\n"); | ||
| 4359 | return; | ||
| 4360 | } | ||
| 4361 | $self->write("DAT:DEST $d"); | ||
| 4362 | $self->_debug(); | ||
| 4363 | } | ||
| 4364 | |||
| 4365 | |||
| 4366 | sub set_data_init { | ||
| 4367 | my $self = shift; | ||
| 4368 | $self->write("DAT INIT"); | ||
| 4369 | $self->_debug(); | ||
| 4370 | } | ||
| 4371 | |||
| 4372 | |||
| 4373 | sub get_data_source { | ||
| 4374 | my $self = shift; | ||
| 4375 | my $r = $self->query("DAT:SOU?"); | ||
| 4376 | $self->_debug(); | ||
| 4377 | return $self->_parseReply($r); | ||
| 4378 | } | ||
| 4379 | |||
| 4380 | |||
| 4381 | sub set_data_source { | ||
| 4382 | my $self = shift; | ||
| 4383 | my ($in) = $self->_check_args_strict( \@_, 'source' ); | ||
| 4384 | |||
| 4385 | my $s; | ||
| 4386 | |||
| 4387 | if ( $in =~ /^\s*(CH)?([1-4])\s*$/i ) { | ||
| 4388 | $s = "CH$2"; | ||
| 4389 | } | ||
| 4390 | elsif ( $in =~ /^\s*MATH\s*$/i ) { | ||
| 4391 | $s = 'MATH'; | ||
| 4392 | } | ||
| 4393 | elsif ( $in =~ /^\s*(REF)?([A-D])\s*$/i ) { | ||
| 4394 | $s = "REF" . uc($2); | ||
| 4395 | } | ||
| 4396 | else { | ||
| 4397 | Lab::Exception::CorruptParameter->throw("Invalid waveform '$in'"); | ||
| 4398 | return; | ||
| 4399 | } | ||
| 4400 | $self->write("DAT:SOU $s"); | ||
| 4401 | $self->_debug(); | ||
| 4402 | } | ||
| 4403 | |||
| 4404 | |||
| 4405 | sub get_data { | ||
| 4406 | my $self = shift; | ||
| 4407 | my ($tail) = $self->_check_args( \@_ ); | ||
| 4408 | my $h = {}; | ||
| 4409 | |||
| 4410 | $h->{width} = $self->get_data_width($tail); | ||
| 4411 | $h->{stop} = $self->get_data_stop($tail); | ||
| 4412 | $h->{start} = $self->get_data_start($tail); | ||
| 4413 | $h->{encoding} = $self->get_data_encoding($tail); | ||
| 4414 | $h->{source} = $self->get_data_source($tail); | ||
| 4415 | $h->{destination} = $self->get_data_destination($tail); | ||
| 4416 | return $h; | ||
| 4417 | } | ||
| 4418 | |||
| 4419 | |||
| 4420 | sub set_data { | ||
| 4421 | my $self = shift; | ||
| 4422 | my ($tail) = $self->_check_args( \@_ ); | ||
| 4423 | |||
| 4424 | $self->set_data_width($tail) if exists $tail->{width}; | ||
| 4425 | $self->set_data_start($tail) if exists $tail->{start}; | ||
| 4426 | $self->set_data_stop($tail) if exists $tail->{stop}; | ||
| 4427 | $self->set_data_encoding($tail) if exists $tail->{encoding}; | ||
| 4428 | $self->set_data_source($tail) if exists $tail->{source}; | ||
| 4429 | $self->set_data_destinatin($tail) if exists $tail->{destination}; | ||
| 4430 | } | ||
| 4431 | |||
| 4432 | |||
| 4433 | sub get_waveform { | ||
| 4434 | my $self = shift; | ||
| 4435 | my ( $in, $tail ) = $self->_check_args( \@_, 'waveform' ); | ||
| 4436 | my $args = clone($tail); | ||
| 4437 | delete( $args->{destination} ) if exists $args->{destination}; | ||
| 4438 | delete( $args->{source} ) if exists $args->{source}; | ||
| 4439 | |||
| 4440 | if ( !$self->get_visible($in) ) { | ||
| 4441 | Lab::Exception::CorruptParameter->throw("Waveform '$in' not visible"); | ||
| 4442 | return; | ||
| 4443 | } | ||
| 4444 | |||
| 4445 | $args->{source} = $in if defined $in; | ||
| 4446 | my $dstop; | ||
| 4447 | if ( $in =~ /^\s*MATH/i ) { | ||
| 4448 | $dstop = $self->get_data_stop(); | ||
| 4449 | if ( $dstop > 1024 ) { | ||
| 4450 | $self->set_data_stop(1024); | ||
| 4451 | } | ||
| 4452 | else { | ||
| 4453 | $dstop = undef; | ||
| 4454 | } | ||
| 4455 | } | ||
| 4456 | |||
| 4457 | $self->set_data($args); | ||
| 4458 | |||
| 4459 | my $header = $self->get_header(); | ||
| 4460 | $self->set_header(1); | ||
| 4461 | my $dath = $self->query("DAT?"); | ||
| 4462 | $self->_debug(); | ||
| 4463 | |||
| 4464 | |||
| 4465 | my $wfpre = $self->query( "WFMP?", read_length => 2000, timeout => 10 ); | ||
| 4466 | $self->_debug(); | ||
| 4467 | |||
| 4468 | my $wf = $self->query("CURV?", read_length => -1, timeout => 60); | ||
| 4469 | $self->_debug(); | ||
| 4470 | |||
| 4471 | $self->set_header($header); | ||
| 4472 | |||
| 4473 | # $self->set_data_stop($dstop) if defined $dstop; | ||
| 4474 | |||
| 4475 | my $hd = scpi_parse($dath); | ||
| 4476 | my $hp = scpi_parse($wfpre,$hd); | ||
| 4477 | my $h = scpi_flat( scpi_parse( $wf, $hp ), $self->{scpi_override} ); | ||
| 4478 | |||
| 4479 | my (@dat); | ||
| 4480 | if ( $h->{'DAT:ENC'} =~ /^ASC/i ) { | ||
| 4481 | @dat = split( /,/, $h->{CURV} ); | ||
| 4482 | } | ||
| 4483 | else { | ||
| 4484 | if ( substr( $h->{CURV}, 0, 2 ) !~ /^#\d/ ) { | ||
| 4485 | croak("bad binary curve data"); | ||
| 4486 | } | ||
| 4487 | my $nx = substr( $h->{CURV}, 1, 1 ); | ||
| 4488 | my $n = substr( $h->{CURV}, 2, $nx ); | ||
| 4489 | my $w = $h->{'WFMP:BYT_N'}; | ||
| 4490 | my $f = $h->{'WFMP:BN_F'}; | ||
| 4491 | my $xsb = $h->{'WFMP:BYT_O'}; | ||
| 4492 | |||
| 4493 | my $form; | ||
| 4494 | if ( $w == 1 ) { | ||
| 4495 | if ( $f eq 'RP' ) { | ||
| 4496 | $form = 'C'; | ||
| 4497 | } | ||
| 4498 | else { | ||
| 4499 | $form = 'c'; | ||
| 4500 | } | ||
| 4501 | } | ||
| 4502 | else { | ||
| 4503 | if ( $f eq 'RP' ) { | ||
| 4504 | $form = 'S'; | ||
| 4505 | } | ||
| 4506 | else { | ||
| 4507 | $form = 's'; | ||
| 4508 | } | ||
| 4509 | if ( $xsb eq 'MSB' ) { | ||
| 4510 | $form .= '>'; | ||
| 4511 | } | ||
| 4512 | else { | ||
| 4513 | $form .= '<'; | ||
| 4514 | } | ||
| 4515 | } | ||
| 4516 | $form .= '*'; | ||
| 4517 | @dat = unpack( $form, substr( $h->{CURV}, $nx + 2 ) ); | ||
| 4518 | } | ||
| 4519 | |||
| 4520 | $h->{t} = []; | ||
| 4521 | my $j = 0; | ||
| 4522 | my $j0 = $h->{'DAT:STAR'}; | ||
| 4523 | my $x0 = $h->{'WFMP:XZE'}; | ||
| 4524 | my $dx = $h->{'WFMP:XIN'}; | ||
| 4525 | my $xoff = $h->{'WFMP:PT_O'}; | ||
| 4526 | my $y0 = $h->{'WFMP:YZE'}; | ||
| 4527 | my $yoff = $h->{'WFMP:YOF'}; | ||
| 4528 | my $dy = $h->{'WFMP:YMU'}; | ||
| 4529 | |||
| 4530 | $h->{'WFMP:XUN'} = _unquote( $h->{'WFMP:XUN'} ); | ||
| 4531 | $h->{'WFMP:YUN'} = _unquote( $h->{'WFMP:YUN'} ); | ||
| 4532 | $h->{'WFMP:WFI'} = _unquote( $h->{'WFMP:WFI'} ); | ||
| 4533 | |||
| 4534 | if ( $h->{'WFMP:PT_F'} eq 'Y' ) { | ||
| 4535 | $h->{v} = []; | ||
| 4536 | for ( $j = 0; $j <= $#dat; $j++ ) { | ||
| 4537 | $h->{t}->[ $j0 + $j ] = $x0 + $dx * ( $j - $xoff ); | ||
| 4538 | $h->{v}->[ $j0 + $j ] = $y0 + $dy * ( $dat[$j] - $yoff ); | ||
| 4539 | } | ||
| 4540 | $h->{'DAT:STOP'} = $j0 + $#dat; | ||
| 4541 | } | ||
| 4542 | else { # envelope | ||
| 4543 | $h->{vmin} = []; | ||
| 4544 | $h->{vmax} = []; | ||
| 4545 | for ( $j = 0; $j <= $#dat; $j += 2 ) { | ||
| 4546 | $h->{t}->[ $j0 + $j / 2 ] = $x0 + $dx * ( $j + 1 - $xoff ); | ||
| 4547 | $h->{vmin}->[ $j0 + $j / 2 ] | ||
| 4548 | = $y0 + $dy * ( $dat[$j] - $yoff ); | ||
| 4549 | $h->{vmax}->[ $j0 + $j / 2 ] | ||
| 4550 | = $y0 + $dy * ( $dat[ $j + 1 ] - $yoff ); | ||
| 4551 | } | ||
| 4552 | $h->{'DAT:STOP'} = $j0 + $#dat / 2; | ||
| 4553 | } | ||
| 4554 | |||
| 4555 | return $h; | ||
| 4556 | } | ||
| 4557 | |||
| 4558 | # remove scpi style quoting | ||
| 4559 | sub _unquote { | ||
| 4560 | my $str = shift; | ||
| 4561 | return '' unless defined($str); | ||
| 4562 | return $str unless $str =~ /^(\'|\")/; | ||
| 4563 | if ( $str =~ /^\'(.*)\'$/ ) { | ||
| 4564 | $str = $1; | ||
| 4565 | $str =~ s/\'\'/'/g; | ||
| 4566 | } | ||
| 4567 | elsif ( $str =~ /^\"(.*)\"$/ ) { | ||
| 4568 | $str = $1; | ||
| 4569 | $str =~ s/\"\"/"/g; | ||
| 4570 | } | ||
| 4571 | return $str; | ||
| 4572 | } | ||
| 4573 | |||
| 4574 | |||
| 4575 | sub create_waveform { | ||
| 4576 | my $self = shift; | ||
| 4577 | my ( $it0, $it1, $n, $vfunc, $tail ) | ||
| 4578 | = $self->_check_args( \@_, qw(tstart tstop nbins vfunc) ); | ||
| 4579 | |||
| 4580 | $n = 2500 if !defined($n); | ||
| 4581 | $n = int($n); | ||
| 4582 | $n = 2500 if $n <= 0; | ||
| 4583 | |||
| 4584 | my ( $t0, $t1 ); | ||
| 4585 | |||
| 4586 | if ( defined($it0) xor defined($it1) ) { | ||
| 4587 | Lab::Exception::CorruptParameter->throw( | ||
| 4588 | "Should define BOTH t0 and t1, or neither"); | ||
| 4589 | return; | ||
| 4590 | } | ||
| 4591 | |||
| 4592 | if ( defined($it0) ) { | ||
| 4593 | $t0 = _parseNRf( $it0, 's', 'sec' ); | ||
| 4594 | if ( $t0 =~ /(MIN|MAX|ERR)/i ) { | ||
| 4595 | Lab::Exception::CorruptParameter->throw("Invalid time '$it0'"); | ||
| 4596 | return; | ||
| 4597 | } | ||
| 4598 | } | ||
| 4599 | |||
| 4600 | if ( defined($it1) ) { | ||
| 4601 | $t1 = _parseNRf( $it1, 's', 'sec' ); | ||
| 4602 | if ( $t1 =~ /(MIN|MAX|ERR)/i ) { | ||
| 4603 | Lab::Exception::CorruptParameter->throw("Invalid time '$it1'"); | ||
| 4604 | return; | ||
| 4605 | } | ||
| 4606 | } | ||
| 4607 | |||
| 4608 | my $hwfd = {}; | ||
| 4609 | $hwfd->{t} = []; | ||
| 4610 | my $t = $hwfd->{t}; | ||
| 4611 | |||
| 4612 | $hwfd->{'DAT:STAR'} = 1; | ||
| 4613 | $hwfd->{'DAT:STOP'} = $n; | ||
| 4614 | if ( defined($t0) ) { | ||
| 4615 | $hwfd->{'WFMP:XZE'} = sprintf( '%.4e', $t0 ); | ||
| 4616 | my $dt = ( $t1 - $t0 ); | ||
| 4617 | $dt = $dt / ( $n - 1 ) if $n > 1; | ||
| 4618 | $hwfd->{'WFMP:XIN'} = sprintf( '%.4e', $dt ); | ||
| 4619 | |||
| 4620 | for ( my $j = 1; $j <= $n; $j++ ) { | ||
| 4621 | $t->[$j] = $t0 + ( $j - 1 ) * $dt; | ||
| 4622 | } | ||
| 4623 | |||
| 4624 | } | ||
| 4625 | if ( !defined($t0) ) { | ||
| 4626 | for ( my $j = 1; $j <= $n; $j++ ) { | ||
| 4627 | $t->[$j] = undef; | ||
| 4628 | } | ||
| 4629 | } | ||
| 4630 | |||
| 4631 | $hwfd->{'WFMP:PT_F'} = 'Y'; | ||
| 4632 | |||
| 4633 | if ( defined($vfunc) ) { | ||
| 4634 | if ( ref($vfunc) ne 'CODE' ) { | ||
| 4635 | Lab::Exception::CorruptParameter->throw( | ||
| 4636 | "not a pointer to routine for filling voltages"); | ||
| 4637 | return; | ||
| 4638 | } | ||
| 4639 | if ( !defined($t0) ) { | ||
| 4640 | Lab::Exception::CorruptParameter->throw( | ||
| 4641 | "cannot fill voltages without t0, t1 defined"); | ||
| 4642 | return; | ||
| 4643 | } | ||
| 4644 | |||
| 4645 | my ( $v0, $v1, $vmin, $vmax ); | ||
| 4646 | |||
| 4647 | for ( my $j = 1; $j <= $n; $j++ ) { | ||
| 4648 | ( $v0, $v1 ) = &{$vfunc}( $t->[$j] ); # call user function | ||
| 4649 | if ( defined($v1) ) { # two values: doing envelope waveform | ||
| 4650 | if ( $v1 < $v0 ) { # v1 > v0, swap if needed | ||
| 4651 | my $vt = $v1; | ||
| 4652 | $v1 = $v0; | ||
| 4653 | $v0 = $vt; | ||
| 4654 | } | ||
| 4655 | $hwfd->{'WFMP:PT_F'} = 'ENV'; | ||
| 4656 | $hwfd->{vmin} = [] unless exists $hwfd->{vmin}; | ||
| 4657 | $hwfd->{vmax} = [] unless exists $hwfd->{vmax}; | ||
| 4658 | $hwfd->{vmin}->[$j] = $v0; | ||
| 4659 | $hwfd->{vmax}->[$j] = $v1; | ||
| 4660 | if ( exists( $hwfd->{v} ) ) { | ||
| 4661 | Lab::Exception::CorruptParameter->throw( | ||
| 4662 | "Invalid mix of v; vmin,vmax"); | ||
| 4663 | return; | ||
| 4664 | } | ||
| 4665 | $n = 1250 if $n > 1250; # envelope has fewer max bins | ||
| 4666 | } | ||
| 4667 | else { | ||
| 4668 | $hwfd->{v} = [] unless exists $hwfd->{v}; | ||
| 4669 | $hwfd->{v}->[$j] = $v0; | ||
| 4670 | if ( exists( $hwfd->{vmin} ) ) { | ||
| 4671 | Lab::Exception::CorruptParameter->throw( | ||
| 4672 | "Invalid mix of v; vmin,vmax"); | ||
| 4673 | return; | ||
| 4674 | } | ||
| 4675 | $v1 = $v0; # need this for the max/min | ||
| 4676 | } | ||
| 4677 | |||
| 4678 | $vmin = $v0 unless defined $vmin && $vmin < $v0; | ||
| 4679 | $vmax = $v1 unless defined $vmax && $vmax > $v1; | ||
| 4680 | } | ||
| 4681 | } | ||
| 4682 | return $hwfd; | ||
| 4683 | } | ||
| 4684 | |||
| 4685 | |||
| 4686 | sub put_waveform { | ||
| 4687 | my $self = shift; | ||
| 4688 | my ( $hwfm, $tail ) = $self->_check_args_strict( \@_, ['waveform'] ); | ||
| 4689 | |||
| 4690 | # extra 'data' call parameters should override info in waveform, but | ||
| 4691 | # tricky to get it right...ignore call parameters for now | ||
| 4692 | # my $args = clone($tail); | ||
| 4693 | # delete($args->{source}) if exists $args->{source}; | ||
| 4694 | # $self->set_data($args); | ||
| 4695 | |||
| 4696 | my $ypos; | ||
| 4697 | my $ysca; | ||
| 4698 | |||
| 4699 | if ( exists( $tail->{position} ) ) { | ||
| 4700 | $ypos = _parseNRf( $tail->{position}, 'div', 'division' ); | ||
| 4701 | $ypos = 5 if $ypos eq 'MAX'; | ||
| 4702 | $ypos = -5 if $ypos eq 'MIN'; | ||
| 4703 | if ( $ypos eq 'ERR' || $ypos > 5 || $ypos < -5 ) { | ||
| 4704 | Lab::Exception::CorruptParameter->throw( | ||
| 4705 | "Invalid position '$tail->{position}'"); | ||
| 4706 | return; | ||
| 4707 | } | ||
| 4708 | } | ||
| 4709 | if ( exists( $tail->{scale} ) ) { | ||
| 4710 | $ysca = _parseNRf( $tail->{scale}, 'V/div' ); | ||
| 4711 | $ysca = 1e-3 if $ysca eq 'MIN'; | ||
| 4712 | $ysca = 10 if $ysca eq 'MAX'; | ||
| 4713 | if ( $ysca eq 'ERR' || $ysca < 1e-3 || $ysca > 10 ) { | ||
| 4714 | Lab::Exception::CorruptParameter->throw( | ||
| 4715 | "Invalid scale '$tail->{scale}'"); | ||
| 4716 | return; | ||
| 4717 | } | ||
| 4718 | } | ||
| 4719 | |||
| 4720 | my $fmt; | ||
| 4721 | $fmt = $tail->{encoding} if exists $tail->{encoding}; | ||
| 4722 | $fmt = $hwfm->{'DAT:ENC'} | ||
| 4723 | if !defined($fmt) && exists( $hwfm->{'DAT:ENC'} ); | ||
| 4724 | $fmt = $self->get_data_encoding() if !defined($fmt); | ||
| 4725 | $fmt = _keyword( $fmt, qw(ASC RI RP SRI SRP) ); | ||
| 4726 | $fmt = _bloat( $fmt, { ASC => 'ASCI', RI => 'RIB', RP => 'RPB' } ); | ||
| 4727 | $hwfm->{'DAT:ENC'} = $fmt; | ||
| 4728 | |||
| 4729 | my $wd; | ||
| 4730 | $wd = $tail->{data_width} if exists $tail->{data_width}; | ||
| 4731 | $wd = $hwfm->{'DAT:WID'} if !defined($wd) && exists $hwfm->{'DAT:WID'}; | ||
| 4732 | $wd = $self->get_data_width() if !defined($wd); | ||
| 4733 | $wd = int( 0.5 + $wd ); | ||
| 4734 | if ( $wd < 1 || $wd > 2 ) { | ||
| 4735 | Lab::Exception::CorruptParameter->throw("Invalid data width '$wd'"); | ||
| 4736 | return; | ||
| 4737 | } | ||
| 4738 | $hwfm->{'DAT:WID'} = $wd; | ||
| 4739 | |||
| 4740 | my ( $datamin, $datamax ); | ||
| 4741 | if ( $wd == 1 ) { | ||
| 4742 | if ( $fmt =~ /RP/ ) { | ||
| 4743 | $datamin = 0x00; | ||
| 4744 | $datamax = 0xff; | ||
| 4745 | } | ||
| 4746 | else { | ||
| 4747 | $datamin = -128; | ||
| 4748 | $datamax = 127; | ||
| 4749 | } | ||
| 4750 | } | ||
| 4751 | else { | ||
| 4752 | if ( $fmt =~ /RP/ ) { | ||
| 4753 | $datamin = 0x0000; | ||
| 4754 | $datamax = 0xffff; | ||
| 4755 | } | ||
| 4756 | else { | ||
| 4757 | $datamin = -32768; | ||
| 4758 | $datamax = 32767; | ||
| 4759 | } | ||
| 4760 | } | ||
| 4761 | |||
| 4762 | if ( defined($ypos) || defined($ysca) ) { | ||
| 4763 | my $ycenter = 0; # okay for signed integer binary and ascii | ||
| 4764 | my $ymul; | ||
| 4765 | if ( $wd == 1 ) { | ||
| 4766 | $ycenter = 127 if $fmt =~ /^\s*S?RP/i; | ||
| 4767 | $ymul = 25; | ||
| 4768 | } | ||
| 4769 | else { | ||
| 4770 | $ycenter = 32767 if $fmt =~ /^\s*S?RP/i; | ||
| 4771 | $ymul = 6554; | ||
| 4772 | } | ||
| 4773 | |||
| 4774 | if ( defined($ypos) ) { | ||
| 4775 | $hwfm->{'WFMP:YZE'} = 0; | ||
| 4776 | $hwfm->{'WFMP:YOF'} = int( $ycenter + $ypos * $ymul ); | ||
| 4777 | } | ||
| 4778 | |||
| 4779 | if ( defined($ysca) ) { | ||
| 4780 | $hwfm->{'WFMP:YMU'} = sprintf( '%.3e', $ysca / $ymul ); | ||
| 4781 | } | ||
| 4782 | } | ||
| 4783 | |||
| 4784 | my $rawdata; | ||
| 4785 | |||
| 4786 | my ( $xmin, $xmax, $ymin, $ymax, $jmin, $jmax ); | ||
| 4787 | my $ptf = 'Y'; | ||
| 4788 | $ptf = $hwfm->{'WFMP:PT_F'} if exists $hwfm->{'WFMP:PT_F'}; | ||
| 4789 | |||
| 4790 | my $jlim = 2500; | ||
| 4791 | $jlim = 1250 if $ptf ne 'Y'; # envelope, fewer bins | ||
| 4792 | |||
| 4793 | my ( $jstart, $jstop ); | ||
| 4794 | |||
| 4795 | if ( exists( $tail->{start} ) ) { | ||
| 4796 | $jstart = _parseNRf( $tail->{start} ); | ||
| 4797 | $jstart = 1 if $jstart eq 'MIN'; | ||
| 4798 | $jstart = $jlim - 1 if $jstart eq 'MAX'; | ||
| 4799 | if ( $jstart eq 'ERR' || $jstart < 1 || $jstart >= $jlim ) { | ||
| 4800 | Lab::Exception::CorruptParameter->throw( | ||
| 4801 | "Invalid start point '$tail->{start}'"); | ||
| 4802 | return; | ||
| 4803 | } | ||
| 4804 | } | ||
| 4805 | else { | ||
| 4806 | $jstart = $hwfm->{'DAT:STAR'} if exists $hwfm->{'DAT:STAR'}; | ||
| 4807 | $jstart = 1 unless defined $jstart; | ||
| 4808 | } | ||
| 4809 | |||
| 4810 | if ( exists( $tail->{stop} ) ) { | ||
| 4811 | $jstop = _parseNRf( $tail->{stop} ); | ||
| 4812 | $jstop = 2 if $jstop eq 'MIN'; | ||
| 4813 | $jstop = $jlim if $jstop eq 'MAX'; | ||
| 4814 | if ( $jstop eq 'ERR' || $jstop < 2 || $jstop > $jlim ) { | ||
| 4815 | Lab::Exception::CorruptParameter->throw( | ||
| 4816 | "Invalid stop point '$tail->{stop}'"); | ||
| 4817 | return; | ||
| 4818 | } | ||
| 4819 | } | ||
| 4820 | else { | ||
| 4821 | $jstop = $hwfm->{'DAT:STOP'} if exists $hwfm->{'DAT:STOP'}; | ||
| 4822 | $jstop = $jlim unless defined $jstop; | ||
| 4823 | } | ||
| 4824 | |||
| 4825 | for ( my $j = 1; $j <= $jlim; $j++ ) { | ||
| 4826 | last if defined($jmin) && !defined( $hwfm->{t}->[$j] ); | ||
| 4827 | next unless defined( $hwfm->{t}->[$j] ); | ||
| 4828 | $jmin = $j unless defined $jmin && $jmin < $j; | ||
| 4829 | $jmax = $j unless defined $jmax && $jmax > $j; | ||
| 4830 | my $x = $hwfm->{t}->[$j]; | ||
| 4831 | $xmin = $x unless defined $xmin && $xmin < $x; | ||
| 4832 | $xmax = $x unless defined $xmax && $xmax > $x; | ||
| 4833 | |||
| 4834 | if ( $ptf eq 'Y' ) { | ||
| 4835 | my $y = $hwfm->{v}->[$j] || 0; | ||
| 4836 | $ymin = $y unless defined $ymin && $ymin < $y; | ||
| 4837 | $ymax = $y unless defined $ymax && $ymax > $y; | ||
| 4838 | } | ||
| 4839 | else { | ||
| 4840 | my $y0 = $hwfm->{vmin}->[$j] || 0; | ||
| 4841 | my $y1 = $hwfm->{vmax}->[$j] || 0; | ||
| 4842 | $ymin = $y0 unless defined $ymin && $ymin < $y0; | ||
| 4843 | $ymax = $y1 unless defined $ymax && $ymax > $y1; | ||
| 4844 | } | ||
| 4845 | } | ||
| 4846 | |||
| 4847 | $hwfm->{'WFMP:XZE'} = $xmin unless exists $hwfm->{'WFMP:XZE'}; | ||
| 4848 | $hwfm->{'WFMP:XIN'} = ( $xmax - $xmin ) / ( $jmax - $jmin ) | ||
| 4849 | unless exists $hwfm->{'WFMP:XIN'}; | ||
| 4850 | |||
| 4851 | $jstart = $jmin if $jmin > $jstart; | ||
| 4852 | $jstop = $jmax if $jmax < $jstop; | ||
| 4853 | |||
| 4854 | if ( $jstart >= $jstop ) { | ||
| 4855 | Lab::Exception::CorruptParameter->throw( | ||
| 4856 | "Invalid start ($jstart) >= stop ($jstop)"); | ||
| 4857 | return; | ||
| 4858 | } | ||
| 4859 | |||
| 4860 | $hwfm->{'DAT:STAR'} = $jstart; | ||
| 4861 | $hwfm->{'DAT:STOP'} = $jstop; | ||
| 4862 | |||
| 4863 | # voltage = (binary - yoffset)*ymul + yzero | ||
| 4864 | # binary = (voltage-yzero)/ymul + yoffset | ||
| 4865 | |||
| 4866 | $hwfm->{'WFMP:YOF'} = 0 unless exists $hwfm->{'WFMP:YOF'}; | ||
| 4867 | my $yoff = $hwfm->{'WFMP:YOF'}; | ||
| 4868 | $hwfm->{'WFMP:YZE'} = sprintf( '%.3e', $ymin - ( $ymax - $ymin ) / 200 ) | ||
| 4869 | unless exists $hwfm->{'WFMP:YZE'}; | ||
| 4870 | my $yzero = $hwfm->{'WFMP:YZE'}; | ||
| 4871 | $hwfm->{'WFMP:YMU'} = sprintf( '%.3e', ( $ymax - $ymin ) / 200 ) | ||
| 4872 | unless exists $hwfm->{'WFMP:YMU'}; | ||
| 4873 | my $ymult = $hwfm->{'WFMP:YMU'}; | ||
| 4874 | |||
| 4875 | my ( @dat, $datapt ); | ||
| 4876 | my $ds = 0; | ||
| 4877 | |||
| 4878 | if ( $ptf eq 'Y' ) { | ||
| 4879 | for ( my $j = $jmin; $j <= $jmax; $j++ ) { | ||
| 4880 | $datapt | ||
| 4881 | = int( 0.5 + $yoff + ( $hwfm->{v}->[$j] - $yzero ) / $ymult ); | ||
| 4882 | $datapt = $datamin if $datapt < $datamin; | ||
| 4883 | $datapt = $datamax if $datapt > $datamax; | ||
| 4884 | push( @dat, $datapt ); | ||
| 4885 | $ds++; | ||
| 4886 | } | ||
| 4887 | } | ||
| 4888 | else { | ||
| 4889 | for ( my $j = $jmin; $j <= $jmax; $j += 2 ) { | ||
| 4890 | $datapt = int( | ||
| 4891 | 0.5 + $yoff + ( $hwfm->{vmin}->[$j] - $yzero ) / $ymult ); | ||
| 4892 | $datapt = $datamin if $datapt < $datamin; | ||
| 4893 | $datapt = $datamax if $datapt > $datamax; | ||
| 4894 | push( @dat, $datapt ); | ||
| 4895 | |||
| 4896 | $datapt = int( | ||
| 4897 | 0.5 + $yoff + ( $hwfm->{vmax}->[$j] - $yzero ) / $ymult ); | ||
| 4898 | $datapt = $datamin if $datapt < $datamin; | ||
| 4899 | $datapt = $datamax if $datapt > $datamax; | ||
| 4900 | push( @dat, $datapt ); | ||
| 4901 | |||
| 4902 | $ds += 2; | ||
| 4903 | } | ||
| 4904 | } | ||
| 4905 | |||
| 4906 | if ( $fmt =~ /ASC/i ) { | ||
| 4907 | $rawdata = join( ',', @dat ); | ||
| 4908 | } | ||
| 4909 | else { | ||
| 4910 | my $form; | ||
| 4911 | |||
| 4912 | if ( $wd == 1 ) { | ||
| 4913 | if ( $fmt =~ /^\s*S?RP/i ) { | ||
| 4914 | $form = 'C'; | ||
| 4915 | } | ||
| 4916 | else { | ||
| 4917 | $form = 'c'; | ||
| 4918 | } | ||
| 4919 | } | ||
| 4920 | else { | ||
| 4921 | if ( $fmt =~ /^\s*S?RP/i ) { | ||
| 4922 | $form = 'S'; | ||
| 4923 | } | ||
| 4924 | else { | ||
| 4925 | $form = 's'; | ||
| 4926 | } | ||
| 4927 | if ( $fmt =~ /^\s*R/i ) { | ||
| 4928 | $form .= '>'; | ||
| 4929 | } | ||
| 4930 | else { | ||
| 4931 | $form .= '<'; | ||
| 4932 | } | ||
| 4933 | $ds = 2 * $ds; | ||
| 4934 | } | ||
| 4935 | $form .= '*'; | ||
| 4936 | $ds = sprintf( '%d', $ds * $hwfm->{'DAT:WID'} ); | ||
| 4937 | $rawdata = '#' . length($ds) . $ds; | ||
| 4938 | $rawdata .= pack( $form, @dat ); | ||
| 4939 | } | ||
| 4940 | |||
| 4941 | # since we now have the raw data, write all to scope | ||
| 4942 | |||
| 4943 | # first, set the destination, if specified | ||
| 4944 | |||
| 4945 | if ( exists( $tail->{destination} ) ) { | ||
| 4946 | $self->set_data_destination( $tail->{destination} ); | ||
| 4947 | } | ||
| 4948 | |||
| 4949 | # next the waveform prefix | ||
| 4950 | my $cmd = ''; | ||
| 4951 | foreach my $k (qw(BYT_N XIN XZE YMU YZE YOF)) { | ||
| 4952 | if ( exists( $hwfm->{"WFMP:$k"} ) ) { | ||
| 4953 | $cmd .= "$k " . $hwfm->{"WFMP:$k"} . ";"; | ||
| 4954 | } | ||
| 4955 | } | ||
| 4956 | $self->write( "WFMP:" . $cmd ) if $cmd ne ''; | ||
| 4957 | $self->_debug(); | ||
| 4958 | |||
| 4959 | $cmd = ''; | ||
| 4960 | foreach my $k (qw(STAR STOP ENC WID)) { | ||
| 4961 | if ( exists( $hwfm->{"DAT:$k"} ) ) { | ||
| 4962 | $cmd .= "$k " . $hwfm->{"DAT:$k"} . ";"; | ||
| 4963 | } | ||
| 4964 | } | ||
| 4965 | $self->write( "DAT:" . $cmd ) if $cmd ne ''; | ||
| 4966 | $self->_debug(); | ||
| 4967 | |||
| 4968 | # next the waveform data | ||
| 4969 | $cmd = 'CURV ' . $rawdata; | ||
| 4970 | $self->write($cmd); | ||
| 4971 | $self->_debug(); | ||
| 4972 | } | ||
| 4973 | |||
| 4974 | |||
| 4975 | sub print_waveform { | ||
| 4976 | my $self = shift; | ||
| 4977 | my ( $in, $tail ) = $self->_check_args_strict( \@_, qw(waveform) ); | ||
| 4978 | |||
| 4979 | croak("must pass waveform as hashref") | ||
| 4980 | unless defined($in) && ref($in) eq 'HASH'; | ||
| 4981 | my $out = *STDOUT; | ||
| 4982 | if ( exists( $tail->{output} ) ) { | ||
| 4983 | if ( ref( $tail->{output} ) =~ /(IO|GLOB)/ ) { | ||
| 4984 | $out = $tail->{output}; | ||
| 4985 | } | ||
| 4986 | elsif ( ref( $tail->{output} ) eq '' ) { | ||
| 4987 | my $t; | ||
| 4988 | open( $t, ">$tail->{output}" ); | ||
| 4989 | $out = $t; | ||
| 4990 | } | ||
| 4991 | else { | ||
| 4992 | carp("problem with output parameter"); | ||
| 4993 | } | ||
| 4994 | } | ||
| 4995 | |||
| 4996 | my $j = 0; | ||
| 4997 | foreach my $k ( sort( keys( %{$in} ) ) ) { | ||
| 4998 | next unless $k =~ /^(WFMP|DAT):/; | ||
| 4999 | print $out "$k: \t'", $in->{$k}, "'\n"; | ||
| 5000 | } | ||
| 5001 | |||
| 5002 | my $j0 = 1; | ||
| 5003 | my $j1 = 2500; | ||
| 5004 | $j0 = $in->{'DAT:STAR'} if exists $in->{'DAT:STAR'}; | ||
| 5005 | |||
| 5006 | if ( exists( $in->{v} ) ) { | ||
| 5007 | |||
| 5008 | $j1 = $in->{'DAT:STOP'} if exists $in->{'DAT:STOP'}; | ||
| 5009 | |||
| 5010 | my $v = $in->{v}; | ||
| 5011 | print $out "Voltages: \n"; | ||
| 5012 | for ( my $j = $j0; $j <= $j1 - 5; $j += 5 ) { | ||
| 5013 | my $str = sprintf( '%04d: t=%+.3e ' . "\t", $j, $in->{t}->[$j] ); | ||
| 5014 | for ( my $k = 0; $k < 5 && $j + $k <= $j1; $k++ ) { | ||
| 5015 | $str .= sprintf( '%+.3e ', $v->[ $j + $k ] ) . "\t"; | ||
| 5016 | } | ||
| 5017 | print $out $str, "\n"; | ||
| 5018 | } | ||
| 5019 | } | ||
| 5020 | elsif ( exists( $in->{vmin} ) ) { | ||
| 5021 | |||
| 5022 | $j1 = 1250; | ||
| 5023 | $j1 = $in->{'DAT:STOP'} if exists $in->{'DAT:STOP'}; | ||
| 5024 | |||
| 5025 | my $vmin = $in->{vmin}; | ||
| 5026 | my $vmax = $in->{vmax}; | ||
| 5027 | print $out "Envelope:\n"; | ||
| 5028 | my $str; | ||
| 5029 | for ( my $j = $j0; $j <= $j1 - 5; $j += 5 ) { | ||
| 5030 | $str = sprintf( '%04d: t=%+.3e MAX ' . "\t", $j, $in->{t}->[$j] ); | ||
| 5031 | for ( my $k = 0; $k < 5 && $j + $k <= $j1; $k++ ) { | ||
| 5032 | $str .= sprintf( '%+.3e ', $vmax->[ $j + $k ] ) . "\t"; | ||
| 5033 | } | ||
| 5034 | print $out $str, "\n"; | ||
| 5035 | $str = sprintf( '%04d: t=%+.3e MIN ' . "\t", $j, $in->{t}->[$j] ); | ||
| 5036 | for ( my $k = 0; $k < 5 && $j + $k <= $j1; $k++ ) { | ||
| 5037 | $str .= sprintf( '%+.3e ', $vmin->[ $j + $k ] ) . "\t"; | ||
| 5038 | } | ||
| 5039 | print $out $str, "\n\n"; | ||
| 5040 | } | ||
| 5041 | } | ||
| 5042 | |||
| 5043 | } | ||
| 5044 | |||
| 5045 | 1; # End of Lab::Instrument::TDS2024B | ||
| 5046 | |||
| 5047 | __END__ |