File Coverage

blib/lib/Lab/Moose/Instrument/Zhinst.pm
Criterion Covered Total %
statement 45 47 95.7
branch 2 4 50.0
condition n/a
subroutine 12 12 100.0
pod 4 4 100.0
total 63 67 94.0


line stmt bran cond sub pod time code
1             package Lab::Moose::Instrument::Zhinst;
2             $Lab::Moose::Instrument::Zhinst::VERSION = '3.880';
3             #ABSTRACT: Base class for Zurich Instruments device drivers
4              
5 3     3   1912 use v5.20;
  3         12  
6              
7 3     3   18 use Moose;
  3         7  
  3         19  
8 3     3   20202 use MooseX::Params::Validate qw/validated_list validated_hash/;
  3         11  
  3         23  
9 3     3   966 use Carp;
  3         6  
  3         210  
10              
11             # do not make imported functions available as methods.
12 3     3   27 use namespace::autoclean;
  3         9  
  3         20  
13 3     3   279 use YAML::XS 'Dump';
  3         13  
  3         223  
14              
15             # FIXME: put this into separate module?
16             use constant {
17 3         2003 ZI_LIST_NODES_RECURSIVE => 1,
18             ZI_LIST_NODES_ABSOLUTE => 2,
19 3     3   20 };
  3         6  
20              
21             extends 'Lab::Moose::Instrument';
22              
23             has device => (
24             is => 'ro',
25             isa => 'Str',
26             builder => '_get_device',
27             lazy => 1,
28             );
29              
30              
31             sub _get_device {
32 2     2   6 my $self = shift;
33              
34 2         14 my $nodes = $self->list_nodes(
35             path => '/',
36             mask => ZI_LIST_NODES_ABSOLUTE | ZI_LIST_NODES_RECURSIVE
37             );
38              
39 2         500 my @devices = $nodes =~ m{^/dev\w*}gmi;
40 2         16 my %hash = map { $_ => 1 } @devices;
  834         1300  
41 2         79 @devices = keys %hash;
42 2 50       11 if ( @devices == 0 ) {
43 0         0 croak "no connected devices";
44             }
45 2 50       15 if ( @devices > 1 ) {
46 0         0 croak
47             "found multiple devices: @devices. Give explicit device argument.";
48             }
49 2         96 return $devices[0];
50             }
51              
52              
53             sub list_nodes {
54 2     2 1 14 my ( $self, %args ) = validated_hash(
55             \@_,
56              
57             # Proper validation is done in Connection::Zhinst.
58             path => { isa => 'Str' },
59             mask => { isa => 'Int' },
60             );
61              
62 2         1417 $args{method} = 'ListNodes';
63 2         189 my $command = Dump( \%args );
64 2         33 return $self->binary_query( command => $command );
65             }
66              
67              
68             sub get_value {
69 3     3 1 20 my ( $self, %args ) = validated_hash(
70             \@_,
71             path => { isa => 'Str' },
72             type => { isa => 'Str' },
73             );
74              
75 3         1533 $args{method} = 'Get';
76 3         151 my $command = Dump( \%args );
77 3         22 return $self->binary_query( command => $command );
78             }
79              
80              
81             sub sync_set_value {
82 2     2 1 33 my ( $self, %args ) = validated_hash(
83             \@_,
84             path => { isa => 'Str' },
85             type => { isa => 'Str' },
86             value => { isa => 'Str' },
87             );
88              
89 2         1964 $args{method} = 'SyncSet';
90 2         134 my $command = Dump( \%args );
91 2         17 return $self->binary_query( command => $command );
92             }
93              
94              
95             sub sync_poll {
96 1     1 1 9 my ( $self, %args ) = validated_hash(
97             \@_,
98             path => { isa => 'Str' },
99             timeout => { isa => 'Num', optional => 1 },
100             );
101 1         644 $args{method} = 'SyncPoll';
102 1         52 my $command = Dump( \%args );
103 1         13 return $self->binary_query( command => $command );
104             }
105              
106             __PACKAGE__->meta->make_immutable();
107              
108             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.880
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