line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Device::Modbus::ASCII::ADU; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
939
|
use parent 'Device::Modbus::ADU'; |
|
2
|
|
|
|
|
235
|
|
|
2
|
|
|
|
|
9
|
|
4
|
2
|
|
|
2
|
|
1527
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
74
|
|
5
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
28
|
|
6
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
445
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub lrc { |
9
|
4
|
|
|
4
|
0
|
5439
|
my ($self, $lrc) = @_; |
10
|
4
|
100
|
|
|
|
14
|
if (defined $lrc) { |
11
|
2
|
|
|
|
|
6
|
$self->{lrc} = $lrc; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
croak "LRC has not been declared" |
14
|
4
|
50
|
|
|
|
13
|
unless exists $self->{lrc}; |
15
|
4
|
|
|
|
|
16
|
return $self->{lrc}; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub binary_message { |
19
|
1
|
|
|
1
|
0
|
720
|
my $self = shift; |
20
|
1
|
|
|
|
|
4
|
my $head = $self->build_header; |
21
|
1
|
|
|
|
|
5
|
my $pdu = $self->message->pdu(); |
22
|
1
|
|
|
|
|
31
|
my $lrc = $self->lrc_for($head . $pdu); |
23
|
1
|
|
|
|
|
9
|
return ':' . unpack('H*', $head . $pdu . pack('C', $lrc)) . "\r\n"; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub build_header { |
27
|
2
|
|
|
2
|
0
|
9
|
my $self = shift; |
28
|
|
|
|
|
|
|
croak "Please include a unit number in the ADU" |
29
|
2
|
50
|
|
|
|
10
|
unless $self->{unit}; |
30
|
2
|
|
|
|
|
9
|
my $header = pack 'C', $self->{unit}; |
31
|
2
|
|
|
|
|
8
|
return $header; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Returns the LRC as a number |
35
|
|
|
|
|
|
|
sub lrc_for { |
36
|
8
|
|
|
8
|
0
|
6004
|
my ($self, $str) = @_; |
37
|
8
|
|
|
|
|
14
|
my $lrc = 0; |
38
|
8
|
|
|
|
|
52
|
$lrc += unpack('C', $_) foreach split //, $str; |
39
|
2
|
|
|
2
|
|
12
|
no warnings 'pack'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
149
|
|
40
|
8
|
|
|
|
|
41
|
return unpack 'C', pack 'c', -$lrc; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |