line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
|
|
|
|
$Lab::Connection::RS232::VERSION = '3.880'; |
17
|
1
|
|
|
1
|
|
2104
|
use v5.20; |
|
1
|
|
|
|
|
4
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
6
|
use Lab::Connection; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
20
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
20
|
|
21
|
1
|
|
|
1
|
|
5
|
use Lab::Exception; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
194
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our @ISA = ("Lab::Connection"); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
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
|
|
|
0
|
1
|
|
my $proto = shift; |
34
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
35
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_) |
36
|
|
|
|
|
|
|
; # getting fields and _permitted from parent class |
37
|
0
|
|
|
|
|
|
$self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__); |
|
0
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Parameter checking |
40
|
0
|
0
|
|
|
|
|
if ( !defined $self->config('port') ) { |
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; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
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.880 |
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 |