| 1 | package Lab::Instrument::SignalRecovery726x; | ||
| 2 | $Lab::Instrument::SignalRecovery726x::VERSION = '3.899'; | ||
| 3 | #ABSTRACT: Signal Recovery 7260 / 7265 Lock-in Amplifier | ||
| 4 | |||
| 5 | use v5.20; | ||
| 6 | |||
| 7 | use strict; | ||
| 8 | use Time::HiRes qw/usleep/, qw/time/; | ||
| 9 | use Lab::Instrument; | ||
| 10 | use Time::HiRes qw (usleep); | ||
| 11 | |||
| 12 | our @ISA = ("Lab::Instrument"); | ||
| 13 | |||
| 14 | our %fields = ( | ||
| 15 | supported_connections => | ||
| 16 | [ 'VISA', 'VISA_GPIB', 'GPIB', 'VISA_RS232', 'RS232', 'DEBUG' ], | ||
| 17 | |||
| 18 | connection_settings => { | ||
| 19 | baudrate => 19200, | ||
| 20 | databits => 7, | ||
| 21 | stopbits => 1, | ||
| 22 | parity => 'even', | ||
| 23 | handshake => 'none', | ||
| 24 | rs232_echo => 'character', | ||
| 25 | timeout => 500, | ||
| 26 | termchar => "\n", | ||
| 27 | timeout => 2 | ||
| 28 | }, | ||
| 29 | |||
| 30 | device_settings => {}, | ||
| 31 | |||
| 32 | device_cache => { | ||
| 33 | imode => undef, | ||
| 34 | vmode => undef, | ||
| 35 | fet => undef, | ||
| 36 | float => undef, | ||
| 37 | cp => undef, | ||
| 38 | sen => undef, | ||
| 39 | linefilter => undef, | ||
| 40 | refchannel => undef, | ||
| 41 | refpha => undef, | ||
| 42 | ouputfilter_slope => undef, | ||
| 43 | |||
| 44 | #value => undef, | ||
| 45 | osc => undef, | ||
| 46 | frq => undef, | ||
| 47 | acgain => undef, | ||
| 48 | tc => undef | ||
| 49 | } | ||
| 50 | |||
| 51 | ); | ||
| 52 | |||
| 53 | sub new { | ||
| 54 | my $proto = shift; | ||
| 55 | my $class = ref($proto) || $proto; | ||
| 56 | my $self = $class->SUPER::new(@_); | ||
| 57 | $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__); | ||
| 58 | |||
| 59 | return $self; | ||
| 60 | } | ||
| 61 | |||
| 62 | sub reset { | ||
| 63 | |||
| 64 | my $self = shift; | ||
| 65 | $self->write("ADF 1"); | ||
| 66 | |||
| 67 | $self->_cache_init(); | ||
| 68 | } | ||
| 69 | |||
| 70 | # ------------------ SIGNAL CHANNEL ------------------------- | ||
| 71 | |||
| 72 | sub set_imode { # basic setting | ||
| 73 | my $self = shift; | ||
| 74 | my ($imode) = $self->_check_args( \@_, ['value'] ); | ||
| 75 | |||
| 76 | # $imode == 0 --> Current Mode OFF | ||
| 77 | # $imode == 1 --> High Bandwidth Current Mode | ||
| 78 | # $imode == 2 --> Low Noise Current Mode | ||
| 79 | |||
| 80 | if ( not defined $imode ) { | ||
| 81 | return get_imode(); | ||
| 82 | } | ||
| 83 | |||
| 84 | if ( defined $imode and ( $imode == 0 || $imode == 1 || $imode == 2 ) ) { | ||
| 85 | my $cmd = sprintf( "IMODE %d", $imode ); | ||
| 86 | $self->write($cmd); | ||
| 87 | } | ||
| 88 | else { | ||
| 89 | Lab::Exception::CorruptParameter->throw( error => | ||
| 90 | "\nSIGNAL REOCOVERY 726x:\nunexpected value for IMODE in sub set_imode. Expected values are:\n 0 --> Current Mode OFF\n 1 --> High Bandwidth Current Mode\n 2 --> Low Noise Current Mode\n" | ||
| 91 | ); | ||
| 92 | } | ||
| 93 | |||
| 94 | } | ||
| 95 | |||
| 96 | sub get_imode { | ||
| 97 | my $self = shift; | ||
| 98 | |||
| 99 | my ($tail) = $self->_check_args( \@_ ); | ||
| 100 | |||
| 101 | return $self->query( "IMODE", $tail ); | ||
| 102 | } | ||
| 103 | |||
| 104 | sub set_vmode { # basic setting | ||
| 105 | my $self = shift; | ||
| 106 | my ($vmode) = $self->_check_args( \@_, ['value'] ); | ||
| 107 | |||
| 108 | # $vmode == 0 --> Both inputs grounded (testmode) | ||
| 109 | # $vmode == 1 --> A input only | ||
| 110 | # $vmode == 2 --> -B input only | ||
| 111 | # $vmode == 3 --> A-B differential mode | ||
| 112 | |||
| 113 | if ( defined $vmode | ||
| 114 | and ( $vmode == 0 || $vmode == 1 || $vmode == 2 || $vmode == 3 ) ) { | ||
| 115 | |||
| 116 | my $cmd = sprintf( "VMODE %d", $vmode ); | ||
| 117 | $self->write($cmd); | ||
| 118 | } | ||
| 119 | else { | ||
| 120 | Lab::Exception::CorruptParameter->throw( error => | ||
| 121 | "\nSIGNAL REOCOVERY 726x:\nunexpected value for VMODE in sub set_vmode. Expected values are:\n 0 --> Both inputs grounded (testmode)\n 1 --> A input only\n 2 --> -B input only\n 3 --> A-B differential mode\n" | ||
| 122 | ); | ||
| 123 | } | ||
| 124 | |||
| 125 | } | ||
| 126 | |||
| 127 | sub get_vmode { | ||
| 128 | my $self = shift; | ||
| 129 | |||
| 130 | my ($tail) = $self->_check_args( \@_ ); | ||
| 131 | |||
| 132 | return $self->query( "VMODE", $tail ); | ||
| 133 | } | ||
| 134 | |||
| 135 | sub set_fet { # basic setting | ||
| 136 | my $self = shift; | ||
| 137 | my ($value) = $self->_check_args( \@_, ['value'] ); | ||
| 138 | |||
| 139 | # $value == 0 --> Bipolar device, 10 kOhm input impedance, 2nV/sqrt(Hz) voltage noise at 1 kHz | ||
| 140 | # $value == 1 --> FET, 10 MOhm input impedance, 5nV/sqrt(Hz) voltage noise at 1 kHz | ||
| 141 | |||
| 142 | if ( defined $value and ( $value == 0 || $value == 1 ) ) { | ||
| 143 | my $cmd = sprintf( "FET %d", $value ); | ||
| 144 | $self->write($cmd); | ||
| 145 | } | ||
| 146 | else { | ||
| 147 | Lab::Exception::CorruptParameter->throw( error => | ||
| 148 | "\nSIGNAL REOCOVERY 726x:\nunexpected value in sub set_fet. Expected values are:\n 0 --> Bipolar device, 10 kOhm input impedance, 2nV/sqrt(Hz) voltage noise at 1 kHz\n 1 --> FET, 10 MOhm input impedance, 5nV/sqrt(Hz) voltage noise at 1 kHz\n" | ||
| 149 | ); | ||
| 150 | } | ||
| 151 | |||
| 152 | } | ||
| 153 | |||
| 154 | sub get_fet { | ||
| 155 | my $self = shift; | ||
| 156 | |||
| 157 | my ($tail) = $self->_check_args( \@_ ); | ||
| 158 | |||
| 159 | return $self->query( "FET", $tail ); | ||
| 160 | } | ||
| 161 | |||
| 162 | sub set_float { # basic setting | ||
| 163 | my $self = shift; | ||
| 164 | my ($value) = $self->_check_args( \@_, ['value'] ); | ||
| 165 | |||
| 166 | # $value == 0 --> input conector shield set to GROUND | ||
| 167 | # $value == 1 --> input conector shield set to FLOAT | ||
| 168 | |||
| 169 | if ( defined $value and ( $value == 0 || $value == 1 ) ) { | ||
| 170 | |||
| 171 | my $cmd = sprintf( "FLOAT %d", $value ); | ||
| 172 | $self->write($cmd); | ||
| 173 | } | ||
| 174 | else { | ||
| 175 | Lab::Exception::CorruptParameter->throw( error => | ||
| 176 | "\nSIGNAL REOCOVERY 726x:\nunexpected value in sub set_float. Expected values are:\n 0 --> input conector shield set to GROUND\n 1 --> input conector shield set to FLOAT\n" | ||
| 177 | ); | ||
| 178 | } | ||
| 179 | |||
| 180 | } | ||
| 181 | |||
| 182 | sub get_float { | ||
| 183 | my $self = shift; | ||
| 184 | |||
| 185 | my ($tail) = $self->_check_args( \@_ ); | ||
| 186 | |||
| 187 | return $self->query("FLOAT"); | ||
| 188 | } | ||
| 189 | |||
| 190 | sub set_cp { # basic setting | ||
| 191 | my $self = shift; | ||
| 192 | my ($value) = $self->_check_args( \@_, ['value'] ); | ||
| 193 | |||
| 194 | # $value == 0 --> input coupling mode AC\n | ||
| 195 | # $value == 1 --> input coupling mode DC\n | ||
| 196 | |||
| 197 | if ( defined $value and ( $value == 0 || $value == 1 ) ) { | ||
| 198 | |||
| 199 | my $cmd = sprintf( "CP %d", $value ); | ||
| 200 | $self->write($cmd); | ||
| 201 | } | ||
| 202 | else { | ||
| 203 | Lab::Exception::CorruptParameter->throw( error => | ||
| 204 | "\nSIGNAL REOCOVERY 726x:\nunexpected value in sub set_cp. Expected values are:\n 0 --> input coupling mode AC\n 1 --> input coupling mode DC\n" | ||
| 205 | ); | ||
| 206 | } | ||
| 207 | |||
| 208 | } | ||
| 209 | |||
| 210 | sub get_cp { | ||
| 211 | my $self = shift; # | ||
| 212 | |||
| 213 | my ($tail) = $self->_check_args( \@_ ); | ||
| 214 | |||
| 215 | return $self->query("CP"); | ||
| 216 | } | ||
| 217 | |||
| 218 | sub set_sen { # basic setting | ||
| 219 | my $self = shift; | ||
| 220 | my ($value) = $self->_check_args( \@_, ['value'] ); | ||
| 221 | |||
| 222 | my @matrix = ( | ||
| 223 | { | ||
| 224 | 2e-9 => 1, | ||
| 225 | 5e-9 => 2, | ||
| 226 | 10e-9 => 3, | ||
| 227 | 2e-8 => 4, | ||
| 228 | 5e-8 => 5, | ||
| 229 | 10e-8 => 6, | ||
| 230 | 2e-7 => 7, | ||
| 231 | 5e-7 => 8, | ||
| 232 | 10e-7 => 9, | ||
| 233 | 2e-6 => 10, | ||
| 234 | 5e-6 => 11, | ||
| 235 | 10e-6 => 12, | ||
| 236 | 2e-5 => 13, | ||
| 237 | 5e-5 => 14, | ||
| 238 | 10e-5 => 15, | ||
| 239 | 2e-4 => 16, | ||
| 240 | 5e-4 => 17, | ||
| 241 | 10e-4 => 18, | ||
| 242 | 2e-3 => 19, | ||
| 243 | 5e-3 => 20, | ||
| 244 | 10e-3 => 21, | ||
| 245 | 2e-2 => 22, | ||
| 246 | 5e-2 => 23, | ||
| 247 | 10e-2 => 24, | ||
| 248 | 2e-1 => 25, | ||
| 249 | 5e-1 => 26, | ||
| 250 | 10e-1 => 27 | ||
| 251 | }, | ||
| 252 | { | ||
| 253 | 2e-15 => 1, | ||
| 254 | 5e-15 => 2, | ||
| 255 | 10e-15 => 3, | ||
| 256 | 2e-14 => 4, | ||
| 257 | 5e-14 => 5, | ||
| 258 | 10e-14 => 6, | ||
| 259 | 2e-13 => 7, | ||
| 260 | 5e-13 => 8, | ||
| 261 | 10e-13 => 9, | ||
| 262 | 2e-12 => 10, | ||
| 263 | 5e-12 => 11, | ||
| 264 | 10e-12 => 12, | ||
| 265 | 2e-11 => 13, | ||
| 266 | 5e-11 => 14, | ||
| 267 | 10e-11 => 15, | ||
| 268 | 2e-10 => 16, | ||
| 269 | 5e-10 => 17, | ||
| 270 | 10e-10 => 18, | ||
| 271 | 2e-9 => 19, | ||
| 272 | 5e-9 => 20, | ||
| 273 | 10e-9 => 21, | ||
| 274 | 2e-8 => 22, | ||
| 275 | 5e-8 => 23, | ||
| 276 | 10e-8 => 24, | ||
| 277 | 2e-7 => 25, | ||
| 278 | 5e-7 => 26, | ||
| 279 | 10e-7 => 27 | ||
| 280 | }, | ||
| 281 | { | ||
| 282 | 2e-15 => 7, | ||
| 283 | 5e-15 => 8, | ||
| 284 | 10e-15 => 9, | ||
| 285 | 2e-14 => 10, | ||
| 286 | 5e-14 => 11, | ||
| 287 | 10e-14 => 12, | ||
| 288 | 2e-13 => 13, | ||
| 289 | 5e-13 => 14, | ||
| 290 | 10e-13 => 15, | ||
| 291 | 2e-12 => 16, | ||
| 292 | 5e-12 => 17, | ||
| 293 | 10e-12 => 18, | ||
| 294 | 2e-11 => 19, | ||
| 295 | 5e-11 => 20, | ||
| 296 | 10e-11 => 21, | ||
| 297 | 2e-10 => 22, | ||
| 298 | 5e-10 => 23, | ||
| 299 | 10e-10 => 24, | ||
| 300 | 2e-9 => 25, | ||
| 301 | 5e-9 => 26, | ||
| 302 | 10e-9 => 27 | ||
| 303 | } | ||
| 304 | ); | ||
| 305 | |||
| 306 | my $imode = $self->query("IMODE"); | ||
| 307 | |||
| 308 | # SENSITIVITY (IMODE == 0) --> 2nV, 5nV, 10nV, 20nV, 50nV, 100nV, 200nV, 500nV, 1uV, 2uV, 5uV, 10uV, 20uV, 50uV, 100uV, 200uV, 500uV, 1mV, 2mV, 5mV, 10mV, 20mV, 50mV, 100mV, 200mV, 500mV, 1V\n | ||
| 309 | # SENSITIVITY (IMODE == 1) --> 2fA, 5fA, 10fA, 20fA, 50fA, 100fA, 200fA, 500fA, 1pA, 2pA, 5pA, 10pA, 20pA, 50pA, 100pA, 200pA, 500pA, 1nA, 2nA, 5nA, 10nA, 20nA, 50nA, 100nA, 200nA, 500nA, 1uA\n | ||
| 310 | # SENSITIVITY (IMODE == 2) --> 2fA, 5fA, 10fA, 20fA, 50fA, 100fA, 200fA, 500fA, 1pA, 2pA, 5pA, 10pA, 20pA, 50pA, 100pA, 200pA, 500pA, 1nA, 2nA, 5nA, 10nA\n | ||
| 311 | |||
| 312 | if ( index( $value, "n" ) >= 0 ) { | ||
| 313 | $value = int($value) * 1e-9; | ||
| 314 | } | ||
| 315 | elsif ( index( $value, "f" ) >= 0 ) { | ||
| 316 | $value = int($value) * 1e-15; | ||
| 317 | } | ||
| 318 | elsif ( index( $value, "p" ) >= 0 ) { | ||
| 319 | $value = int($value) * 1e-12; | ||
| 320 | } | ||
| 321 | elsif ( index( $value, "u" ) >= 0 ) { | ||
| 322 | $value = int($value) * 1e-6; | ||
| 323 | } | ||
| 324 | elsif ( index( $value, "m" ) >= 0 ) { | ||
| 325 | $value = int($value) * 1e-3; | ||
| 326 | } | ||
| 327 | |||
| 328 | if ( exists $matrix[$imode]->{$value} ) { | ||
| 329 | |||
| 330 | my $cmd = sprintf( "SEN %d", $matrix[$imode]->{$value} ); | ||
| 331 | $self->write($cmd); | ||
| 332 | } | ||
| 333 | elsif ( $value == "AUTO" ) { | ||
| 334 | $self->write("AS"); | ||
| 335 | } | ||
| 336 | |||
| 337 | else { | ||
| 338 | Lab::Exception::CorruptParameter->throw( error => | ||
| 339 | "\nSIGNAL REOCOVERY 726x:\nunexpected value for SENSITIVITY in sub set_sen. Expected values are: \n\n SENSITIVITY (IMODE == 0) --> 2nV, 5nV, 10nV, 20nV, 50nV, 100nV, 200nV, 500nV, 1uV, 2uV, 5uV, 10uV, 20uV, 50uV, 100uV, 200uV, 500uV, 1mV, 2mV, 5mV, 10mV, 20mV, 50mV, 100mV, 200mV, 500mV, 1V\n\n SENSITIVITY (IMODE == 1) --> 2fA, 5fA, 10fA, 20fA, 50fA, 100fA, 200fA, 500fA, 1pA, 2pA, 5pA, 10pA, 20pA, 50pA, 100pA, 200pA, 500pA, 1nA, 2nA, 5nA, 10nA, 20nA, 50nA, 100nA, 200nA, 500nA, 1uA\n\n SENSITIVITY (IMODE == 2) --> 2fA, 5fA, 10fA, 20fA, 50fA, 100fA, 200fA, 500fA, 1pA, 2pA, 5pA, 10pA, 20pA, 50pA, 100pA, 200pA, 500pA, 1nA, 2nA, 5nA, 10nA\n" | ||
| 340 | ); | ||
| 341 | } | ||
| 342 | |||
| 343 | } | ||
| 344 | |||
| 345 | sub get_sen { | ||
| 346 | my $self = shift; | ||
| 347 | |||
| 348 | my ($tail) = $self->_check_args( \@_ ); | ||
| 349 | |||
| 350 | my @matrix_reverse = ( | ||
| 351 | [ | ||
| 352 | 2e-9, 5e-9, 10e-9, 2e-8, 5e-8, 10e-8, 2e-7, 5e-7, | ||
| 353 | 10e-7, 2e-6, 5e-6, 10e-6, 2e-5, 5e-5, 10e-5, 2e-4, | ||
| 354 | 5e-4, 10e-4, 2e-3, 5e-3, 10e-3, 2e-2, 5e-2, 10e-2, | ||
| 355 | 2e-1, 5e-1, 10e-1 | ||
| 356 | ], | ||
| 357 | [ | ||
| 358 | 2e-15, 5e-15, 10e-15, 2e-14, 5e-14, 10e-14, 2e-13, 5e-13, | ||
| 359 | 10e-13, 2e-12, 5e-12, 10e-12, 2e-11, 5e-11, 10e-11, 2e-10, | ||
| 360 | 5e-10, 10e-10, 2e-9, 5e-9, 10e-9, 2e-8, 5e-8, 10e-8, | ||
| 361 | 2e-7, 5e-7, 10e-7 | ||
| 362 | ], | ||
| 363 | [ | ||
| 364 | 2e-15, 5e-15, 10e-15, 2e-14, 5e-14, 10e-14, 2e-13, 5e-13, | ||
| 365 | 10e-13, 2e-12, 5e-12, 10e-12, 2e-11, 5e-11, 10e-11, 2e-10, | ||
| 366 | 5e-10, 10e-10, 2e-9, 5e-9, 10e-9 | ||
| 367 | ] | ||
| 368 | ); | ||
| 369 | |||
| 370 | my $imode = $self->get_imode( { 'read_mode' => "cache" } ); | ||
| 371 | |||
| 372 | return $matrix_reverse[$imode][ $self->query("SEN") - 1 ]; | ||
| 373 | |||
| 374 | } | ||
| 375 | |||
| 376 | sub set_acgain { # basic setting | ||
| 377 | my $self = shift; | ||
| 378 | my ($value) = $self->_check_args( \@_, ['value'] ); | ||
| 379 | |||
| 380 | # AC-GAIN == 0 --> 0 dB gain of the signal channel amplifier\n | ||
| 381 | # AC-GAIN == 1 --> 10 dB gain of the signal channel amplifier\n | ||
| 382 | # ... | ||
| 383 | # AC-GAIN == 9 --> 90 dB gain of the signal channel amplifier\n | ||
| 384 | |||
| 385 | if ( index( $value, "dB" ) >= 0 ) { | ||
| 386 | $value = int($value) / 10; | ||
| 387 | } | ||
| 388 | |||
| 389 | if ( defined $value | ||
| 390 | and int($value) == $value | ||
| 391 | and $value <= 9 | ||
| 392 | and $value >= 0 ) { | ||
| 393 | |||
| 394 | my $cmd = sprintf( "ACGAIN %d", $value ); | ||
| 395 | $self->write($cmd); | ||
| 396 | my $gain = $self->query("ACGAIN"); | ||
| 397 | |||
| 398 | } | ||
| 399 | elsif ( $value eq "AUTO" ) { | ||
| 400 | my $cmd = sprintf("AUTOMATIC 1"); | ||
| 401 | $self->write($cmd); | ||
| 402 | } | ||
| 403 | else { | ||
| 404 | Lab::Exception::CorruptParameter->throw( error => | ||
| 405 | "\nSIGNAL REOCOVERY 726x:\nunexpected value for AC-GAIN in sub set_acgain. Expected values are:\n AC-GAIN == 0 --> 0 dB gain of the signal channel amplifier\n AC-GAIN == 1 --> 10 dB gain of the signal channel amplifier\n ...\n AC-GAIN == 9 --> 90 dB gain of the signal channel amplifier\n" | ||
| 406 | ); | ||
| 407 | } | ||
| 408 | |||
| 409 | } | ||
| 410 | |||
| 411 | sub get_acgain { | ||
| 412 | my $self = shift; | ||
| 413 | |||
| 414 | my ($tail) = $self->_check_args( \@_ ); | ||
| 415 | |||
| 416 | return $self->query( "ACGAIN", $tail ); | ||
| 417 | } | ||
| 418 | |||
| 419 | sub set_linefilter { # basic setting | ||
| 420 | my $self = shift; | ||
| 421 | my ( $value, $linefrequency ) | ||
| 422 | = $self->_check_args( \@_, [ 'value', 'line_frequency' ] ); | ||
| 423 | |||
| 424 | if ( not defined $linefrequency ) { $linefrequency = 1; } # 1-->50Hz | ||
| 425 | elsif ( $linefrequency eq "50Hz" ) { $linefrequency = 1; } | ||
| 426 | elsif ( $linefrequency eq "60Hz" ) { $linefrequency = 0; } # 0 --> 60Hz | ||
| 427 | else { | ||
| 428 | Lab::Exception::CorruptParameter->throw( error => | ||
| 429 | "\nSIGNAL REOCOVERY 726x:\nunexpected value for LINEFREQUENCY in sub set_linefilter. Expected values are '50Hz' or '60Hz'." | ||
| 430 | ); | ||
| 431 | } | ||
| 432 | |||
| 433 | # LINE-FILTER == 0 --> OFF\n | ||
| 434 | # LINE-FILTER == 1 --> enable 50Hz/60Hz notch filter\n | ||
| 435 | # LINE-FILTER == 2 --> enable 100Hz/120Hz notch filter\n | ||
| 436 | # LINE-FILTER == 3 --> enable 50Hz/60Hz and 100Hz/120Hz notch filter\n | ||
| 437 | |||
| 438 | if ( defined $value | ||
| 439 | and ( $value == 0 || $value == 1 || $value == 2 || $value == 3 ) ) { | ||
| 440 | |||
| 441 | my $cmd = sprintf( "LF %d, %d", $value, $linefrequency ); | ||
| 442 | $self->write($cmd); | ||
| 443 | } | ||
| 444 | else { | ||
| 445 | Lab::Exception::CorruptParameter->throw( error => | ||
| 446 | "\nSIGNAL REOCOVERY 726x:\nunexpected value for FILTER in sub set_linefilter. Expected values are:\n LINE-FILTER == 0 --> OFF\n LINE-FILTER == 1 --> enable 50Hz/60Hz notch filter\n LINE-FILTER == 2 --> enable 100Hz/120Hz notch filter\n LINE-FILTER == 3 --> enable 50Hz/60Hz and 100Hz/120Hz notch filter\n" | ||
| 447 | ); | ||
| 448 | } | ||
| 449 | |||
| 450 | } | ||
| 451 | |||
| 452 | sub get_linefilter { | ||
| 453 | my $self = shift; | ||
| 454 | |||
| 455 | my ($tail) = $self->_check_args( \@_ ); | ||
| 456 | |||
| 457 | return $self->query("LF"); | ||
| 458 | } | ||
| 459 | |||
| 460 | # ------------------REFERENCE CHANNEL --------------------------- | ||
| 461 | |||
| 462 | sub set_refchannel { # basic setting | ||
| 463 | my $self = shift; | ||
| 464 | my ($value) = $self->_check_args( \@_, ['value'] ); | ||
| 465 | |||
| 466 | # INT --> internal reference input mode\n | ||
| 467 | # EXT LOGIC --> external rear panel TTL input\n | ||
| 468 | # EXT --> external front panel analog input\n | ||
| 469 | |||
| 470 | if ( $value eq "INT" ) { $value = 0; } | ||
| 471 | elsif ( $value eq "EXT LOGIC" ) { $value = 1; } | ||
| 472 | elsif ( $value eq "EXT" ) { $value = 2; } | ||
| 473 | else { | ||
| 474 | Lab::Exception::CorruptParameter->throw( error => | ||
| 475 | "\nSIGNAL REOCOVERY 726x:\nunexpected value for REFERENCE CHANEL in sub set_refchennel. Expected values are:\n INT --> internal reference input mode\n EXT LOGIC --> external rear panel TTL input\n EXT --> external front panel analog input\n" | ||
| 476 | ); | ||
| 477 | } | ||
| 478 | |||
| 479 | my $cmd = sprintf( "IE %d", $value ); | ||
| 480 | $self->write($cmd); | ||
| 481 | |||
| 482 | } | ||
| 483 | |||
| 484 | sub get_refchannel { | ||
| 485 | my $self = shift; | ||
| 486 | |||
| 487 | my ($tail) = $self->_check_args( \@_ ); | ||
| 488 | |||
| 489 | my $result = $self->query( "IE", $tail ); | ||
| 490 | |||
| 491 | if ( $result == 0 ) { | ||
| 492 | return 'INT'; | ||
| 493 | } | ||
| 494 | elsif ( $result == 1 ) { | ||
| 495 | return 'EXT LOGIC'; | ||
| 496 | } | ||
| 497 | elsif ( $result == 2 ) { | ||
| 498 | return 'EXT'; | ||
| 499 | } | ||
| 500 | |||
| 501 | } | ||
| 502 | |||
| 503 | sub autophase { # basic setting | ||
| 504 | my $self = shift; | ||
| 505 | $self->write("AQN"); | ||
| 506 | usleep( 5 * $self->set_tc() * 1e6 ); | ||
| 507 | } | ||
| 508 | |||
| 509 | sub set_refpha { # basic setting | ||
| 510 | my $self = shift; | ||
| 511 | my ($value) = $self->_check_args( \@_, ['value'] ); | ||
| 512 | |||
| 513 | if ( $value >= 0 && $value <= 360 ) { | ||
| 514 | $self->write( sprintf( "REFP %d", $value * 1e3 ) ); | ||
| 515 | } | ||
| 516 | else { | ||
| 517 | Lab::Exception::CorruptParameter->throw( error => | ||
| 518 | "\nSIGNAL REOCOVERY 726x:\nunexpected value for REFERENCE PHASE in sub set_refpha. Expected values must be in the range 0..360" | ||
| 519 | ); | ||
| 520 | } | ||
| 521 | } | ||
| 522 | |||
| 523 | sub get_refpha { # basic setting | ||
| 524 | my $self = shift; | ||
| 525 | |||
| 526 | my ($tail) = $self->_check_args( \@_ ); | ||
| 527 | |||
| 528 | my $val = $self->query("REFP."); | ||
| 529 | |||
| 530 | # Trailing zero byte if phase is zero. Device bug?? | ||
| 531 | $val =~ s/\0//; | ||
| 532 | |||
| 533 | return $val; | ||
| 534 | |||
| 535 | } | ||
| 536 | |||
| 537 | # ----------------- SIGNAL CHANNEL OUTPUT FILTERS --------------- | ||
| 538 | |||
| 539 | sub set_ouputfilter_slope { # basic setting | ||
| 540 | my $self = shift; | ||
| 541 | my ($value) = $self->_check_args( \@_, ['value'] ); | ||
| 542 | |||
| 543 | # 6dB --> 6dB/octave slope of output filter\n | ||
| 544 | # 12dB --> 12dB/octave slope of output filter\n | ||
| 545 | # 18dB --> 18dB/octave slope of output filter\n | ||
| 546 | # 24dB --> 24dB/octave slope of output filter\n | ||
| 547 | |||
| 548 | if ( $value eq "6dB" ) { $value = 0; } | ||
| 549 | elsif ( $value eq "12dB" ) { $value = 1; } | ||
| 550 | elsif ( $value eq "18dB" ) { $value = 2; } | ||
| 551 | elsif ( $value eq "24dB" ) { $value = 3; } | ||
| 552 | else { | ||
| 553 | Lab::Exception::CorruptParameter->throw( error => | ||
| 554 | "\nSIGNAL REOCOVERY 726x:\nunexpected value for SLOPE in sub set_ouputfilter_slope. Expected values are:\n 6dB --> 6dB/octave slope of output filter\n 12dB --> 12dB/octave slope of output filter\n 18dB --> 18dB/octave slope of output filter\n 24dB --> 24dB/octave slope of output filter\n" | ||
| 555 | ); | ||
| 556 | } | ||
| 557 | |||
| 558 | my $cmd = sprintf( "SLOPE %d", $value ); | ||
| 559 | $self->write($cmd); | ||
| 560 | |||
| 561 | } | ||
| 562 | |||
| 563 | sub get_ouputfilter_slope { | ||
| 564 | my $self = shift; | ||
| 565 | |||
| 566 | my ($tail) = $self->_check_args( \@_ ); | ||
| 567 | |||
| 568 | my $result = $self->query( "SLOPE", $tail ); | ||
| 569 | |||
| 570 | if ( $result == 0 ) { | ||
| 571 | return '6dB'; | ||
| 572 | } | ||
| 573 | elsif ( $result == 1 ) { | ||
| 574 | return '12dB'; | ||
| 575 | } | ||
| 576 | elsif ( $result == 2 ) { | ||
| 577 | return '18dB'; | ||
| 578 | } | ||
| 579 | elsif ( $result == 3 ) { | ||
| 580 | return '24dB'; | ||
| 581 | } | ||
| 582 | |||
| 583 | } | ||
| 584 | |||
| 585 | sub set_tc { # basic setting | ||
| 586 | my $self = shift; | ||
| 587 | my ($value) = $self->_check_args( \@_, ['value'] ); | ||
| 588 | |||
| 589 | # Filter Time Constant: 10us, 20us, 40us, 80us, 160us, 320us, 640us, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms, 1s, 2s, 5s, 10s, 20s, 50s, 100s, 200s, 500s, 1ks, 2ks, 5ks, 10ks, 20ks, 50ks, 100ks\n | ||
| 590 | |||
| 591 | my %list = ( | ||
| 592 | 10e-6 => 0, | ||
| 593 | 20e-6 => 1, | ||
| 594 | 40e-6 => 2, | ||
| 595 | 80e-6 => 3, | ||
| 596 | 160e-6 => 4, | ||
| 597 | 320e-6 => 5, | ||
| 598 | 640e-6 => 6, | ||
| 599 | 5e-3 => 7, | ||
| 600 | 10e-3 => 8, | ||
| 601 | 20e-3 => 9, | ||
| 602 | 50e-3 => 10, | ||
| 603 | 100e-3 => 11, | ||
| 604 | 200e-3 => 12, | ||
| 605 | 500e-3 => 13, | ||
| 606 | 1 => 14, | ||
| 607 | 2 => 15, | ||
| 608 | 5 => 16, | ||
| 609 | 10 => 17, | ||
| 610 | 20 => 18, | ||
| 611 | 50 => 19, | ||
| 612 | 100 => 20, | ||
| 613 | 200 => 21, | ||
| 614 | 500 => 22, | ||
| 615 | 1e3 => 23, | ||
| 616 | 2e3 => 24, | ||
| 617 | 5e3 => 25, | ||
| 618 | 10e3 => 26, | ||
| 619 | 20e3 => 27, | ||
| 620 | 50e3 => 28, | ||
| 621 | 100e3 => 29 | ||
| 622 | ); | ||
| 623 | my @list = ( | ||
| 624 | 10e-6, 20e-6, 40e-6, 80e-6, 160e-6, 320e-6, 640e-6, 5e-3, | ||
| 625 | 10e-3, 20e-3, 50e-3, 100e-3, 200e-3, 500e-3, 1, 2, | ||
| 626 | 5, 10, 20, 50, 100, 200, 500, 1e3, | ||
| 627 | 2e3, 5e3, 10e3, 20e3, 50e3, 100e3 | ||
| 628 | ); | ||
| 629 | |||
| 630 | if ( $value =~ /\b(\d+\.?[\d+]?)us?\b/ ) { | ||
| 631 | $value = $1 * 1e-6; | ||
| 632 | } | ||
| 633 | elsif ( $value =~ /\b(\d+\.?[\d+]?)ms?\b/ ) { | ||
| 634 | $value = $1 * 1e-3; | ||
| 635 | } | ||
| 636 | elsif ( $value =~ /\b(\d+\.?[\d+]?)ks?\b/ ) { | ||
| 637 | $value = $1 * 1000; | ||
| 638 | } | ||
| 639 | |||
| 640 | if ( exists $list{$value} ) { | ||
| 641 | my $cmd = sprintf( "TC %d", $list{$value} ); | ||
| 642 | $self->write($cmd); | ||
| 643 | } | ||
| 644 | else { | ||
| 645 | Lab::Exception::CorruptParameter->throw( error => | ||
| 646 | "\nSIGNAL REOCOVERY 726x:\nunexpected value for TIME CONSTANT in set_tc. Filter Time Constant TC can be:\n10us, 20us, 40us, 80us, 160us, 320us, 640us, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms, 1s, 2s, 5s, 10s, 20s, 50s, 100s, 200s, 500s, 1ks, 2ks, 5ks, 10ks, 20ks, 50ks, 100ks\n" | ||
| 647 | ); | ||
| 648 | } | ||
| 649 | |||
| 650 | } | ||
| 651 | |||
| 652 | sub get_tc { | ||
| 653 | my $self = shift; | ||
| 654 | |||
| 655 | my ($tail) = $self->_check_args( \@_ ); | ||
| 656 | |||
| 657 | my @list = ( | ||
| 658 | 10e-6, 20e-6, 40e-6, 80e-6, 160e-6, 320e-6, 640e-6, 5e-3, | ||
| 659 | 10e-3, 20e-3, 50e-3, 100e-3, 200e-3, 500e-3, 1, 2, | ||
| 660 | 5, 10, 20, 50, 100, 200, 500, 1e3, | ||
| 661 | 2e3, 5e3, 10e3, 20e3, 50e3, 100e3 | ||
| 662 | ); | ||
| 663 | |||
| 664 | my $tc = $self->query( "TC", $tail ); | ||
| 665 | |||
| 666 | return $list[$tc]; | ||
| 667 | } | ||
| 668 | |||
| 669 | # ---------------- SIGNAL CHANNEL OUTPUT AMPLIFIERS -------------- | ||
| 670 | |||
| 671 | sub set_offset | ||
| 672 | { # basic setting <-----Hier muessen Fehler noch besser abgefangen werden und eine get_funktion aingefügt werden + caching | ||
| 673 | my $self = shift; | ||
| 674 | my ( $x_value, $y_value ) = $self->_check_args( \@_, [ 'X', 'Y' ] ); | ||
| 675 | my @offset; | ||
| 676 | |||
| 677 | if ( $x_value >= -300 || $x_value <= 300 ) { | ||
| 678 | my $cmd = sprintf( "XOF 1 %d", $x_value * 100 ); | ||
| 679 | $self->write($cmd); | ||
| 680 | my @temp = split( /,/, $self->query("XOF") ); | ||
| 681 | $offset[0] = $temp[1] / 100; | ||
| 682 | if ( $offset[0] != $x_value ) { | ||
| 683 | Lab::Exception::CorruptParameter->throw( error => | ||
| 684 | "\nSIGNAL REOCOVERY 726x:\ncouldn't set X chanel output offset" | ||
| 685 | ); | ||
| 686 | } | ||
| 687 | } | ||
| 688 | |||
| 689 | if ( $y_value >= -300 || $y_value <= 300 ) { | ||
| 690 | my $cmd = sprintf( "YOF 1 %d", $y_value * 100 ); | ||
| 691 | $self->write($cmd); | ||
| 692 | my @temp = split( /,/, $self->query("YOF") ); | ||
| 693 | $offset[1] = $temp[1] / 100; | ||
| 694 | if ( $offset[1] != $y_value ) { | ||
| 695 | Lab::Exception::CorruptParameter->throw( error => | ||
| 696 | "\nSIGNAL REOCOVERY 726x:\ncouldn't set Y chanel output offset" | ||
| 697 | ); | ||
| 698 | } | ||
| 699 | } | ||
| 700 | |||
| 701 | if ( $x_value eq 'OFF' ) { | ||
| 702 | $self->write("XOF 0"); | ||
| 703 | my @temp = split( /,/, $self->query("XOF") ); | ||
| 704 | $offset[0] = $temp[0]; | ||
| 705 | if ( $offset[0] != 0 ) { | ||
| 706 | Lab::Exception::CorruptParameter->throw( error => | ||
| 707 | "\nSIGNAL REOCOVERY 726x:\ncouldn't set X chanel output offset" | ||
| 708 | ); | ||
| 709 | } | ||
| 710 | } | ||
| 711 | |||
| 712 | if ( $y_value eq 'OFF' ) { | ||
| 713 | $self->write("YOF 0"); | ||
| 714 | my @temp = split( /,/, $self->query("YOF") ); | ||
| 715 | $offset[1] = $temp[0]; | ||
| 716 | if ( $offset[1] != 0 ) { | ||
| 717 | Lab::Exception::CorruptParameter->throw( error => | ||
| 718 | "\nSIGNAL REOCOVERY 726x:\ncouldn't set Y chanel output offset" | ||
| 719 | ); | ||
| 720 | } | ||
| 721 | } | ||
| 722 | |||
| 723 | if ( $x_value eq 'AUTO' ) { | ||
| 724 | $self->write("AXO"); | ||
| 725 | my @temp = split( /,/, $self->query("XOF") ); | ||
| 726 | $offset[0] = $temp[1]; | ||
| 727 | my @temp = split( /,/, $self->query("YOF") ); | ||
| 728 | $offset[1] = $temp[1]; | ||
| 729 | } | ||
| 730 | |||
| 731 | return @offset; | ||
| 732 | |||
| 733 | } | ||
| 734 | |||
| 735 | # -------------- INTERNAL OSCILLATOR ------------------------------ | ||
| 736 | |||
| 737 | sub set_osc { # basic setting | ||
| 738 | my $self = shift; | ||
| 739 | my ($value) = $self->_check_args( \@_, ['value'] ); | ||
| 740 | |||
| 741 | my $id = $self->query( "ID", { read_mode => "cache" } ); | ||
| 742 | |||
| 743 | if ( index( $value, "u" ) >= 0 ) { | ||
| 744 | $value = int($value) * 1e-6; | ||
| 745 | } | ||
| 746 | elsif ( index( $value, "m" ) >= 0 ) { | ||
| 747 | $value = int($value) * 1e-3; | ||
| 748 | } | ||
| 749 | |||
| 750 | if ( $value >= 0 && $value <= 5 ) { | ||
| 751 | if ( $id == 7260 ) { | ||
| 752 | $self->write( sprintf( "OA %d", sprintf( "%d", $value * 1e3 ) ) ); | ||
| 753 | } | ||
| 754 | elsif ( $id == 7265 ) { | ||
| 755 | $self->write( sprintf( "OA %d", sprintf( "%d", $value * 1e6 ) ) ); | ||
| 756 | } | ||
| 757 | |||
| 758 | } | ||
| 759 | else { | ||
| 760 | Lab::Exception::CorruptParameter->throw( error => | ||
| 761 | "\nSIGNAL REOCOVERY 726x:\n\nSIGNAL REOCOVERY 726x:\nunexpected value for OSCILLATOR OUTPUT in sub set_osc. Expected values must be in the range 0..5V." | ||
| 762 | ); | ||
| 763 | } | ||
| 764 | } | ||
| 765 | |||
| 766 | sub get_osc { | ||
| 767 | my $self = shift; | ||
| 768 | |||
| 769 | my ($tail) = $self->_check_args( \@_ ); | ||
| 770 | |||
| 771 | my $id = $self->query( "ID", { read_mode => "cache" } ); | ||
| 772 | |||
| 773 | my $osc; | ||
| 774 | |||
| 775 | if ( $id == 7260 ) { | ||
| 776 | return $self->query( "OA", $tail ) / 1e3; | ||
| 777 | } | ||
| 778 | elsif ( $id == 7265 ) { | ||
| 779 | return $self->query( "OA", $tail ) / 1e6; | ||
| 780 | } | ||
| 781 | |||
| 782 | } | ||
| 783 | |||
| 784 | sub set_frq { # basic setting | ||
| 785 | my $self = shift; | ||
| 786 | my ($value) = $self->_check_args( \@_, ['value'] ); | ||
| 787 | |||
| 788 | if ( index( $value, "m" ) >= 0 ) { | ||
| 789 | $value = int($value) * 1e-3; | ||
| 790 | } | ||
| 791 | elsif ( index( $value, "k" ) >= 0 ) { | ||
| 792 | $value = int($value) * 1e3; | ||
| 793 | } | ||
| 794 | |||
| 795 | if ( $value > 0 && $value <= 250000 ) { | ||
| 796 | $self->write( sprintf( "OF %d", $value * 1e3 ) ); | ||
| 797 | } | ||
| 798 | else { | ||
| 799 | Lab::Exception::CorruptParameter->throw( error => | ||
| 800 | "\nSIGNAL REOCOVERY 726x:\n\nSIGNAL REOCOVERY 726x:\nunexpected value for OSCILLATOR FREQUENCY in sub set_frq. Expected values must be in the range 0..250kHz" | ||
| 801 | ); | ||
| 802 | } | ||
| 803 | |||
| 804 | } | ||
| 805 | |||
| 806 | sub get_frq { | ||
| 807 | my $self = shift; | ||
| 808 | |||
| 809 | my ($tail) = $self->_check_args( \@_ ); | ||
| 810 | return $self->query( "OF", $tail ) / 1e3; | ||
| 811 | } | ||
| 812 | |||
| 813 | # --------------- INSTRUMENT OUTPUTS ------------------------------ | ||
| 814 | |||
| 815 | sub get_value { # basic | ||
| 816 | my $self = shift; | ||
| 817 | my ( $channel, $read_mode, $tail ) | ||
| 818 | = $self->_check_args( \@_, [ 'channel', 'read_mode' ] ); | ||
| 819 | |||
| 820 | my $result; | ||
| 821 | |||
| 822 | # $channel can be:\n X --> X channel output\n Y --> Y channel output\n MAG --> Magnitude\n PHA --> Signale phase\n XY --> X and Y channel output\n MP --> Magnitude and signal Phase\n ALL --> X,Y, Magnitude and signal Phase\n | ||
| 823 | if ( $channel eq "X" ) { | ||
| 824 | |||
| 825 | if ( $read_mode eq 'cache' | ||
| 826 | and defined $self->{'device_cache'}->{'value'}->{'X'} ) { | ||
| 827 | return $self->{'device_cache'}->{'value'}->{'X'}; | ||
| 828 | } | ||
| 829 | |||
| 830 | $result = $self->query( "X.", $tail ); | ||
| 831 | $result =~ s/\x00//g; | ||
| 832 | $self->{'device_cache'}->{'value'}->{'X'} = $result; | ||
| 833 | return $result; | ||
| 834 | } | ||
| 835 | elsif ( $channel eq "Y" ) { | ||
| 836 | |||
| 837 | if ( $read_mode eq 'cache' | ||
| 838 | and defined $self->{'device_cache'}->{'value'}->{'Y'} ) { | ||
| 839 | return $self->{'device_cache'}->{'value'}->{'Y'}; | ||
| 840 | } | ||
| 841 | |||
| 842 | $result = $self->query( "Y.", $tail ); | ||
| 843 | $result =~ s/\x00//g; | ||
| 844 | $self->{'device_cache'}->{'value'}->{'Y'} = $result; | ||
| 845 | return $result; | ||
| 846 | } | ||
| 847 | elsif ( $channel eq "MAG" ) { | ||
| 848 | |||
| 849 | if ( $read_mode eq 'cache' | ||
| 850 | and defined $self->{'device_cache'}->{'value'}->{'MAG'} ) { | ||
| 851 | return $self->{'device_cache'}->{'value'}->{'MAG'}; | ||
| 852 | } | ||
| 853 | |||
| 854 | $result = $self->query( "MAG.", $tail ); | ||
| 855 | $result =~ s/\x00//g; | ||
| 856 | $self->{'device_cache'}->{'value'}->{'MAG'} = $result; | ||
| 857 | return $result; | ||
| 858 | } | ||
| 859 | elsif ( $channel eq "PHA" ) { | ||
| 860 | |||
| 861 | if ( $read_mode eq 'cache' | ||
| 862 | and defined $self->{'device_cache'}->{'value'}->{'PHA'} ) { | ||
| 863 | return $self->{'device_cache'}->{'value'}->{'PHA'}; | ||
| 864 | } | ||
| 865 | |||
| 866 | $result = $self->query( "PHA.", $tail ); | ||
| 867 | $result =~ s/\x00//g; | ||
| 868 | $self->{'device_cache'}->{'value'}->{'PHA'} = $result; | ||
| 869 | return $result; | ||
| 870 | } | ||
| 871 | elsif ( $channel eq "XY" ) { | ||
| 872 | |||
| 873 | if ( $read_mode eq 'cache' | ||
| 874 | and defined $self->{'device_cache'}->{'value'}->{'X'} | ||
| 875 | and defined $self->{'device_cache'}->{'value'}->{'Y'} ) { | ||
| 876 | return $self->{'device_cache'}->{'value'}; | ||
| 877 | } | ||
| 878 | |||
| 879 | $result = $self->query( "XY.", $tail ); | ||
| 880 | $result =~ s/\x00//g; | ||
| 881 | |||
| 882 | ( | ||
| 883 | $self->{'device_cache'}->{'value'}->{'X'}, | ||
| 884 | $self->{'device_cache'}->{'value'}->{'Y'} | ||
| 885 | ) = split( ",", $result ); | ||
| 886 | |||
| 887 | return $self->{'device_cache'}->{'value'}; | ||
| 888 | } | ||
| 889 | elsif ( $channel eq "MP" ) { | ||
| 890 | |||
| 891 | if ( $read_mode eq 'cache' | ||
| 892 | and defined $self->{'device_cache'}->{'value'}->{'MAG'} | ||
| 893 | and defined $self->{'device_cache'}->{'value'}->{'PHA'} ) { | ||
| 894 | return $self->{'device_cache'}->{'value'}; | ||
| 895 | } | ||
| 896 | |||
| 897 | $result = $self->query( "MP.", $tail ); | ||
| 898 | $result =~ s/\x00//g; | ||
| 899 | ( | ||
| 900 | $self->{'device_cache'}->{'value'}->{'MAG'}, | ||
| 901 | $self->{'device_cache'}->{'value'}->{'PHA'} | ||
| 902 | ) = split( ",", $result ); | ||
| 903 | return $self->{'device_cache'}->{'value'}; | ||
| 904 | } | ||
| 905 | elsif ( $channel eq "ALL" or $channel eq "" ) { | ||
| 906 | |||
| 907 | if ( $read_mode eq 'cache' | ||
| 908 | and defined $self->{'device_cache'}->{'value'}->{'X'} | ||
| 909 | and defined $self->{'device_cache'}->{'value'}->{'Y'} | ||
| 910 | and defined $self->{'device_cache'}->{'value'}->{'MAG'} | ||
| 911 | and defined $self->{'device_cache'}->{'value'}->{'PHA'} ) { | ||
| 912 | return $self->{'device_cache'}->{'value'}; | ||
| 913 | } | ||
| 914 | |||
| 915 | $result = $self->query( "XY.", $tail ) . "," | ||
| 916 | . $self->query( "MP.", $tail ); | ||
| 917 | $result =~ s/\x00//g; | ||
| 918 | ( | ||
| 919 | $self->{'device_cache'}->{'value'}->{'X'}, | ||
| 920 | $self->{'device_cache'}->{'value'}->{'Y'}, | ||
| 921 | $self->{'device_cache'}->{'value'}->{'MAG'}, | ||
| 922 | $self->{'device_cache'}->{'value'}->{'PHA'} | ||
| 923 | ) = split( ",", $result ); | ||
| 924 | return $self->{'device_cache'}->{'value'}; | ||
| 925 | } | ||
| 926 | else { | ||
| 927 | Lab::Exception::CorruptParameter->throw( error => | ||
| 928 | "\nSIGNAL REOCOVERY 726x:\nCHANNEL can be:\n X --> X channel output\n Y --> Y channel output\n MAG --> Magnitude\n PHA --> Signale phase\n XY --> X and Y channel output\n MP --> Magnitude and signal Phase\n ALL --> X,Y, Magnitude and signal Phase\n" | ||
| 929 | ); | ||
| 930 | } | ||
| 931 | } | ||
| 932 | |||
| 933 | sub config_measurement { # basic | ||
| 934 | |||
| 935 | my $self = shift; | ||
| 936 | |||
| 937 | my ( $channel, $nop, $interval, $trigger ) = $self->_check_args( | ||
| 938 | \@_, | ||
| 939 | [ 'channel', 'nop', 'interval', 'trigger' ] | ||
| 940 | ); | ||
| 941 | |||
| 942 | print "--------------------------------------\n"; | ||
| 943 | print "SignalRecovery sub config_measurement:\n"; | ||
| 944 | |||
| 945 | $self->_clear_buffer(); | ||
| 946 | |||
| 947 | # select which data to store in buffer | ||
| 948 | if ( $channel eq "X" ) { $channel = 17; } | ||
| 949 | elsif ( $channel eq "Y" ) { $channel = 18; } | ||
| 950 | elsif ( $channel eq "XY" ) { $channel = 19; } | ||
| 951 | elsif ( $channel eq "MAG" ) { $channel = 20; } | ||
| 952 | elsif ( $channel eq "PHA" ) { $channel = 24; } | ||
| 953 | elsif ( $channel eq "MP" ) { $channel = 28; } | ||
| 954 | elsif ( $channel eq "ALL" ) { $channel = 31; } | ||
| 955 | elsif ( $channel eq "X-" ) { | ||
| 956 | $channel = 1; | ||
| 957 | } # only X channel; Sensitivity not logged --> floating point read out not possible! | ||
| 958 | elsif ( $channel eq "Y-" ) { | ||
| 959 | $channel = 2; | ||
| 960 | } # only Y channel; Sensitivity not logged --> floating point read out not possible! | ||
| 961 | elsif ( $channel eq "XY-" ) { | ||
| 962 | $channel = 3; | ||
| 963 | } # only XY channel; Sensitivity not logged --> floating point read out not possible! | ||
| 964 | elsif ( $channel eq "MAG-" ) { | ||
| 965 | $channel = 4; | ||
| 966 | } # only MAG channel; Sensitivity not logged --> floating point read out not possible! | ||
| 967 | elsif ( $channel eq "PHA-" ) { | ||
| 968 | $channel = 8; | ||
| 969 | } # only PHA channel; Sensitivity not logged --> floating point read out not possible! | ||
| 970 | elsif ( $channel eq "MP-" ) { | ||
| 971 | $channel = 12; | ||
| 972 | } # only MP channel; Sensitivity not logged --> floating point read out not possible! | ||
| 973 | elsif ( $channel eq "ALL-" ) { | ||
| 974 | $channel = 15; | ||
| 975 | } # only XYMP channel; Sensitivity not logged --> floating point read out not possible! | ||
| 976 | else { | ||
| 977 | Lab::Exception::CorruptParameter->throw( error => | ||
| 978 | "\nSIGNAL REOCOVERY 726x:\nunexpected value for DATA CHANNELS in sub config_measurement. Expected values are:\n X --> X channel output\n XY --> X and Y channel output\n MAG --> MAG channel output\n PHA --> PHA channel output\n MP --> MAG and PHA channel output\n ALL --> X,Y, Magnitude and signal Phase\n \n X- --> X channel output without Sensitivity \n XY- --> X and Y channel output without Sensitivity\n MAG- --> MAG channel output without Sensitivity\n PHA- --> PHA channel output without Sensitivity\n MP- --> MAG and PHA channel output without Sensitivity\n ALL- --> X,Y, Magnitude and signal Phase without Sensitivity\n" | ||
| 979 | ); | ||
| 980 | } | ||
| 981 | $self->_set_buffer_datachannels($channel); | ||
| 982 | |||
| 983 | print "SIGNAL REOCOVERY 726x: set channels: " | ||
| 984 | . $self->_set_buffer_datachannels($channel); | ||
| 985 | |||
| 986 | # set buffer size | ||
| 987 | print "SIGNAL REOCOVERY 726x: set buffer length: " | ||
| 988 | . $self->_set_buffer_length($nop); | ||
| 989 | |||
| 990 | # set measuremnt interval | ||
| 991 | if ( not defined $interval ) { | ||
| 992 | $interval = $self->set_tc(); | ||
| 993 | } | ||
| 994 | print "SIGNAL REOCOVERY 726x: set storage interval: " | ||
| 995 | . $self->_set_buffer_storageinterval($interval) . "\n"; | ||
| 996 | |||
| 997 | if ( $trigger eq "EXT" ) { | ||
| 998 | $self->write("TDT"); | ||
| 999 | usleep(1e6); | ||
| 1000 | } | ||
| 1001 | |||
| 1002 | print "SignalRecovery config_measurement complete\n"; | ||
| 1003 | print "--------------------------------------\n"; | ||
| 1004 | |||
| 1005 | } | ||
| 1006 | |||
| 1007 | sub get_data { # basic | ||
| 1008 | |||
| 1009 | my $self = shift; | ||
| 1010 | |||
| 1011 | my ( $SEN, $timeout ) = $self->_check_args( \@_, [ 'SEN', 'timeout' ] ); | ||
| 1012 | |||
| 1013 | my @dummy; | ||
| 1014 | my @data; | ||
| 1015 | my %channel_list = ( | ||
| 1016 | 1 => "0", | ||
| 1017 | 2 => "1", | ||
| 1018 | 3 => "0,1", | ||
| 1019 | 4 => "2", | ||
| 1020 | 8 => "3", | ||
| 1021 | 12 => "2,3", | ||
| 1022 | 15 => "0,1,2,3", | ||
| 1023 | 17 => "0", | ||
| 1024 | 18 => "1", | ||
| 1025 | 19 => "0,1", | ||
| 1026 | 20 => "2", | ||
| 1027 | 24 => "3", | ||
| 1028 | 28 => "2,3", | ||
| 1029 | 31 => "0,1,2,3" | ||
| 1030 | ); | ||
| 1031 | |||
| 1032 | # it takes approx. 4ms per datapoint; 25k-Points --> 100sec | ||
| 1033 | |||
| 1034 | # reduce Time-Out for READ | ||
| 1035 | if ( not defined $timeout ) { | ||
| 1036 | $timeout = 100; | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | my $status = Lab::VISA::viSetAttribute( | ||
| 1040 | $self->{vi}->{instr}, | ||
| 1041 | $Lab::VISA::VI_ATTR_TMO_VALUE, $timeout | ||
| 1042 | ); | ||
| 1043 | if ( $status != $Lab::VISA::VI_SUCCESS ) { | ||
| 1044 | Lab::Exception::CorruptParameter->throw( | ||
| 1045 | error => "Error while setting baud: $status" ); | ||
| 1046 | } | ||
| 1047 | |||
| 1048 | my @channels = split( ",", $channel_list{ int( $self->query("CBD") ) } ); | ||
| 1049 | |||
| 1050 | #if ($channels == 17) { $channels = 1; } | ||
| 1051 | #elsif ($channels == 19) { $channels = 2; } | ||
| 1052 | #elsif ($channels == 31) { $channels = 4; } | ||
| 1053 | |||
| 1054 | $self->wait(); # wait until active sweep has been finished | ||
| 1055 | |||
| 1056 | foreach my $i (@channels) { | ||
| 1057 | if ( defined $SEN and $SEN >= 2e-15 and $SEN <= 1 ) { | ||
| 1058 | $self->write( sprintf( "DC %d", $i ) ); | ||
| 1059 | my @temp; | ||
| 1060 | my $data; | ||
| 1061 | |||
| 1062 | while (1) { | ||
| 1063 | eval '$self->read(100)*$SEN*0.01'; | ||
| 1064 | if ( $@ =~ /(Error while reading:)/ ) { last; } | ||
| 1065 | push( @temp, $data ); | ||
| 1066 | } | ||
| 1067 | push( @data, \@temp ); | ||
| 1068 | |||
| 1069 | } | ||
| 1070 | else { | ||
| 1071 | $self->write( sprintf( "DC. %d", $i ) ); | ||
| 1072 | my @temp; | ||
| 1073 | my $data; | ||
| 1074 | |||
| 1075 | while (1) { | ||
| 1076 | eval '$data = $self->read(100)'; | ||
| 1077 | if ( $@ =~ /(Error while reading:)/ ) { last; } | ||
| 1078 | push( @temp, $data ); | ||
| 1079 | } | ||
| 1080 | push( @data, \@temp ); | ||
| 1081 | } | ||
| 1082 | |||
| 1083 | } | ||
| 1084 | |||
| 1085 | # set Time-Out for READ back to default value | ||
| 1086 | my $status = Lab::VISA::viSetAttribute( | ||
| 1087 | $self->{vi}->{instr}, | ||
| 1088 | $Lab::VISA::VI_ATTR_TMO_VALUE, 3000 | ||
| 1089 | ); | ||
| 1090 | if ( $status != $Lab::VISA::VI_SUCCESS ) { | ||
| 1091 | Lab::Exception::CorruptParameter->throw( | ||
| 1092 | error => "Error while setting baud: $status" ); | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | return @data; | ||
| 1096 | |||
| 1097 | } | ||
| 1098 | |||
| 1099 | sub trg { # basic | ||
| 1100 | my $self = shift; | ||
| 1101 | $self->write("TD"); | ||
| 1102 | } | ||
| 1103 | |||
| 1104 | sub abort { # basic | ||
| 1105 | |||
| 1106 | my $self = shift; | ||
| 1107 | |||
| 1108 | $self->write("HC"); | ||
| 1109 | |||
| 1110 | } | ||
| 1111 | |||
| 1112 | sub active { | ||
| 1113 | my $self = shift; | ||
| 1114 | |||
| 1115 | my @status = split( ",", $self->query("M") ); | ||
| 1116 | if ( $status[0] == 0 ) { | ||
| 1117 | return 0; | ||
| 1118 | } | ||
| 1119 | else { | ||
| 1120 | return 1; | ||
| 1121 | } | ||
| 1122 | |||
| 1123 | } | ||
| 1124 | |||
| 1125 | sub wait { | ||
| 1126 | my $self = shift; | ||
| 1127 | |||
| 1128 | while (1) { | ||
| 1129 | usleep(1e3); | ||
| 1130 | my @status = split( ",", $self->query("M") ); | ||
| 1131 | if ( $status[0] == 0 ) { last; } | ||
| 1132 | } | ||
| 1133 | return 0; | ||
| 1134 | } | ||
| 1135 | |||
| 1136 | # --------------- DISPLAY ------------------------------ | ||
| 1137 | |||
| 1138 | sub display_on { # basic setting | ||
| 1139 | |||
| 1140 | my $self = shift; | ||
| 1141 | $self->write("LTS 1"); | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | sub display_off { # basic setting | ||
| 1145 | |||
| 1146 | my $self = shift; | ||
| 1147 | $self->write("LTS 0"); | ||
| 1148 | } | ||
| 1149 | |||
| 1150 | # --------------- OUTPUT DATA CURVE BUFFER ------------------------- | ||
| 1151 | |||
| 1152 | sub _clear_buffer { # internal / advanced use only | ||
| 1153 | |||
| 1154 | my $self = shift; | ||
| 1155 | |||
| 1156 | $self->write("NC"); | ||
| 1157 | |||
| 1158 | } | ||
| 1159 | |||
| 1160 | sub _set_buffer_datachannels { # internal / advanced use only | ||
| 1161 | |||
| 1162 | my $self = shift; | ||
| 1163 | my ($value) = $self->_check_args( \@_, ['value'] ); | ||
| 1164 | |||
| 1165 | if ( not defined $value ) { | ||
| 1166 | return $self->query("CBD"); | ||
| 1167 | } | ||
| 1168 | |||
| 1169 | $self->write( sprintf( "CBD %d", $value ) ); | ||
| 1170 | return $self->query("CBD"); | ||
| 1171 | } | ||
| 1172 | |||
| 1173 | sub _set_buffer_length { # internal / advanced use only | ||
| 1174 | |||
| 1175 | my $self = shift; | ||
| 1176 | my ($nop) = $self->_check_args( \@_, ['nop'] ); | ||
| 1177 | |||
| 1178 | if ( not defined $nop ) { | ||
| 1179 | return $self->query("LEN"); | ||
| 1180 | } | ||
| 1181 | |||
| 1182 | # get number of channels to be stored | ||
| 1183 | my $channels = $self->query("CBD"); | ||
| 1184 | if ( $channels == 17 ) { $channels = 2; } | ||
| 1185 | elsif ( $channels == 19 ) { $channels = 3; } | ||
| 1186 | elsif ( $channels == 31 ) { $channels = 5; } | ||
| 1187 | |||
| 1188 | # check buffer size | ||
| 1189 | if ( $nop > int( 32000 / $channels ) ) { | ||
| 1190 | Lab::Exception::CorruptParameter->throw( error => | ||
| 1191 | "\nSIGNAL REOCOVERY 726x:\n\nSIGNAL REOCOVERY 726x:\ncan't init BUFFER. Buffersize is too small for the given NUMBER OF POINTS and NUMBER OF CHANNELS to store.\n POINTS x (CHANNELS+1) cant exceed 32000.\n" | ||
| 1192 | ); | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | $self->write( sprintf( "LEN %d", $nop ) ); | ||
| 1196 | return my $return = $self->query("LEN"); | ||
| 1197 | |||
| 1198 | } | ||
| 1199 | |||
| 1200 | sub _set_buffer_storageinterval { # internal / advanced use only | ||
| 1201 | |||
| 1202 | my $self = shift; | ||
| 1203 | my ($interval) = $self->_check_args( \@_, ['value'] ); | ||
| 1204 | |||
| 1205 | if ( not defined $interval ) { | ||
| 1206 | return $self->query("STR") / 1e3; | ||
| 1207 | } | ||
| 1208 | |||
| 1209 | if ( $interval < 5e-3 or $interval > 1e6 ) { | ||
| 1210 | Lab::Exception::CorruptParameter->throw( error => | ||
| 1211 | "\nSIGNAL REOCOVERY 726x:\nunexpected value for INTERVAL in sub set_buffer_interval. Expected values are between 5ms...1E6s with a resolution of 5ms." | ||
| 1212 | ); | ||
| 1213 | } | ||
| 1214 | |||
| 1215 | $self->write( sprintf( "STR %d", $interval * 1e3 ) ); | ||
| 1216 | |||
| 1217 | return $self->query("STR") / 1e3; | ||
| 1218 | |||
| 1219 | } | ||
| 1220 | |||
| 1221 | 1; | ||
| 1222 | |||
| 1223 | __END__ |