line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lab::Connection::MODBUS_RS232; |
2
|
|
|
|
|
|
|
#ABSTRACT: RS232/RS485 MODBUS RTU connection |
3
|
|
|
|
|
|
|
$Lab::Connection::MODBUS_RS232::VERSION = '3.880'; |
4
|
1
|
|
|
1
|
|
1866
|
use v5.20; |
|
1
|
|
|
|
|
5
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
11
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
7
|
1
|
|
|
1
|
|
8
|
use Scalar::Util qw(weaken); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
53
|
|
8
|
1
|
|
|
1
|
|
6
|
use Time::HiRes qw (usleep sleep); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
6
|
|
9
|
1
|
|
|
1
|
|
112
|
use Lab::Exception; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
262
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = ("Lab::Connection"); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %fields = ( |
14
|
|
|
|
|
|
|
bus_class => 'Lab::Bus::MODBUS_RS232', |
15
|
|
|
|
|
|
|
wait_status => 0, # sec; |
16
|
|
|
|
|
|
|
wait_query => 10e-6, # sec; |
17
|
|
|
|
|
|
|
read_length => 1000, # bytes |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
22
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
23
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_) |
24
|
|
|
|
|
|
|
; # getting fields and _permitted from parent class |
25
|
0
|
|
|
|
|
|
$self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__); |
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# this does not really make sense for MODBUS, as there are no "commands" and "responses" |
31
|
|
|
|
|
|
|
# disable for the time being |
32
|
|
|
|
|
|
|
# maybe makes sense: write value to one address, wait, read from another address. |
33
|
|
|
|
|
|
|
sub Query { |
34
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
35
|
0
|
|
|
|
|
|
my $options = undef; |
36
|
0
|
0
|
|
|
|
|
if ( ref $_[0] eq 'HASH' ) { $options = shift } |
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
else { $options = {@_} } |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
warn |
40
|
|
|
|
|
|
|
"Query is not implemented (and makes no sense) for MODBUS connections. Use Read. Ignoring.\n"; |
41
|
0
|
|
|
|
|
|
return undef; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# return undef unless $self->slave_address($self->config()->{'slave_address'}); |
45
|
|
|
|
|
|
|
# # check the configuration hash for a valid bus object or bus type, and set the bus |
46
|
|
|
|
|
|
|
# if( defined($self->config()->{'Bus'}) ) { |
47
|
|
|
|
|
|
|
# if($self->_checkbus($self->config()->{'Bus'})) { |
48
|
|
|
|
|
|
|
# $self->Bus($self->config()->{'Bus'}); |
49
|
|
|
|
|
|
|
# } |
50
|
|
|
|
|
|
|
# else { |
51
|
|
|
|
|
|
|
# warn('Given Bus not supported'); |
52
|
|
|
|
|
|
|
# return undef; |
53
|
|
|
|
|
|
|
# } |
54
|
|
|
|
|
|
|
# } |
55
|
|
|
|
|
|
|
# else { |
56
|
|
|
|
|
|
|
# if($self->_checkbus($self->config()->{'ConnType'})) { |
57
|
|
|
|
|
|
|
# my $ConnType = $self->config()->{'ConnType'}; |
58
|
|
|
|
|
|
|
# my $Port = $self->config()->{'Port'}; |
59
|
|
|
|
|
|
|
# my $slave_address = $self->config()->{'slave_address'}; |
60
|
|
|
|
|
|
|
# my $Interface = ""; |
61
|
|
|
|
|
|
|
# if($ConnType eq 'MODBUS_RS232') { |
62
|
|
|
|
|
|
|
# $self->config()->{'Interface'} = 'RS232'; |
63
|
|
|
|
|
|
|
# $self->Bus(new Lab::Bus::MODBUS_RS232( $self->config() )) || croak('Failed to create bus'); |
64
|
|
|
|
|
|
|
# #$self->Bus(eval("new Lab::Bus::$ConnType( $self->config() )")) || croak('Failed to create bus'); |
65
|
|
|
|
|
|
|
# } |
66
|
|
|
|
|
|
|
# else { |
67
|
|
|
|
|
|
|
# warn('Only RS232 bus type supported for now!\n'); |
68
|
|
|
|
|
|
|
# return undef; |
69
|
|
|
|
|
|
|
# } |
70
|
|
|
|
|
|
|
# } |
71
|
|
|
|
|
|
|
# else { |
72
|
|
|
|
|
|
|
# warn('Given Bus Type not supported'); |
73
|
|
|
|
|
|
|
# return undef; |
74
|
|
|
|
|
|
|
# } |
75
|
|
|
|
|
|
|
# } |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# |
78
|
|
|
|
|
|
|
# Nothing to do, Read, Write, Query from Lab::Connection are sufficient. |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=pod |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=encoding utf-8 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 NAME |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Lab::Connection::MODBUS_RS232 - RS232/RS485 MODBUS RTU connection |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 VERSION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
version 3.880 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 CAVEATS/BUGS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Probably few. Mostly because there's not a lot to be done here. Please report. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SEE ALSO |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over 4 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * L<Lab::Connection> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * L<Lab::Bus::MODBUS_RS232> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=back |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This software is copyright (c) 2023 by the Lab::Measurement team; in detail: |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Copyright 2011 Andreas K. Huettel, Florian Olbrich |
117
|
|
|
|
|
|
|
2012 Florian Olbrich |
118
|
|
|
|
|
|
|
2016 Simon Reinhardt |
119
|
|
|
|
|
|
|
2017 Andreas K. Huettel |
120
|
|
|
|
|
|
|
2020 Andreas K. Huettel |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
124
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |