line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Device::Modbus::Exception; |
2
|
|
|
|
|
|
|
|
3
|
13
|
|
|
13
|
|
14832
|
use parent 'Device::Modbus'; |
|
13
|
|
|
|
|
241
|
|
|
13
|
|
|
|
|
52
|
|
4
|
13
|
|
|
13
|
|
596
|
use Carp; |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
663
|
|
5
|
13
|
|
|
13
|
|
11535
|
use overload '""' => \&stringify; |
|
13
|
|
|
|
|
9327
|
|
|
13
|
|
|
|
|
87
|
|
6
|
|
|
|
|
|
|
|
7
|
13
|
|
|
13
|
|
612
|
use strict; |
|
13
|
|
|
|
|
40
|
|
|
13
|
|
|
|
|
207
|
|
8
|
13
|
|
|
13
|
|
37
|
use warnings; |
|
13
|
|
|
|
|
14
|
|
|
13
|
|
|
|
|
3068
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %exc_descr_for = ( |
11
|
|
|
|
|
|
|
1 => '1 - Function code not supported', |
12
|
|
|
|
|
|
|
2 => '2 - Incorrect address or address not supported', |
13
|
|
|
|
|
|
|
3 => '3 - Invalid data (either quantity or values)', |
14
|
|
|
|
|
|
|
4 => '4 - Execution failed', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
66
|
|
|
66
|
0
|
3050
|
my ($class, %args) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Must receive either a function name or a function code |
21
|
66
|
100
|
66
|
|
|
180
|
unless (exists $args{function} or exists $args{code}) { |
22
|
1
|
|
|
|
|
177
|
croak 'Please specify either a function name or code to instantiate an exception'; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
65
|
100
|
100
|
|
|
354
|
if (exists $args{function} && exists $Device::Modbus::code_for{$args{function}}) { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
26
|
12
|
|
|
|
|
26
|
$args{code} = $Device::Modbus::code_for{$args{function}} + 0x80; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
elsif (exists $args{code} && exists $Device::Modbus::function_for{$args{code} - 0x80}) { |
29
|
50
|
|
|
|
|
88
|
$args{function} = $Device::Modbus::function_for{$args{code} - 0x80}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
elsif (exists $args{code}) { |
32
|
2
|
|
|
|
|
5
|
$args{function} = 'Non-supported function'; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else { |
35
|
1
|
|
|
|
|
96
|
croak "Function $args{function} is not supported"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Must receive an exception code |
39
|
|
|
|
|
|
|
croak 'A valid exception code (between 1 and 4) is required' |
40
|
64
|
100
|
100
|
|
|
642
|
unless exists $args{exception_code} && $args{exception_code} > 0 && $args{exception_code} <= 4; |
|
|
|
100
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
61
|
|
|
|
|
223
|
return bless \%args, $class; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub pdu { |
46
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
47
|
1
|
|
|
|
|
6
|
return pack('CC', $self->{code}, $self->{exception_code}); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub stringify { |
51
|
52
|
|
|
52
|
0
|
47
|
my $self = shift; |
52
|
|
|
|
|
|
|
|
53
|
52
|
|
100
|
|
|
145
|
my $str = $Device::Modbus::function_for{$self->{code}-0x80} // 'Unknown'; |
54
|
52
|
|
|
|
|
70
|
my $descr = $exc_descr_for{$self->{exception_code}}; |
55
|
|
|
|
|
|
|
|
56
|
52
|
|
|
|
|
169
|
return "Exception for function <$str>: $descr"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |