NAME
Lab::Connection - Connection base class
VERSION
version 3.780
SYNOPSIS
This is the base class for all connections. Every inheriting classes constructors should start as follows:
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = $class->SUPER::new(@_);
$self->_construct(__PACKAGE__); #initialize fields etc.
...
}
DESCRIPTION
Lab::Connection
is the base class for all connections and implements a generic set of access methods. It doesn't do anything on its own.
A connection in general is an object which is created by an instrument and provides it with a generic set of methods to talk to its hardware counterpart. For example Lab::Instrument::HP34401A can work with any connection of the type GPIB, that is, connections derived from Lab::Connection::GPIB.
That would be, for example Lab::Connection::LinuxGPIB Lab::Connection::VISA_GPIB
Towards the instrument, these look the same, but they work with different drivers/backends.
CONSTRUCTOR
new
Generally called in child class constructor:
my $self = $class->SUPER::new(@_);
Return blessed $self, with @_ accessible through $self->Config().
METHODS
Clear
Try to clear the connection, if the bus supports it.
Read
my $result = $connection->Read();
my $result = $connection->Read( timeout => 30 );
configuration hash options:
brutal => <1/0> # suppress timeout errors if set to 1
read_length => <int> # how many bytes/characters to read
...see bus documentation
Reads a string from the connected device. In this basic form, its merely a wrapper to the method connection_read() of the used bus. You can give a configuration hash, which options are passed on to the bus. This hash is also meant for options to Read itself, if need be.
Write
$connection->Write( command => '*CLS' );
configuration hash options:
command => <command string>
...more (see bus documentation)
Write a command string to the connected device. In this basic form, its merely a wrapper to the method connection_write() of the used bus. You need to supply a configuration hash, with at least the key 'command' set. This hash is also meant for options to Read itself, if need be.
Query
my $result = $connection->Query( command => '*IDN?' );
configuration hash options:
command => <command string>
wait_query => <wait time between read and write in seconds> # overwrites the connection default
brutal => <1/0> # suppress timeout errors if set to true
read_length => <int> # how many bytes/characters to read
...more (see bus documentation)
Write a command string to the connected device, and immediately read the response.
You need to supply a configuration hash with at least the 'command' key set. The wait_query key sets the time to wait between read and write in usecs. The hash is also passed along to the used bus methods.
BrutalRead
The same as read with the 'brutal' option set to 1.
BrutalQuery
The same as Query with the 'brutal' option set to 1.
LongQuery
The same as Query with 'read_length' set to 10240.
config
Provides unified access to the fields in initial @_ to all the cild classes. E.g.
$GPIB_Address=$instrument->Config(gpib_address);
Without arguments, returns a reference to the complete $self->Config aka @_ of the constructor.
$Config = $connection->Config();
$GPIB_Address = $connection->Config()->{'gpib_address'};
CAVEATS/BUGS
Probably few. Mostly because there's not a lot to be done here. Please report.
SEE ALSO
and all the others...
COPYRIGHT AND LICENSE
This software is copyright (c) 2021 by the Lab::Measurement team; in detail:
Copyright 2010-2011 Andreas K. Huettel, Florian Olbrich
2012 Florian Olbrich, Hermann Kraus, Stefan Geissler
2013 Alois Dirnaichner, Christian Butschkow, Stefan Geissler
2014 Alexei Iankilevitch
2016 Simon Reinhardt
2017 Andreas K. Huettel
2019 Simon Reinhardt
2020 Andreas K. Huettel
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.