Connection/MODBUS_RS232.pm

filter: Statementstmt 58.0% 18 / 31 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 53.1% 25 / 47 SCAR 14.2
CC
3
Cov
50%
new
6.0
Query
6.0
BEGIN
1.0
CRAP 4.1
« Connection/GPIB.pm ↑ Summary Moose/DataFile/Gnuplot/Compressed.pm »
1 package Lab::Connection::MODBUS_RS232;
2 #ABSTRACT: RS232/RS485 MODBUS RTU connection
3 1 $Lab::Connection::MODBUS_RS232::VERSION = '3.881';
4 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Time::HiRes qw (usleep sleep);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Lab::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our @ISA = ("Lab::Connection");
12  
13 1 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 ▶ my $proto = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
22 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
23 0 my $self = $class->SUPER::new(@_)
24 ; # getting fields and _permitted from parent class
25 0 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
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 ▶ my $self = shift;
Subroutine Query: not called CC=2 SCAR=17.9
Pod documented
35 0 my $options = undef;
36 0 ▶ if ( ref $_[0] eq 'HASH' ) { $options = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 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 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.881
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
« Connection/GPIB.pm ↑ Summary Moose/DataFile/Gnuplot/Compressed.pm »