line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lab::Bus::DEBUG; |
2
|
|
|
|
|
|
|
#ABSTRACT: Interactive debug bus |
3
|
|
|
|
|
|
|
$Lab::Bus::DEBUG::VERSION = '3.880'; |
4
|
3
|
|
|
3
|
|
1871
|
use v5.20; |
|
3
|
|
|
|
|
17
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
21
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
90
|
|
7
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
104
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
16
|
use Scalar::Util qw(weaken); |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
197
|
|
10
|
3
|
|
|
3
|
|
34
|
use Time::HiRes qw (usleep sleep); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
22
|
|
11
|
3
|
|
|
3
|
|
1291
|
use Lab::Bus; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
91
|
|
12
|
3
|
|
|
3
|
|
18
|
use Data::Dumper; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
123
|
|
13
|
3
|
|
|
3
|
|
17
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
157
|
|
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
26
|
use Lab::Exception; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
76
|
|
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
19
|
use parent 'Lab::Bus'; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
28
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
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
|
|
|
2
|
1
|
5
|
my $proto = shift; |
32
|
2
|
|
33
|
|
|
15
|
my $class = ref($proto) || $proto; |
33
|
2
|
|
|
|
|
4
|
my $twin = undef; |
34
|
2
|
|
|
|
|
13
|
my $self = $class->SUPER::new(@_) |
35
|
|
|
|
|
|
|
; # getting fields and _permitted from parent class |
36
|
2
|
|
|
|
|
8
|
$self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__); |
|
2
|
|
|
|
|
10
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# no twin search - just register |
39
|
2
|
50
|
|
|
|
25
|
if ( $class eq __PACKAGE__ ) |
40
|
|
|
|
|
|
|
{ # careful - do only if this is not a parent class constructor |
41
|
2
|
|
|
|
|
5
|
my $i = 0; |
42
|
2
|
|
|
|
|
21
|
while ( defined $Lab::Bus::BusList{ $self->type() }->{$i} ) { $i++; } |
|
0
|
|
|
|
|
0
|
|
43
|
2
|
|
|
|
|
19
|
$Lab::Bus::BusList{ $self->type() }->{$i} = $self; |
44
|
2
|
|
|
|
|
27
|
weaken( $Lab::Bus::BusList{ $self->type() }->{$i} ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
|
|
37
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub connection_new { # @_ = ({ resource_name => $resource_name }) |
51
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
52
|
2
|
|
|
|
|
4
|
my $args = undef; |
53
|
2
|
|
|
|
|
3
|
my $status = undef; |
54
|
2
|
|
|
|
|
4
|
my $connection_handle = undef; |
55
|
2
|
50
|
|
|
|
25
|
if ( ref $_[0] eq 'HASH' ) { |
56
|
2
|
|
|
|
|
7
|
$args = shift; |
57
|
|
|
|
|
|
|
} # try to be flexible about options as hash/hashref |
58
|
0
|
|
|
|
|
0
|
else { $args = {@_} } |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
18
|
$connection_handle = { debug_instr_index => $self->instrument_index() }; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
11
|
$self->instrument_index( $self->instrument_index() + 1 ); |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
19
|
return $connection_handle; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub connection_read |
68
|
|
|
|
|
|
|
{ # @_ = ( $connection_handle, $args = { read_length, brutal } |
69
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
70
|
0
|
|
|
|
|
0
|
my $connection_handle = shift; |
71
|
0
|
|
|
|
|
0
|
my $args = undef; |
72
|
0
|
0
|
|
|
|
0
|
if ( ref $_[0] eq 'HASH' ) { |
73
|
0
|
|
|
|
|
0
|
$args = shift; |
74
|
|
|
|
|
|
|
} # try to be flexible about options as hash/hashref |
75
|
0
|
|
|
|
|
0
|
else { $args = {@_} } |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
0
|
|
|
0
|
my $command = $args->{'command'} || undef; |
78
|
0
|
|
0
|
|
|
0
|
my $brutal = $args->{'brutal'} || $self->brutal(); |
79
|
0
|
|
0
|
|
|
0
|
my $read_length = $args->{'read_length'} || $self->read_length(); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
my $result = undef; |
82
|
0
|
|
|
|
|
0
|
my $user_status = undef; |
83
|
0
|
|
|
|
|
0
|
my $message = ""; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
my $brutal_txt = 'false'; |
86
|
0
|
0
|
|
|
|
0
|
$brutal_txt = 'true' if $brutal; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
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
|
|
|
|
|
0
|
print $message; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
0
|
$result = <STDIN>; |
102
|
0
|
|
|
|
|
0
|
chomp($result); |
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
0
|
if ( $result =~ /^(T!).*/ ) { |
|
|
0
|
|
|
|
|
|
105
|
0
|
|
|
|
|
0
|
$result = substr( $result, 2 ); |
106
|
0
|
|
|
|
|
0
|
Lab::Exception::Timeout->throw( |
107
|
|
|
|
|
|
|
error => "Timeout in " . __PACKAGE__ . "::connection_read().\n", |
108
|
|
|
|
|
|
|
data => $result, |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
elsif ( $result =~ /^(E!).*/ ) { |
112
|
0
|
|
|
|
|
0
|
$result = substr( $result, 2 ); |
113
|
0
|
|
|
|
|
0
|
Lab::Exception::Error->throw( |
114
|
|
|
|
|
|
|
error => "Error in " . __PACKAGE__ . "::connection_read().\n", ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
0
|
print "\n"; |
118
|
0
|
|
|
|
|
0
|
return $result; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub connection_write |
122
|
|
|
|
|
|
|
{ # @_ = ( $connection_handle, $args = { command, wait_status } |
123
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
124
|
0
|
|
|
|
|
0
|
my $connection_handle = shift; |
125
|
0
|
|
|
|
|
0
|
my $args = undef; |
126
|
0
|
0
|
|
|
|
0
|
if ( ref $_[0] eq 'HASH' ) { |
127
|
0
|
|
|
|
|
0
|
$args = shift; |
128
|
|
|
|
|
|
|
} # try to be flexible about options as hash/hashref |
129
|
0
|
|
|
|
|
0
|
else { $args = {@_} } |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
0
|
|
|
0
|
my $command = $args->{'command'} || undef; |
132
|
0
|
0
|
|
|
|
0
|
if ( !defined $command ) { |
133
|
0
|
|
|
|
|
0
|
Lab::Exception::CorruptParameter->throw( |
134
|
|
|
|
|
|
|
error => "No command given to " |
135
|
|
|
|
|
|
|
. __PACKAGE__ |
136
|
|
|
|
|
|
|
. "::connection_write\n" ); |
137
|
|
|
|
|
|
|
} |
138
|
0
|
|
0
|
|
|
0
|
my $brutal = $args->{'brutal'} || $self->brutal(); |
139
|
0
|
|
0
|
|
|
0
|
my $read_length = $args->{'read_length'} || $self->read_length(); |
140
|
0
|
|
0
|
|
|
0
|
my $wait_status = $args->{'wait_status'} || $self->wait_status(); |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
0
|
my $message = ""; |
143
|
0
|
|
|
|
|
0
|
my $user_return = ""; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
0
|
my $brutal_txt = 'false'; |
146
|
0
|
0
|
|
|
|
0
|
$brutal_txt = 'true' if $brutal; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
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
|
|
|
|
|
0
|
print $message; |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
0
|
$user_return = <STDIN>; |
163
|
0
|
|
|
|
|
0
|
chomp($user_return); |
164
|
|
|
|
|
|
|
|
165
|
0
|
0
|
|
|
|
0
|
if ( !defined $command ) { |
166
|
0
|
|
|
|
|
0
|
Lab::Exception::CorruptParameter->throw( |
167
|
|
|
|
|
|
|
error => "No command given to " |
168
|
|
|
|
|
|
|
. __PACKAGE__ |
169
|
|
|
|
|
|
|
. "::connection_write().\n", ); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
else { |
172
|
|
|
|
|
|
|
|
173
|
0
|
0
|
|
|
|
0
|
if ( $user_return eq 'E' ) { |
174
|
0
|
|
|
|
|
0
|
Lab::Exception::Error->throw( error => "Error in " |
175
|
|
|
|
|
|
|
. __PACKAGE__ |
176
|
|
|
|
|
|
|
. "::connection_write() while executing $command.", ); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
0
|
print "\n"; |
180
|
0
|
|
|
|
|
0
|
return 1; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub timeout { |
185
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
186
|
2
|
|
|
|
|
6
|
my $connection_handle = shift; |
187
|
2
|
|
|
|
|
2
|
my $timo = shift; |
188
|
|
|
|
|
|
|
|
189
|
2
|
|
|
|
|
446
|
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
|
|
|
0
|
0
|
|
my $self = shift; |
195
|
0
|
|
|
|
|
|
my $connection_handle = shift; |
196
|
0
|
|
|
|
|
|
my $args = undef; |
197
|
0
|
0
|
|
|
|
|
if ( ref $_[0] eq 'HASH' ) { |
198
|
0
|
|
|
|
|
|
$args = shift; |
199
|
|
|
|
|
|
|
} # try to be flexible about options as hash/hashref |
200
|
0
|
|
|
|
|
|
else { $args = {@_} } |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
0
|
|
|
|
my $command = $args->{'command'} || undef; |
203
|
0
|
|
0
|
|
|
|
my $brutal = $args->{'brutal'} || $self->brutal(); |
204
|
0
|
|
0
|
|
|
|
my $read_length = $args->{'read_length'} || $self->read_length(); |
205
|
0
|
|
0
|
|
|
|
my $wait_status = $args->{'wait_status'} || $self->wait_status(); |
206
|
0
|
|
0
|
|
|
|
my $wait_query = $args->{'wait_query'} || $self->wait_query(); |
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
|
|
|
0
|
|
|
my $self = shift; |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
return undef; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
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.880 |
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 |