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