Connection/USBtmc.pm

filter: Statementstmt 36.2% 21 / 58 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 54.5% 6 / 11 Podpod 100% 5 / 5 totaltotal 30.4% 32 / 105 SCAR 37.1
CC
9
Cov
27%
Query
20.0
Write
12.0
Read
12.0
CRAP 41.1
« Moose/Sweep.pm ↑ Summary Moose/Connection/Mock.pm »
1 package Lab::Connection::USBtmc;
2 #ABSTRACT: F</dev/usbtmc> Linux USB Test&Measurement kernel driver connection
3 1 $Lab::Connection::USBtmc::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::Connection::GPIB;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Lab::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our @ISA = ("Lab::Connection::GPIB");
13  
14 1 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 ▶ my $proto = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
24 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
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__);
29  
30 0 return $self;
31 }
32  
33 sub Write {
34 0 ▶ my $self = shift;
Subroutine Write: not called CC=3 SCAR=24.8
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 ▶ my $timeout = $options->{'timeout'} || $self->timeout();
Condition0%0/3
$options->{'timeout'} || $self->timeout
l!l&&r!l&&!r
000
MC/DC0%0/2
$options->{'timeout'} || $self->timeout
$options->{'timeout'} $self->timeout
Truth table0%0/3
A || B
A= $options->{'timeout'}B= $self->timeout
ABresult
1X1
011
000
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 ▶ my $self = shift;
Subroutine Read: not called CC=3 SCAR=24.8
Pod documented
48 0 my $options = undef;
49 0 ▶ if ( ref $_[0] eq 'HASH' ) { $options = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
50 0 else { $options = {@_} }
51  
52 0 ▶ my $timeout = $options->{'timeout'} || $self->timeout();
Condition0%0/3
$options->{'timeout'} || $self->timeout
l!l&&r!l&&!r
000
MC/DC0%0/2
$options->{'timeout'} || $self->timeout
$options->{'timeout'} $self->timeout
Truth table0%0/3
A || B
A= $options->{'timeout'}B= $self->timeout
ABresult
1X1
011
000
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 ▶ my $self = shift;
Subroutine Query: not called CC=4 SCAR=30.0
Pod documented
61 0 my $options = undef;
62 0 ▶ if ( ref $_[0] eq 'HASH' ) { $options = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
63 0 else { $options = {@_} }
64  
65 0 ▶ my $wait_query = $options->{'wait_query'} || $self->wait_query();
Condition0%0/3
$options->{'wait_query'} || $self->wait_query
l!l&&r!l&&!r
000
MC/DC0%0/2
$options->{'wait_query'} || $self->wait_query
$options->{'wait_query'} $self->wait_query
Truth table0%0/3
A || B
A= $options->{'wait_query'}B= $self->wait_query
ABresult
1X1
011
000
66 0 ▶ my $timeout = $options->{'timeout'} || $self->timeout();
Condition0%0/3
$options->{'timeout'} || $self->timeout
l!l&&r!l&&!r
000
MC/DC0%0/2
$options->{'timeout'} || $self->timeout
$options->{'timeout'} $self->timeout
Truth table0%0/3
A || B
A= $options->{'timeout'}B= $self->timeout
ABresult
1X1
011
000
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 ▶ my $self = shift;
Subroutine Clear: not called CC=1 SCAR=6.9
Pod documented
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 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
« Moose/Sweep.pm ↑ Summary Moose/Connection/Mock.pm »