Moose/Instrument/SCPI/Format.pm

filter: Statementstmt 89.7% 35 / 39 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 4 / 4 totaltotal 87.7% 50 / 57 SCAR 11.1
CC
3
Cov
86%
format_data_query
2.1
format_data
2.0
format_border
2.0
CRAP 3.0
« Moose/Instrument/KeysightN9310A.pm ↑ Summary Moose/Instrument/RS_ZVA.pm »
1 package Lab::Moose::Instrument::SCPI::Format;
2 4 $Lab::Moose::Instrument::SCPI::Format::VERSION = '3.881';
3 #ABSTRACT: Role for SCPI FORMat subsystem.
4  
5 4 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Lab::Moose::Instrument qw/setter_params getter_params validated_getter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Lab::Moose::Instrument::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 4 cache format_data => ( getter => 'format_data_query' );
15  
16 sub format_data_query {
17 3 ▶ my ( $self, %args ) = validated_getter( \@_ );
Subroutine format_data_query: called CC=2 SCAR=7.4
Pod documented
18  
19 3 my $format = $self->query( command => 'FORM?', %args );
20  
21 3 ▶ if ( $format !~ /^(?<format>\w+)(,\+?(?<length>\d+))?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($format =~ /^(?<format>\w+)(,\+?(?<length>\d+))?$/u) 0 3 3
22 0 croak "illegal value of DATA:FORMat: $format";
23 }
24  
25 3 return $self->cached_format_data( [ $+{format}, $+{length} ] );
26 }
27  
28 sub format_data {
29 3 ▶ my ( $self, %args ) = validated_hash(
Subroutine format_data: called CC=2 SCAR=7.0
Pod documented
30 \@_,
31 setter_params(),
32 format => { isa => 'Str' },
33 length => { isa => 'Int', optional => 1 },
34 );
35  
36 3 my $format = delete $args{format};
37 3 my $length = delete $args{length};
38 3 my $command = "FORM $format";
39 3 ▶ if ( defined $length ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length) 3 0 3
40 3 $command .= ", $length";
41 }
42  
43 3 $self->write( command => $command, %args );
44  
45 3 return $self->cached_format_data( [ $format, $length ] );
46 }
47  
48  
49 4 cache format_border => ( getter => 'format_border_query' );
50  
51 sub format_border_query {
52 1 ▶ my ( $self, %args ) = validated_getter( \@_ );
Subroutine format_border_query: called CC=1 SCAR=0.0
Pod documented
53  
54 1 return $self->cached_format_border(
55 $self->query( command => 'FORM:BORD?', %args ) );
56 }
57  
58 sub format_border {
59 0 ▶ my ( $self, $value, %args ) = validated_setter( \@_ );
Subroutine format_border: not called CC=1 SCAR=6.9
Pod documented
60  
61 0 $self->write( command => "FORM:BORD $value", %args );
62 0 return $self->cached_format_border($value);
63 }
64  
65 4 1;
66  
67 __END__
68  
69 =pod
70  
71 =encoding UTF-8
72  
73 =head1 NAME
74  
75 Lab::Moose::Instrument::SCPI::Format - Role for SCPI FORMat subsystem.
76  
77 =head1 VERSION
78  
79 version 3.881
80  
81 =head1 METHODS
82  
83 =head2 format_data_query
84  
85 =head2 format_data
86  
87 # set to binary single precision
88 $instr->format_data(format => 'REAL', length => 32);
89  
90 # set to binary double precision
91 $instr->format_data(format => 'REAL', length => 64);
92  
93 # set to ASCII, 10 significant digits
94 $instr->format_data(format => 'ASC', length => 10);
95  
96 my $format = $instr->cached_format_data();
97 print "format: $format->[0], len: $format->[1]\n";
98  
99 Set/Get data format.
100  
101 =head2 format_border_query
102  
103 =head2 format_border
104  
105 $instr->format_border(value => 'NORM'); # or 'SWAP'
106  
107 Set/Get byte order of transferred data. Normally you want 'SWAP'
108 (little-endian), which is the native machine format of the measurement PC.
109  
110 =head1 COPYRIGHT AND LICENSE
111  
112 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
113  
114 Copyright 2016 Simon Reinhardt
115 2017 Andreas K. Huettel, Simon Reinhardt
116 2018 Simon Reinhardt
117 2020 Andreas K. Huettel, Sam Bingner
118  
119  
120 This is free software; you can redistribute it and/or modify it under
121 the same terms as the Perl 5 programming language system itself.
122  
123 =cut
« Moose/Instrument/KeysightN9310A.pm ↑ Summary Moose/Instrument/RS_ZVA.pm »