Lab::Connection - connection base class
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. ... }
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.
Lab::Connection
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.
Generally called in child class constructor:
my $self = $class->SUPER::new(@_);
Return blessed $self, with @_ accessible through $self->Config().
Try to clear the connection, if the bus supports it.
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.
$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.
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.
The same as read with the 'brutal' option set to 1.
The same as Query with the 'brutal' option set to 1.
The same as Query with 'read_length' set to 10240.
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'};
Probably few. Mostly because there's not a lot to be done here. Please report.
Lab::Connection::GPIB
Lab::Connection::VISA_GPIB
Lab::Connection::MODBUS
and all the others...
Copyright 2011 Florian Olbrich
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Lab::Measurement, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lab::Measurement
CPAN shell
perl -MCPAN -e shell install Lab::Measurement
For more information on module installation, please visit the detailed CPAN module installation guide.