| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Lab::Connection::USBtmc; |
|
2
|
|
|
|
|
|
|
#ABSTRACT: F</dev/usbtmc> Linux USB Test&Measurement kernel driver connection |
|
3
|
|
|
|
|
|
|
$Lab::Connection::USBtmc::VERSION = '3.881'; |
|
4
|
1
|
|
|
1
|
|
2076
|
use v5.20; |
|
|
1
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
25
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Scalar::Util qw(weaken); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
48
|
|
|
8
|
1
|
|
|
1
|
|
7
|
use Time::HiRes qw (usleep sleep); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
9
|
1
|
|
|
1
|
|
102
|
use Lab::Connection::GPIB; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
23
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use Lab::Exception; |
|
|
1
|
|
|
|
|
12
|
|
|
|
1
|
|
|
|
|
581
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = ("Lab::Connection::GPIB"); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %fields = ( |
|
15
|
|
|
|
|
|
|
bus_class => 'Lab::Bus::USBtmc', |
|
16
|
|
|
|
|
|
|
wait_status => 0, # usec; |
|
17
|
|
|
|
|
|
|
wait_query => 10e-6, # sec; |
|
18
|
|
|
|
|
|
|
read_length => 1000, # bytes |
|
19
|
|
|
|
|
|
|
timeout => 1, # seconds |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
|
23
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
|
24
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
|
25
|
0
|
|
|
|
|
|
my $twin = undef; |
|
26
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_) |
|
27
|
|
|
|
|
|
|
; # getting fields and _permitted from parent class |
|
28
|
0
|
|
|
|
|
|
$self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__); |
|
|
0
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return $self; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub Write { |
|
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
|
|
0
|
|
|
|
my $timeout = $options->{'timeout'} || $self->timeout(); |
|
40
|
0
|
|
|
|
|
|
$self->bus()->timeout( $self->connection_handle(), $timeout ); |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return $self->bus() |
|
43
|
|
|
|
|
|
|
->connection_write( $self->connection_handle(), $options ); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub Read { |
|
47
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
48
|
0
|
|
|
|
|
|
my $options = undef; |
|
49
|
0
|
0
|
|
|
|
|
if ( ref $_[0] eq 'HASH' ) { $options = shift } |
|
|
0
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
else { $options = {@_} } |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
0
|
|
|
|
my $timeout = $options->{'timeout'} || $self->timeout(); |
|
53
|
0
|
|
|
|
|
|
$self->bus()->timeout( $self->connection_handle(), $timeout ); |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
return $self->bus() |
|
56
|
|
|
|
|
|
|
->connection_read( $self->connection_handle(), $options ); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub Query { |
|
60
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
61
|
0
|
|
|
|
|
|
my $options = undef; |
|
62
|
0
|
0
|
|
|
|
|
if ( ref $_[0] eq 'HASH' ) { $options = shift } |
|
|
0
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
else { $options = {@_} } |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
0
|
|
|
|
my $wait_query = $options->{'wait_query'} || $self->wait_query(); |
|
66
|
0
|
|
0
|
|
|
|
my $timeout = $options->{'timeout'} || $self->timeout(); |
|
67
|
0
|
|
|
|
|
|
$self->bus()->timeout( $self->connection_handle(), $timeout ); |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->Write($options); |
|
70
|
0
|
|
|
|
|
|
usleep($wait_query); |
|
71
|
0
|
|
|
|
|
|
return $self->Read($options); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub Clear { |
|
75
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
76
|
0
|
|
|
|
|
|
my $options = undef; |
|
77
|
0
|
|
|
|
|
|
return $self->bus() |
|
78
|
|
|
|
|
|
|
->connection_device_clear( $self->connection_handle() ); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# |
|
82
|
|
|
|
|
|
|
# Query from Lab::Connection is sufficient |
|
83
|
|
|
|
|
|
|
# EnableTermChar, SetTermChar from Lab::Connection::GPIB are sufficient. |
|
84
|
|
|
|
|
|
|
# |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=pod |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=encoding utf-8 |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Lab::Connection::USBtmc - F</dev/usbtmc> Linux USB Test&Measurement kernel driver connection |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 VERSION |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
version 3.881 |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This is not called directly. To make a GPIB suppporting instrument use |
|
106
|
|
|
|
|
|
|
Lab::Connection::USBtmc, set the connection_type parameter accordingly: |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$instrument = U2000->new( |
|
109
|
|
|
|
|
|
|
connection_type => 'USBtmc', |
|
110
|
|
|
|
|
|
|
usb_vendor => 0x3838, |
|
111
|
|
|
|
|
|
|
usb_product => 0x1234, |
|
112
|
|
|
|
|
|
|
) |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Ways to indicate device: |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
tmc_address => number (for /dev/usbtmcN) |
|
117
|
|
|
|
|
|
|
visa_name => 'USB::0x1234::0x5678::serial:INSTR'; |
|
118
|
|
|
|
|
|
|
usb_vendor => 0x1234, usb_product => 0x5678 |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Lab::Connection::USBtmc provides a GPIB-type connection with the bus |
|
123
|
|
|
|
|
|
|
L<Lab::Bus::USBtmc>, using F</dev/usbtmc*> as backend. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
It inherits from L<Lab::Connection::GPIB> and subsequently from |
|
126
|
|
|
|
|
|
|
L<Lab::Connection>. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
For L<Lab::Bus::USBtmc>, the generic methods of L<Lab::Connection> suffice, so |
|
129
|
|
|
|
|
|
|
only a few defaults are set: |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
wait_status=>0, # usec; |
|
132
|
|
|
|
|
|
|
wait_query=>10, # usec; |
|
133
|
|
|
|
|
|
|
read_length=>1000, # bytes |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 new |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my $connection = Lab::Connection::USBtmc->new( |
|
140
|
|
|
|
|
|
|
usb_vendor => 0x1234, # vendor id |
|
141
|
|
|
|
|
|
|
usb_product => 0x5678, # product id |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 METHODS |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Mostly, this just falls back on the methods inherited from L<Lab::Connection>. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 config |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Provides unified access to the attributes of all the child |
|
151
|
|
|
|
|
|
|
classes. E.g. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
$USB_product = $instrument->config('usb_product'); |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Without arguments, returns a reference to the complete C<< $self->config >> |
|
156
|
|
|
|
|
|
|
created by the constructor. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
$config = $connection->config(); |
|
159
|
|
|
|
|
|
|
$USB_product = $connection->config()->{'usb_product'}; |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 CAVEATS/BUGS |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Probably few. Mostly because there's not a lot to be done here. Please report. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=over 4 |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item * L<Lab::Connection> |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item * L<Lab::Connection::GPIB> |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=back |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This software is copyright (c) 2023 by the Lab::Measurement team; in detail: |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Copyright 2011 Andreas K. Huettel, Florian Olbrich |
|
180
|
|
|
|
|
|
|
2012 Florian Olbrich, Hermann Kraus |
|
181
|
|
|
|
|
|
|
2016 Charles Lane, Simon Reinhardt |
|
182
|
|
|
|
|
|
|
2017 Andreas K. Huettel |
|
183
|
|
|
|
|
|
|
2020 Andreas K. Huettel |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
187
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |