lab-measurement / Lab-Measurement

Lab::Measurement allows to perform test and measurement tasks with Perl scripts.
https://www.labmeasurement.de/
Other
10 stars 12 forks source link

Lab::Moose::Instrument::SCPIBlock set_data_format_precision query before setting #19

Closed evgmik closed 6 years ago

evgmik commented 6 years ago

Hi, I am looking at I am looking at sub set_data_format_precision in Lab::Moose::Instrument::SCPIBlock inside there are the following lines

    my $precision = delete $args{precision};                                                   
    my $length    = $precision eq 'single' ? 32 : 64;                                          
    my $format    = $self->cached_format_data();                                               

    if ( $format->[0] ne 'REAL' || $format->[1] != $length ) {                                 
        carp "setting data format: REAL, $length";                                             
        $self->format_data( format => 'REAL', length => $length );                             
    }

note the call for $self->cached_format_data(); in the 3rd line. Consequently setter refuses to change format if it does not coincide with what already set. Is it a bug or I missing some deep logic?

amba commented 6 years ago

Hi @evgmik,

The use of cached_format_data and the if-condition is a performance optimization with the objective to only perform a write command if the format needs to be changed. So, format_data is only called if the cached value and the supplied function argument are not equal (ne is used to test strings for inequality; != is used to test numeric values for inequality).

Best, Simon