| 1 | package Lab::Connection::USBtmc; | ||
| 2 | #ABSTRACT: F</dev/usbtmc> Linux USB Test&Measurement kernel driver connection | ||
| 3 | $Lab::Connection::USBtmc::VERSION = '3.899'; | ||
| 4 | use v5.20; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use Scalar::Util qw(weaken); | ||
| 8 | use Time::HiRes qw (usleep sleep); | ||
| 9 | use Lab::Connection::GPIB; | ||
| 10 | use Lab::Exception; | ||
| 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 | my $proto = shift; | ||
| 24 | my $class = ref($proto) || $proto; | ||
| 25 | my $twin = undef; | ||
| 26 | my $self = $class->SUPER::new(@_) | ||
| 27 | ; # getting fields and _permitted from parent class | ||
| 28 | $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__); | ||
| 29 | |||
| 30 | return $self; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub Write { | ||
| 34 | my $self = shift; | ||
| 35 | my $options = undef; | ||
| 36 | if ( ref $_[0] eq 'HASH' ) { $options = shift } | ||
| 37 | else { $options = {@_} } | ||
| 38 | |||
| 39 | my $timeout = $options->{'timeout'} || $self->timeout(); | ||
| 40 | $self->bus()->timeout( $self->connection_handle(), $timeout ); | ||
| 41 | |||
| 42 | return $self->bus() | ||
| 43 | ->connection_write( $self->connection_handle(), $options ); | ||
| 44 | } | ||
| 45 | |||
| 46 | sub Read { | ||
| 47 | my $self = shift; | ||
| 48 | my $options = undef; | ||
| 49 | if ( ref $_[0] eq 'HASH' ) { $options = shift } | ||
| 50 | else { $options = {@_} } | ||
| 51 | |||
| 52 | my $timeout = $options->{'timeout'} || $self->timeout(); | ||
| 53 | $self->bus()->timeout( $self->connection_handle(), $timeout ); | ||
| 54 | |||
| 55 | return $self->bus() | ||
| 56 | ->connection_read( $self->connection_handle(), $options ); | ||
| 57 | } | ||
| 58 | |||
| 59 | sub Query { | ||
| 60 | my $self = shift; | ||
| 61 | my $options = undef; | ||
| 62 | if ( ref $_[0] eq 'HASH' ) { $options = shift } | ||
| 63 | else { $options = {@_} } | ||
| 64 | |||
| 65 | my $wait_query = $options->{'wait_query'} || $self->wait_query(); | ||
| 66 | my $timeout = $options->{'timeout'} || $self->timeout(); | ||
| 67 | $self->bus()->timeout( $self->connection_handle(), $timeout ); | ||
| 68 | |||
| 69 | $self->Write($options); | ||
| 70 | usleep($wait_query); | ||
| 71 | return $self->Read($options); | ||
| 72 | } | ||
| 73 | |||
| 74 | sub Clear { | ||
| 75 | my $self = shift; | ||
| 76 | my $options = undef; | ||
| 77 | 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__ |