Moose/Instrument/OI_Common.pm

filter: Statementstmt 75.5% 37 / 49 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 10 / 12 Podpod 75.0% 3 / 4 totaltotal 75.3% 52 / 69 SCAR 11.5
CC
3
Cov
74%
_parse_setter_retval
2.1
_parse_getter_retval
2.1
get_temperature_channel
2.0
CRAP 3.2
« Instrument/TemperatureControl.pm ↑ Summary Moose/Instrument/HP34410A.pm »
1 package Lab::Moose::Instrument::OI_Common;
2 2 $Lab::Moose::Instrument::OI_Common::VERSION = '3.881';
3 #ABSTRACT: Role for handling Oxfords Instruments pseudo-SCPI commands
4  
5 2 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Lab::Moose::Instrument qw/validated_getter validated_setter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 sub get_temperature_channel {
16 0 ▶ my ( $self, %args ) = validated_getter(
Subroutine get_temperature_channel: not called CC=1 SCAR=6.9
Pod undocumented
17 \@_,
18 channel => { isa => 'Str' }
19 );
20  
21 0 my $channel = delete $args{channel};
22  
23 0 my $rv
24 = $self->oi_getter( cmd => "READ:DEV:$channel:TEMP:SIG:TEMP", %args );
25 0 $rv =~ s/K.*$//;
26 0 return $rv;
27 }
28  
29 sub get_temperature_channel_resistance {
30 0 ▶ my ( $self, %args ) = validated_getter(
Subroutine get_temperature_channel_resistance: not called CC=1 SCAR=6.9
Pod documented
31 \@_,
32 channel => { isa => 'Str' }
33 );
34  
35 0 my $channel = delete $args{channel};
36  
37 0 my $rv
38 = $self->oi_getter( cmd => "READ:DEV:$channel:TEMP:SIG:RES", %args );
39 0 $rv =~ s/Ohm.*$//;
40 0 return $rv;
41 }
42  
43 sub _parse_setter_retval {
44 6 ▶ my $self = shift;
Subroutine _parse_setter_retval: called CC=2 SCAR=7.2
45 6 my ( $header, $retval ) = @_;
46  
47 6 $header = 'STAT:' . $header;
48 6 ▶ if ( $retval !~ /^\Q$header\E:([^:]+):VALID$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($retval =~ /^\Q$header\E:([^:]+):VALID$/u) 0 6 6
49 0 croak "Invalid return value of setter for header $header:\n $retval";
50 }
51 6 return $1;
52 }
53  
54 sub _parse_getter_retval {
55 11 ▶ my $self = shift;
Subroutine _parse_getter_retval: called CC=2 SCAR=7.2
56 11 my ( $header, $retval ) = @_;
57  
58 11 $header =~ s/^READ:/STAT:/;
59  
60 11 ▶ if ( $retval !~ /^\Q$header\E:(.+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($retval =~ /^\Q$header\E:(.+)/u) 0 11 11
61 0 croak "Invalid return value of getter for header $header:\n $retval";
62 }
63 11 return $1;
64 }
65  
66  
67 sub oi_getter {
68 11 ▶ my ( $self, %args ) = validated_getter(
Subroutine oi_getter: called CC=1 SCAR=0.0
Pod documented
69 \@_,
70 cmd => { isa => 'Str' }
71 );
72 11 my $cmd = delete $args{cmd};
73 11 my $rv = $self->query( command => $cmd, %args );
74 11 return $self->_parse_getter_retval( $cmd, $rv );
75 }
76  
77  
78 sub oi_setter {
79 6 ▶ my ( $self, $value, %args ) = validated_setter(
Subroutine oi_setter: called CC=1 SCAR=0.0
Pod documented
80 \@_,
81 cmd => { isa => 'Str' }
82 );
83 6 my $cmd = delete $args{cmd};
84 6 my $rv = $self->query( command => "$cmd:$value", %args );
85 6 return $self->_parse_setter_retval( $cmd, $rv );
86 }
87  
88 2 1;
89  
90 __END__
91  
92 =pod
93  
94 =encoding UTF-8
95  
96 =head1 NAME
97  
98 Lab::Moose::Instrument::OI_Common - Role for handling Oxfords Instruments pseudo-SCPI commands
99  
100 =head1 VERSION
101  
102 version 3.881
103  
104 =head1 DESCRIPTION
105  
106 =head1 METHODS
107  
108 =head2 get_temperature
109  
110 $t = $m->get_temperature_channel(channel => 'MB1.T1');
111  
112 Read out the designated temperature channel. The result is in Kelvin.
113  
114 =head2 get_temperature_channel_resistance
115  
116 $r = $m->get_temperature_channel_resistance(channel => 'MB1.T1');
117  
118 Read out the designated temperature channel resistance. The result is in Ohm.
119  
120 =head2 oi_getter
121  
122 my $current = $self->oi_getter(cmd => "READ:DEV:$channel:PSU:SIG:CURR", %args);
123 $current =~ s/A$//;
124  
125 Perform query with I<READ:*> command and parse return value.
126  
127 =head2 oi_setter
128  
129 $self->oi_setter(
130 cmd => "SET:DEV:$channel:PSU:SIG:SWHT",
131 value => $value,
132 %args);
133  
134 Perform set/query with I<SET:*> command and parse return value.
135  
136 =head1 COPYRIGHT AND LICENSE
137  
138 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
139  
140 Copyright 2018 Andreas K. Huettel, Simon Reinhardt
141 2019 Simon Reinhardt
142 2020 Andreas K. Huettel
143  
144  
145 This is free software; you can redistribute it and/or modify it under
146 the same terms as the Perl 5 programming language system itself.
147  
148 =cut
« Instrument/TemperatureControl.pm ↑ Summary Moose/Instrument/HP34410A.pm »