line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Device::Modbus::ASCII; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
370
|
use Device::Modbus::ASCII::ADU; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
5
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.006'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
18
|
use Role::Tiny; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#### Modbus ASCII Operations |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new_adu { |
15
|
3
|
|
|
3
|
0
|
1120
|
my ($self, $msg) = @_; |
16
|
3
|
|
|
|
|
22
|
my $adu = Device::Modbus::ASCII::ADU->new; |
17
|
3
|
100
|
|
|
|
32
|
if (defined $msg) { |
18
|
1
|
|
|
|
|
8
|
$adu->message($msg); |
19
|
1
|
50
|
|
|
|
29
|
$adu->unit($msg->{unit}) if defined $msg->{unit}; |
20
|
|
|
|
|
|
|
} |
21
|
3
|
|
|
|
|
25
|
return $adu; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
### Parsing a message |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub parse_header { |
27
|
2
|
|
|
2
|
0
|
8
|
my ($self, $adu) = @_; |
28
|
2
|
|
|
|
|
9
|
my ($col, $unit) = $self->parse_buffer(3, 'AA2'); |
29
|
2
|
50
|
|
|
|
9
|
croak "Response message must start by ':', but it does not" |
30
|
|
|
|
|
|
|
unless $col eq ':'; |
31
|
2
|
|
|
|
|
13
|
$adu->unit(1*$unit); |
32
|
2
|
|
|
|
|
31
|
return $adu; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub parse_footer { |
36
|
2
|
|
|
2
|
0
|
6
|
my ($self, $adu) = @_; |
37
|
|
|
|
|
|
|
# print STDERR "Remaining chars: <", $self->{buffer}, ">\n"; |
38
|
2
|
|
|
|
|
9
|
my $lrc = $self->parse_buffer(2, 'A2'); |
39
|
2
|
|
|
|
|
10
|
my $ln = $self->parse_buffer(2, 'H4'); |
40
|
2
|
50
|
|
|
|
8
|
croak "Response message must end by '\r\n', but it does not" |
41
|
|
|
|
|
|
|
unless $ln eq '0d0a'; # \r\n |
42
|
2
|
|
|
|
|
15
|
$adu->lrc( unpack 'C', pack 'H4', $lrc); |
43
|
2
|
|
|
|
|
7
|
return $adu; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |