| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Device::Modbus::TCP::ADU; |
|
2
|
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
19214
|
use parent 'Device::Modbus::ADU'; |
|
|
18
|
|
|
|
|
37
|
|
|
|
18
|
|
|
|
|
92
|
|
|
4
|
18
|
|
|
18
|
|
15618
|
use Carp; |
|
|
18
|
|
|
|
|
43
|
|
|
|
18
|
|
|
|
|
792
|
|
|
5
|
18
|
|
|
18
|
|
104
|
use strict; |
|
|
18
|
|
|
|
|
46
|
|
|
|
18
|
|
|
|
|
319
|
|
|
6
|
18
|
|
|
18
|
|
94
|
use warnings; |
|
|
18
|
|
|
|
|
5284
|
|
|
|
18
|
|
|
|
|
4086
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub id { |
|
9
|
28
|
|
|
28
|
0
|
2445
|
my ($self, $value) = @_; |
|
10
|
28
|
100
|
|
|
|
90
|
if (defined $value) { |
|
11
|
11
|
|
|
|
|
56
|
$self->{id} = $value; |
|
12
|
|
|
|
|
|
|
} |
|
13
|
|
|
|
|
|
|
croak "ID has not been declared" |
|
14
|
28
|
100
|
|
|
|
309
|
unless exists $self->{id}; |
|
15
|
27
|
|
|
|
|
99
|
return $self->{id}; |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub length { |
|
19
|
8
|
|
|
8
|
0
|
1602
|
my ($self, $value) = @_; |
|
20
|
8
|
100
|
|
|
|
214
|
if (defined $value) { |
|
21
|
6
|
|
|
|
|
35
|
$self->{length} = $value; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
croak "PDU length has not been declared" |
|
24
|
8
|
100
|
|
|
|
134
|
unless exists $self->{length}; |
|
25
|
7
|
|
|
|
|
20
|
return $self->{length}; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Modbus TCP states unit number is 0xFF by default |
|
29
|
|
|
|
|
|
|
sub unit { |
|
30
|
41
|
|
|
41
|
0
|
1836
|
my $self = shift; |
|
31
|
41
|
100
|
100
|
|
|
208
|
$_[0] = 0xFF unless exists $self->{unit} || defined $_[0]; |
|
32
|
41
|
|
|
|
|
204
|
return $self->SUPER::unit(@_); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub binary_message { |
|
36
|
11
|
|
|
11
|
0
|
39
|
my $self = shift; |
|
37
|
11
|
50
|
|
|
|
30
|
croak "Please include a unit number in the ADU." |
|
38
|
|
|
|
|
|
|
unless $self->unit; |
|
39
|
11
|
|
|
|
|
145
|
my $header = $self->build_header; |
|
40
|
11
|
|
|
|
|
35
|
my $pdu = $self->message->pdu(); |
|
41
|
11
|
|
|
|
|
265
|
return $header . $pdu; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#### APU building |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub build_header { |
|
47
|
12
|
|
|
12
|
0
|
417
|
my $self = shift; |
|
48
|
12
|
|
|
|
|
46
|
my $header = pack 'nnnC', |
|
49
|
|
|
|
|
|
|
$self->id, # Transaction id |
|
50
|
|
|
|
|
|
|
0x0000, # Protocol number (Modbus) |
|
51
|
|
|
|
|
|
|
CORE::length($self->message->pdu) + 1, # Length of PDU + 1 byte for unit |
|
52
|
|
|
|
|
|
|
$self->unit; # Unit number |
|
53
|
12
|
|
|
|
|
138
|
return $header; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |