The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Lab::Instrument - General instrument package

SYNOPSIS

Lab::Instrument is meant to be used as a base class for inheriting instruments. For very simple applications it can also be used directly. Every inheriting class constructor should start as follows:

  sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self = $class->SUPER::new(@_);
    $self->_construct(__PACKAGE__);  # check for supported connections, initialize fields etc.
    ...
  }

Beware that only the first set of parameters specific to an individual GPIB board or any other bus hardware gets used. Settings for EOI assertion for example. Right now, this doesn't really matter because the options aren't there yet, you just can't set anything. :) Just keep it in mind.

If you know what you're doing or you have an exotic scenario you can use the connection parameter "IgnoreTwin => 1", but this is discouraged - it will kill bus management and you might run into hardware/resource sharing issues.

DESCRIPTION

Lab::Instrument is the base class for Instruments. It doesn't do much by itself, but is meant to be inherited in specific instrument drivers. It provides general read, write and query methods and basic connection handling (internal, _set_connection, _check_connection).

The connection object can be obtained by calling connection().

Also, fields common to all instrument classes are created and set to default values where applicable, e.g.:

  connection => undef,
  connection_type => "",
  supported_connections => [ ],
  config => {},

CONSTRUCTOR

new

This blesses $self (don't do it in an inheriting class!), initializes the basic "fields" to be accessed via AUTOLOAD and puts the configuration hash in $self->Config to be accessed in methods and inherited classes.

Arguments: just the configuration hash passed along from a child class constructor.

METHODS

write

 $instrument->write($command);
 

Sends the command $command to the instrument. An option hash can be supplied as second or also as only argument. Generally, all options are passed to the connection, so additional options may be supported based on the connection.

read

 $result=$instrument->read({ ReadLength => <max length>, Brutal => <1/0>);

Reads a result of ReadLength from the instrument and returns it. Returns an exception on error.

If the parameter Brutal is set, a timeout in the connection will not result in an Exception thrown, but will return the data obtained until the timeout without further comment. Be aware that this data is also contained in the the timeout exception object (see Lab::Exception).

Generally, all options are passed to the connection, so additional options may be supported based on the connection.

query

 $result=$instrument->query({ Cmd => $command, WaitQuery => $wait_query, ReadLength => $max length, 
                              WaitStatus => $wait_status);

Sends the command $command to the instrument and reads a result from the instrument and returns it. The length of the read buffer is set to ReadLength or to the default set in the connection.

Waits for WaitQuery microseconds before trying to read the answer.

WaitStatus not implemented yet - needed?

The default value of 'wait_query' can be overwritten by defining the corresponding object key.

Generally, all options are passed to the connection, so additional options may be supported based on the connection.

connection

 $connection=$instrument->connection();

Returns the connection object used by this instrument. It can then be passed on to another object on the same connection, or be used to change connection parameters.

WriteConfig

this is NOT YET IMPLEMENTED in this base class so far

 $instrument->WriteConfig( 'TRIGGER' => { 'SOURCE' => 'CHANNEL1',
                                                          'EDGE'   => 'RISE' },
                       'AQUIRE'  => 'HRES',
                       'MEASURE' => { 'VRISE' => 'ON' });

Builds up the commands and sends them to the instrument. To get the correct format a command rules hash has to be set up by the driver package

e.g. for SCPI commands $instrument->{'CommandRules'} = { 'preCommand' => ':', 'inCommand' => ':', 'betweenCmdAndData' => ' ', 'postData' => '' # empty entries can be skipped };

CAVEATS/BUGS

Probably many, with all the porting. This will get better.

SEE ALSO

AUTHOR/COPYRIGHT

 Copyright 2004-2006 Daniel Schröer <schroeer@cpan.org>, 
           2009-2010 Daniel Schröer, Andreas K. Hüttel (L<http://www.akhuettel.de/>) and David Kalok,
           2010      Matthias Völker <mvoelker@cpan.org>
           2011      Florian Olbrich, Andreas K. Hüttel

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.