Moose/Instrument/Zhinst.pm

filter: Statementstmt 96.1% 50 / 52 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 4 / 4 totaltotal 94.4% 68 / 72 SCAR 11.0
CC
3
Cov
93%
_get_device
3.2
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« Moose/Instrument/SCPI/Sense/Impedance.pm ↑ Summary Moose/Instrument/SCPI/Sense/Frequency.pm »
1 package Lab::Moose::Instrument::Zhinst;
2 3 $Lab::Moose::Instrument::Zhinst::VERSION = '3.881';
3 #ABSTRACT: Base class for Zurich Instruments device drivers
4  
5 3 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use MooseX::Params::Validate qw/validated_list validated_hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # do not make imported functions available as methods.
12 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use YAML::XS 'Dump';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # FIXME: put this into separate module?
16 use constant {
17 3 ZI_LIST_NODES_RECURSIVE => 1,
18 ZI_LIST_NODES_ABSOLUTE => 2,
19 3 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 extends 'Lab::Moose::Instrument';
22  
23 3 has device => (
24 is => 'ro',
25 isa => 'Str',
26 builder => '_get_device',
27 lazy => 1,
28 );
29  
30  
31 sub _get_device {
32 2 ▶ my $self = shift;
Subroutine _get_device: called CC=3 SCAR=11.5
33  
34 2 my $nodes = $self->list_nodes(
35 path => '/',
36 mask => ZI_LIST_NODES_ABSOLUTE | ZI_LIST_NODES_RECURSIVE
37 );
38  
39 2 my @devices = $nodes =~ m{^/dev\w*}gmi;
40 2 my %hash = map { $_ => 1 } @devices;
41 2 @devices = keys %hash;
42 2 ▶ if ( @devices == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@devices == 0) 0 2 2
43 0 croak "no connected devices";
44 }
45 2 ▶ if ( @devices > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@devices > 1) 0 2 2
46 0 croak
47 "found multiple devices: @devices. Give explicit device argument.";
48 }
49 2 return $devices[0];
50 }
51  
52  
53 sub list_nodes {
54 2 ▶ my ( $self, %args ) = validated_hash(
Subroutine list_nodes: called CC=1 SCAR=0.0
Pod documented
55 \@_,
56  
57 # Proper validation is done in Connection::Zhinst.
58 path => { isa => 'Str' },
59 mask => { isa => 'Int' },
60 );
61  
62 2 $args{method} = 'ListNodes';
63 2 my $command = Dump( \%args );
64 2 return $self->binary_query( command => $command );
65 }
66  
67  
68 sub get_value {
69 3 ▶ my ( $self, %args ) = validated_hash(
Subroutine get_value: called CC=1 SCAR=0.0
Pod documented
70 \@_,
71 path => { isa => 'Str' },
72 type => { isa => 'Str' },
73 );
74  
75 3 $args{method} = 'Get';
76 3 my $command = Dump( \%args );
77 3 return $self->binary_query( command => $command );
78 }
79  
80  
81 sub sync_set_value {
82 2 ▶ my ( $self, %args ) = validated_hash(
Subroutine sync_set_value: called CC=1 SCAR=0.0
Pod documented
83 \@_,
84 path => { isa => 'Str' },
85 type => { isa => 'Str' },
86 value => { isa => 'Str' },
87 );
88  
89 2 $args{method} = 'SyncSet';
90 2 my $command = Dump( \%args );
91 2 return $self->binary_query( command => $command );
92 }
93  
94  
95 sub sync_poll {
96 1 ▶ my ( $self, %args ) = validated_hash(
Subroutine sync_poll: called CC=1 SCAR=0.0
Pod documented
97 \@_,
98 path => { isa => 'Str' },
99 timeout => { isa => 'Num', optional => 1 },
100 );
101 1 $args{method} = 'SyncPoll';
102 1 my $command = Dump( \%args );
103 1 return $self->binary_query( command => $command );
104 }
105  
106 3 __PACKAGE__->meta->make_immutable();
107  
108 3 1;
109  
110 __END__
111  
112 =pod
113  
114 =encoding UTF-8
115  
116 =head1 NAME
117  
118 Lab::Moose::Instrument::Zhinst - Base class for Zurich Instruments device drivers
119  
120 =head1 VERSION
121  
122 version 3.881
123  
124 =head1 METHODS
125  
126 =head2 list_nodes
127  
128 my $nodes = $instr->list_nodes(path => $path, mask => $mask);
129  
130 Call L<Lab::Zhinst> ListNodes method.
131  
132 =head2 get_value
133  
134 my $filter_order = $instr->get_value(path => "$device/demods/0/order", type => 'I');
135 my $demod_hash = $instr->get_value(path => "$device/demods/0/sample", type => 'DemodSample');
136  
137 Call L<Lab::Zhinst> Get* method.
138 Supported values for the C<$type> argument: I (integer), D (double), B (byte
139 array), Demod, DIO, AuxIn.
140  
141 =head2 sync_set_value
142  
143 my $set_tc = $instr->sync_set_value(
144 path => "$device/demods/0/timeconstant",
145 type => 'D',
146 value => '1.1',
147 );
148  
149 Call L<Lab::Zhinst> SyncSet* method. Supported values for C<$type>: I, D, B.
150  
151 =head2 sync_poll
152  
153 my $sample = $instr->sync_poll(
154 path => "$device/imps/0/sample",
155 timeout => 0.1,
156 );
157  
158 Poll event and return the most recent value in the event. Before doing the
159 poll, flush the event queque with a Sync to ensure that we get a newly recorded
160 event.
161  
162 =head1 COPYRIGHT AND LICENSE
163  
164 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
165  
166 Copyright 2017 Andreas K. Huettel, Simon Reinhardt
167 2020 Andreas K. Huettel
168  
169  
170 This is free software; you can redistribute it and/or modify it under
171 the same terms as the Perl 5 programming language system itself.
172  
173 =cut
« Moose/Instrument/SCPI/Sense/Impedance.pm ↑ Summary Moose/Instrument/SCPI/Sense/Frequency.pm »