Connection/RS232.pm

filter: Statementstmt 66.6% 16 / 24 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 56.7% 21 / 37 SCAR 13.4
CC
3
Cov
55%
new
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.8
« Moose/Sweep/Continuous/Magnet.pm ↑ Summary Instrument/HP83732A.pm »
1 #
2 # This is the RS232 Connection base class. It provides the interface definition for all
3 # connections implementing access via a RS232 line with its typical properties
4 # (baud rate, stop bits, ...)
5 #
6 # In your scripts, use the implementing classes (e.g. Lab::Connection::VISA_RS232).
7 #
8 # Instruments using a RS232 connection will check the inheritance tree of the provided connection
9 # for this class.
10 #
11  
12 # TODO: a lot, ...
13  
14 package Lab::Connection::RS232;
15 #ABSTRACT: RS232 Connection base class
16 1 $Lab::Connection::RS232::VERSION = '3.881';
17 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use Lab::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Lab::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 our @ISA = ("Lab::Connection");
24  
25 1 our %fields = (
26 bus_class => 'Lab::Bus::RS232',
27 port => undef,
28 brutal => 0,
29 read_length => 1000, # bytes
30 );
31  
32 sub new {
33 0 ▶ my $proto = shift;
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
34 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
35 0 my $self = $class->SUPER::new(@_)
36 ; # getting fields and _permitted from parent class
37 0 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
38  
39 # Parameter checking
40 0 ▶ if ( !defined $self->config('port') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->config("port")) 0 0 0
41 0 Lab::Exception::CorruptParameter->throw(
42 error => "No RS232 port specified! I can't work like this.\n" );
43 }
44  
45 0 return $self;
46 }
47  
48 #
49 # These are the method stubs you have to overwrite when implementing the RS232 connection for your
50 # hardware/driver. See documentation for detailed description of the parameters, expected exceptions
51 # and expected return values.
52 #
53 # You might just be satisfied with the generic ones from Lab::Connection, take a look at them.
54 #
55  
56 # sub Clear { # @_ = ()
57 # return 0;
58 # }
59  
60 # sub Write { # @_ = ( command => $cmd, wait_status => $wait_status, brutal => 1/0 )
61 # return 0; # status true/false
62 # }
63  
64 # sub Read { # @_ = ( read_length => $read_length, brutal => 1/0 )
65 # return 0; # result
66 # }
67  
68 # now comes RS232-specific stuff
69  
70 # Initialization is handled by default by the bus (see e.g. Bus::RS232).
71 # In some cases when this is not possible it can be done by a derived connection class.
72  
73 1 1;
74  
75  
76 1 1;
77  
78 __END__
79  
80 =pod
81  
82 =encoding utf-8
83  
84 =head1 NAME
85  
86 Lab::Connection::RS232 - RS232 Connection base class
87  
88 =head1 VERSION
89  
90 version 3.881
91  
92 =head1 SYNOPSIS
93  
94 This is the base class for all connections providing a RS232 interface.
95 Every inheriting class constructor should start as follows:
96  
97 sub new {
98 my $proto = shift;
99 my $class = ref($proto) || $proto;
100 my $self = $class->SUPER::new(@_);
101 $self->_construct(__PACKAGE__); #initialize fields etc.
102 ...
103 }
104  
105 =head1 DESCRIPTION
106  
107 C<Lab::Connection::RS232> is the base class for all connections providing a GPIB interface.
108 It is not usable on its own. It inherits from L<Lab::Connection>.
109  
110 =head1 NAME
111  
112 Lab::Connection::RS232 - RS232 connection base class
113  
114 =head1 CONSTRUCTOR
115  
116 =head2 new
117  
118 Generally called in child class constructor:
119  
120 my $self = $class->SUPER::new(@_);
121  
122 Return blessed $self, with @_ accessible through $self->Config().
123  
124 =head1 METHODS
125  
126 This just calls back on the methods inherited from Lab::Connection.
127  
128 If you inherit this class in your own connection however, you have to provide the following methods.
129 Take a look at e.g. L<Lab::Connection::VISA_RS232> and at the basic implementations
130 in L<Lab::Connection> (they may even suffice).
131  
132 =head3 Write()
133  
134 Takes a config hash, has to at least pass the key 'command' correctly to the underlying bus.
135  
136 =head3 Read()
137  
138 Takes a config hash, reads back a message from the device.
139  
140 =head3 Clear()
141  
142 Clears the instrument.
143  
144 =head2 config
145  
146 Provides unified access to the fields in initial @_ to all the child classes.
147 E.g.
148  
149 =head1 CAVEATS/BUGS
150  
151 Probably few. Mostly because there's not a lot to be done here. Please report.
152  
153 =head1 SEE ALSO
154  
155 =over 4
156  
157 =item * L<Lab::Connection>
158  
159 =item * L<Lab::Connection::System_RS232>
160  
161 =item * L<Lab::Connection::VISA_RS232>
162  
163 =back
164  
165 =head1 AUTHOR/COPYRIGHT
166  
167 Copyright 2011 Florian Olbrich
168 2012 Andreas K. Hüttel
169  
170 This library is free software; you can redistribute it and/or modify it under the same
171 terms as Perl itself.
172  
173 =head1 COPYRIGHT AND LICENSE
174  
175 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
176  
177 Copyright 2012 Andreas K. Huettel
178 2016 Simon Reinhardt
179 2017 Andreas K. Huettel
180 2020 Andreas K. Huettel
181  
182  
183 This is free software; you can redistribute it and/or modify it under
184 the same terms as the Perl 5 programming language system itself.
185  
186 =cut
« Moose/Sweep/Continuous/Magnet.pm ↑ Summary Instrument/HP83732A.pm »