line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Device::Modbus::TCP::Client; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
287372
|
use parent 'Device::Modbus::Client'; |
|
17
|
|
|
|
|
4038
|
|
|
17
|
|
|
|
|
81
|
|
4
|
17
|
|
|
17
|
|
120418
|
use Role::Tiny::With; |
|
17
|
|
|
|
|
66770
|
|
|
17
|
|
|
|
|
883
|
|
5
|
17
|
|
|
17
|
|
109
|
use Carp; |
|
17
|
|
|
|
|
24
|
|
|
17
|
|
|
|
|
661
|
|
6
|
17
|
|
|
17
|
|
85
|
use strict; |
|
17
|
|
|
|
|
34
|
|
|
17
|
|
|
|
|
269
|
|
7
|
17
|
|
|
17
|
|
61
|
use warnings; |
|
17
|
|
|
|
|
31
|
|
|
17
|
|
|
|
|
3553
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'Device::Modbus::TCP'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
3
|
|
|
3
|
1
|
5903
|
my ($class, %args) = @_; |
13
|
|
|
|
|
|
|
|
14
|
3
|
|
50
|
|
|
59
|
$args{host} //= '127.0.0.1'; |
15
|
3
|
|
50
|
|
|
21
|
$args{port} //= 502; |
16
|
3
|
|
50
|
|
|
63
|
$args{timeout} //= 2; |
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
|
|
29
|
return bless \%args, $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub socket { |
22
|
34
|
|
|
34
|
1
|
2002508
|
my $self = shift; |
23
|
34
|
100
|
|
|
|
101
|
if (@_) { |
24
|
3
|
|
|
|
|
19
|
$self->{socket} = shift; |
25
|
|
|
|
|
|
|
} |
26
|
34
|
100
|
|
|
|
136
|
if (!defined $self->{socket}) { |
27
|
3
|
50
|
|
|
|
32
|
$self->_build_socket || croak "Unable to open a connection"; |
28
|
|
|
|
|
|
|
} |
29
|
34
|
|
|
|
|
173
|
return $self->{socket}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub connected { |
33
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
34
|
0
|
|
0
|
|
|
0
|
return defined $self->{socket} && $self->{socket}->connected; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _build_socket { |
38
|
3
|
|
|
3
|
|
8
|
my $self = shift; |
39
|
|
|
|
|
|
|
my $sock = IO::Socket::INET->new( |
40
|
|
|
|
|
|
|
PeerAddr => $self->{host}, |
41
|
|
|
|
|
|
|
PeerPort => $self->{port}, |
42
|
|
|
|
|
|
|
Blocking => $self->{blocking}, |
43
|
|
|
|
|
|
|
Timeout => $self->{timeout}, |
44
|
3
|
|
|
|
|
72
|
Proto => 'tcp', |
45
|
|
|
|
|
|
|
); |
46
|
3
|
50
|
|
|
|
5527
|
return undef unless $sock; |
47
|
3
|
|
|
|
|
27
|
$self->socket($sock); |
48
|
3
|
|
|
|
|
14
|
return 1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#### Transaction ID |
52
|
|
|
|
|
|
|
my $trans_id = 0; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub next_trn_id { |
55
|
3
|
|
|
3
|
0
|
16
|
my $self = shift; |
56
|
3
|
|
|
|
|
11
|
$trans_id++; |
57
|
3
|
50
|
|
|
|
15
|
$trans_id = 1 if $trans_id > 65_535; |
58
|
3
|
|
|
|
|
15
|
return $trans_id; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |