Bus/DEBUG.pm

filter: Statementstmt 43.5% 57 / 131 Branchbran 11.5% 3 / 26 Conditioncond 2.7% 1 / 36 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 76.4% 13 / 17 Podpod 66.6% 4 / 6 totaltotal 32.6% 78 / 239 SCAR 55.6
CC
27
Cov
32%
connection_write
110.0
connection_read
72.0
connection_query
56.0
CRAP 260.2
« Instrument/TCD.pm ↑ Summary Moose/Connection/Zhinst.pm »
1 package Lab::Bus::DEBUG;
2 #ABSTRACT: Interactive debug bus
3 3 $Lab::Bus::DEBUG::VERSION = '3.881';
4 3 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Time::HiRes qw (usleep sleep);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Lab::Bus;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use Lab::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 ▶use parent 'Lab::Bus';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 3 our %fields = (
20 brutal => 0, # brutal as default?
21 type => 'DEBUG',
22 wait_status => 10e-6, # sec;
23 wait_query => 10e-6, # sec;
24 query_length => 300, # bytes
25 query_long_length => 10240, #bytes
26 read_length => 1000, # bytesx
27 instrument_index => 0,
28 );
29  
30 sub new {
31 2 ▶ my $proto = shift;
Subroutine new: called CC=4 SCAR=14.5
Pod documented
32 2 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
33 2 my $twin = undef;
34 2 my $self = $class->SUPER::new(@_)
35 ; # getting fields and _permitted from parent class
36 2 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
37  
38 # no twin search - just register
39 2 ▶ if ( $class eq __PACKAGE__ )
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 2 0 2
40 { # careful - do only if this is not a parent class constructor
41 2 my $i = 0;
42 2 ▶ while ( defined $Lab::Bus::BusList{ $self->type() }->{$i} ) { $i++; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Lab::Bus::BusList{$self->type}{$i}) 0 2 2
43 2 $Lab::Bus::BusList{ $self->type() }->{$i} = $self;
44 2 weaken( $Lab::Bus::BusList{ $self->type() }->{$i} );
45 }
46  
47 2 return $self;
48 }
49  
50 sub connection_new { # @_ = ({ resource_name => $resource_name })
51 2 ▶ my $self = shift;
Subroutine connection_new: called CC=2 SCAR=7.0
Pod documented
52 2 my $args = undef;
53 2 my $status = undef;
54 2 my $connection_handle = undef;
55 2 ▶ if ( ref $_[0] eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 2 0 2
56 2 $args = shift;
57 } # try to be flexible about options as hash/hashref
58 0 else { $args = {@_} }
59  
60 2 $connection_handle = { debug_instr_index => $self->instrument_index() };
61  
62 2 $self->instrument_index( $self->instrument_index() + 1 );
63  
64 2 return $connection_handle;
65 }
66  
67 sub connection_read
68 { # @_ = ( $connection_handle, $args = { read_length, brutal }
69 0 ▶ my $self = shift;
Subroutine connection_read: not called CC=8 SCAR=42.8
Pod documented
70 0 my $connection_handle = shift;
71 0 my $args = undef;
72 0 ▶ if ( ref $_[0] eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
73 0 $args = shift;
74 } # try to be flexible about options as hash/hashref
75 0 else { $args = {@_} }
76  
77 0 ▶ my $command = $args->{'command'} || undef;
Condition0%0/2
$args->{'command'} || undef
l!l
00
MC/DC0%0/1
$args->{'command'} || undef
$args->{'command'}
Truth table0%0/2
A
A= $args->{'command'}
Aresult
11
00
78 0 ▶ my $brutal = $args->{'brutal'} || $self->brutal();
Condition0%0/3
$args->{'brutal'} || $self->brutal
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'brutal'} || $self->brutal
$args->{'brutal'} $self->brutal
Truth table0%0/3
A || B
A= $args->{'brutal'}B= $self->brutal
ABresult
1X1
011
000
79 0 ▶ my $read_length = $args->{'read_length'} || $self->read_length();
Condition0%0/3
$args->{'read_length'} || $self->read_length
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'read_length'} || $self->read_length
$args->{'read_length'} $self->read_length
Truth table0%0/3
A || B
A= $args->{'read_length'}B= $self->read_length
ABresult
1X1
011
000
80  
81 0 my $result = undef;
82 0 my $user_status = undef;
83 0 my $message = "";
84  
85 0 my $brutal_txt = 'false';
86 0 ▶ $brutal_txt = 'true' if $brutal;
Branch: 1 branch
BranchTrueFalseTotal
if $brutal 0 0 0
87  
88 0 ( $message = <<ENDMSG ) =~ s/^\t+//gm;
89  
90  
91 DEBUG bus
92 connection_read called on Instrument No. $connection_handle->{'debug_instr_index'}
93 Brutal: $brutal_txt
94 Read length: $read_length
95  
96 Enter device response (one line). Timeout prefix: 'T!', Error: 'E!'
97 ENDMSG
98  
99 0 print $message;
100  
101 0 $result = <STDIN>;
102 0 chomp($result);
103  
104 0 ▶ if ( $result =~ /^(T!).*/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($result =~ /^(T!).*/u) { } 0 0 0
elsif ($result =~ /^(E!).*/u) { } 0 0 0
105 0 $result = substr( $result, 2 );
106 0 Lab::Exception::Timeout->throw(
107 error => "Timeout in " . __PACKAGE__ . "::connection_read().\n",
108 data => $result,
109 );
110 }
111 elsif ( $result =~ /^(E!).*/ ) {
112 0 $result = substr( $result, 2 );
113 0 Lab::Exception::Error->throw(
114 error => "Error in " . __PACKAGE__ . "::connection_read().\n", );
115 }
116  
117 0 print "\n";
118 0 return $result;
119 }
120  
121 sub connection_write
122 { # @_ = ( $connection_handle, $args = { command, wait_status }
123 0 ▶ my $self = shift;
Subroutine connection_write: not called CC=10 SCAR=47.0
Pod documented
124 0 my $connection_handle = shift;
125 0 my $args = undef;
126 0 ▶ if ( ref $_[0] eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
127 0 $args = shift;
128 } # try to be flexible about options as hash/hashref
129 0 else { $args = {@_} }
130  
131 0 ▶ my $command = $args->{'command'} || undef;
Condition0%0/2
$args->{'command'} || undef
l!l
00
MC/DC0%0/1
$args->{'command'} || undef
$args->{'command'}
Truth table0%0/2
A
A= $args->{'command'}
Aresult
11
00
132 0 ▶ if ( !defined $command ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $command) 0 0 0
133 0 Lab::Exception::CorruptParameter->throw(
134 error => "No command given to "
135 . __PACKAGE__
136 . "::connection_write\n" );
137 }
138 0 ▶ my $brutal = $args->{'brutal'} || $self->brutal();
Condition0%0/3
$args->{'brutal'} || $self->brutal
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'brutal'} || $self->brutal
$args->{'brutal'} $self->brutal
Truth table0%0/3
A || B
A= $args->{'brutal'}B= $self->brutal
ABresult
1X1
011
000
139 0 ▶ my $read_length = $args->{'read_length'} || $self->read_length();
Condition0%0/3
$args->{'read_length'} || $self->read_length
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'read_length'} || $self->read_length
$args->{'read_length'} $self->read_length
Truth table0%0/3
A || B
A= $args->{'read_length'}B= $self->read_length
ABresult
1X1
011
000
140 0 ▶ my $wait_status = $args->{'wait_status'} || $self->wait_status();
Condition0%0/3
$args->{'wait_status'} || $self->wait_status
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'wait_status'} || $self->wait_status
$args->{'wait_status'} $self->wait_status
Truth table0%0/3
A || B
A= $args->{'wait_status'}B= $self->wait_status
ABresult
1X1
011
000
141  
142 0 my $message = "";
143 0 my $user_return = "";
144  
145 0 my $brutal_txt = 'false';
146 0 ▶ $brutal_txt = 'true' if $brutal;
Branch: 1 branch
BranchTrueFalseTotal
if $brutal 0 0 0
147  
148 0 ( $message = <<ENDMSG ) =~ s/^\t+//gm;
149  
150  
151 DEBUG bus
152 connection_write called on Instrument No. $connection_handle->{'debug_instr_index'}
153 Command: $command
154 Brutal: $brutal_txt
155 Read length: $read_length
156 Wait status: $wait_status
157  
158 Enter return state: (E)rror, just Return for success
159 ENDMSG
160 0 print $message;
161  
162 0 $user_return = <STDIN>;
163 0 chomp($user_return);
164  
165 0 ▶ if ( !defined $command ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $command) { } 0 0 0
166 0 Lab::Exception::CorruptParameter->throw(
167 error => "No command given to "
168 . __PACKAGE__
169 . "::connection_write().\n", );
170 }
171 else {
172  
173 0 ▶ if ( $user_return eq 'E' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user_return eq "E") 0 0 0
174 0 Lab::Exception::Error->throw( error => "Error in "
175 . __PACKAGE__
176 . "::connection_write() while executing $command.", );
177 }
178  
179 0 print "\n";
180 0 return 1;
181 }
182 }
183  
184 sub timeout {
185 2 ▶ my $self = shift;
Subroutine timeout: called CC=1 SCAR=0.0
Pod undocumented
186 2 my $connection_handle = shift;
187 2 my $timo = shift;
188  
189 2 say "DEBUG Bus: setting timeout to '$timo'";
190 }
191  
192 sub connection_query
193 { # @_ = ( $connection_handle, $args = { command, read_length, wait_status, wait_query, brutal }
194 0 ▶ my $self = shift;
Subroutine connection_query: not called CC=7 SCAR=40.3
Pod undocumented
195 0 my $connection_handle = shift;
196 0 my $args = undef;
197 0 ▶ if ( ref $_[0] eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
198 0 $args = shift;
199 } # try to be flexible about options as hash/hashref
200 0 else { $args = {@_} }
201  
202 0 ▶ my $command = $args->{'command'} || undef;
Condition0%0/2
$args->{'command'} || undef
l!l
00
MC/DC0%0/1
$args->{'command'} || undef
$args->{'command'}
Truth table0%0/2
A
A= $args->{'command'}
Aresult
11
00
203 0 ▶ my $brutal = $args->{'brutal'} || $self->brutal();
Condition0%0/3
$args->{'brutal'} || $self->brutal
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'brutal'} || $self->brutal
$args->{'brutal'} $self->brutal
Truth table0%0/3
A || B
A= $args->{'brutal'}B= $self->brutal
ABresult
1X1
011
000
204 0 ▶ my $read_length = $args->{'read_length'} || $self->read_length();
Condition0%0/3
$args->{'read_length'} || $self->read_length
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'read_length'} || $self->read_length
$args->{'read_length'} $self->read_length
Truth table0%0/3
A || B
A= $args->{'read_length'}B= $self->read_length
ABresult
1X1
011
000
205 0 ▶ my $wait_status = $args->{'wait_status'} || $self->wait_status();
Condition0%0/3
$args->{'wait_status'} || $self->wait_status
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'wait_status'} || $self->wait_status
$args->{'wait_status'} $self->wait_status
Truth table0%0/3
A || B
A= $args->{'wait_status'}B= $self->wait_status
ABresult
1X1
011
000
206 0 ▶ my $wait_query = $args->{'wait_query'} || $self->wait_query();
Condition0%0/3
$args->{'wait_query'} || $self->wait_query
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'wait_query'} || $self->wait_query
$args->{'wait_query'} $self->wait_query
Truth table0%0/3
A || B
A= $args->{'wait_query'}B= $self->wait_query
ABresult
1X1
011
000
207  
208 0 my $result = undef;
209 0 my $status = undef;
210 0 my $write_cnt = 0;
211 0 my $read_cnt = undef;
212  
213 0 $write_cnt = $self->connection_write($args);
214  
215 0 print "\nwait_query: $wait_query usec\n";
216  
217 0 $result = $self->connection_read($args);
218 0 return $result;
219 }
220  
221 sub _search_twin {
222 0 ▶ my $self = shift;
Subroutine _search_twin: not called CC=1 SCAR=6.9
223  
224 0 return undef;
225 }
226  
227 3 1;
228  
229 __END__
230  
231 =pod
232  
233 =encoding utf-8
234  
235 =head1 NAME
236  
237 Lab::Bus::DEBUG - Interactive debug bus
238  
239 =head1 VERSION
240  
241 version 3.881
242  
243 =head1 DESCRIPTION
244  
245 This will be an interactive debug bus, which prints out the commands sent by the
246 measurement script, and lets you manually enter the instrument responses.
247  
248 Unfinished, needs testing.
249  
250 =head1 COPYRIGHT AND LICENSE
251  
252 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
253  
254 Copyright 2011-2012 Andreas K. Huettel, Florian Olbrich
255 2013 Andreas K. Huettel
256 2016 Simon Reinhardt
257 2017 Andreas K. Huettel
258 2020 Andreas K. Huettel
259  
260  
261 This is free software; you can redistribute it and/or modify it under
262 the same terms as the Perl 5 programming language system itself.
263  
264 =cut
« Instrument/TCD.pm ↑ Summary Moose/Connection/Zhinst.pm »