=pod

=head1 NAME

Lab::VISA - Perl interface to National Instruments' VISA library

=head1 SYNOPSIS

    use Lab::VISA;

=head1 DESCRIPTION

This library offers a Perl interface to National Instruments' NI-VISA library.

With this library you can easily control the instruments in your lab (multimeters, voltage
sources, magnet sources, pulse generators etc.) with Perl. You can perform
complicated measurement jobs with just some Perl loops.

It comes even better: The general L<Lab::Instrument|Lab::Instrument> class reduces the
communication overhead to minimal C<read>, C<write> and C<query> methods.
And on top of this, there are specialized instrument classes (virtual instruments) such as
L<Lab::Instrument::HP34401A|Lab::Instrument::HP34401A>, that offer
even more high level comfort with methods as C<read_voltage>.
Everything is prepared so that you can just start the measurement.

The L<Lab::Tools|Lab::Tools> package offers classes to simplify the task
to log data to files and to maintain this data.

This manpage describes the perl syntax of the API. Each function is explained
with some sentences which I cited from [1]. See this manual for further
documentation on the library.

Installation instructions can be found in L<Lab::VISA::Installation>.

A general tutorial for using Lab::VISA and assorted packages is located in L<Lab::VISA::Tutorial>.

[1] NI-VISA Programmer Reference Manual. Part Number 370132C-01.

=head1 FUNCTIONS

=head2 viClear

    $status=Lab::VISA::viClear($vi);

The C<viClear()> operation performs an IEEE 488.1-style clear of the device.

=head2 viClose

    $status=Lab::VISA::viClose($object);

The C<viClose()> operation closes a session, event, or a find list. In this process all the data
structures that had been allocated for the specified vi are freed. Calling C<viClose()> on a
VISA Resource Manager session will also close all I/O sessions associated with that resource
manager session.

=head2 viFindNext

    ($status, $instrDesc)=
        Lab::VISA::viFindNext($findList);

The C<viFindNext()> operation returns the next device found in the list created by
C<viFindRsrc()>. The list is referenced by the handle that was returned by C<viFindRsrc()>.

=head2 viFindRsrc

    ($status, $findList, $retcnt, $instrDesc)=
        Lab::VISA::viFindRsrc($sesn, $expr);

The C<viFindRsrc()> operation matches the value specified in the C<expr> parameter with the
resources available for a particular interface.

On successful completion, this function returns the first resource found (C<instrDesc>) and
returns a count (C<retcnt>) to indicate if there were more resources found for the designated
interface. This function also returns, in the C<findList> parameter, a handle to a find list.
This handle points to the list of resources and it must be used as an input to C<viFindNext()>.
When this handle is no longer needed, it should be passed to C<viClose()>.

The search criteria specified in the C<expr> parameter has two parts: a regular expression over
a resource string and an optional logical expression over attribute values. The regular
expression is matched against the resource strings of resources known to the VISA Resource
Manager. If the resource string matches the regular expression, the attribute values of the
resource are then matched against the expression over attribute values. If the match is
successful, the resource has met the search criteria and gets added to the list of resources
found.

All resource strings returned by C<viFindRsrc()> will always be recognized by
C<viOpen()>. However, C<viFindRsrc()> will not necessarily return all strings that you can pass
to C<viParseRsrc()> or C<viOpen()>. This is especially true for network and C<TCPIP> resources.

=head2 viGetAttribute

    ($status, $attrState)=
        Lab::VISA::viGetAttribute($object, $attribute);

The C<viGetAttribute()> operation is used to retrieve the state of an attribute for the
specified session, event, or find list.

=head2 viOpen

    ($status, $vi)=
        Lab::VISA::viOpen($sesn, $rsrcName, $accessMode, $openTimeout);

The C<viOpen()> operation opens a session to the specified resource. It returns a session
identifier that can be used to call any other operations of that resource. The address string
passed to C<viOpen()> must uniquely identify a resource.

For the parameter accessMode, the value C<VI_EXCLUSIVE_LOCK> (1) is used to acquire an
exclusive lock immediately upon opening a session; if a lock cannot be acquired, the session
is closed and an error is returned. The value C<VI_LOAD_CONFIG> (4) is used to configure
attributes to values specified by some external configuration utility. Multiple access modes
can be used simultaneously by specifying a bit-wise OR of the values other than C<VI_NULL>.
NI-VISA currently supports C<VI_LOAD_CONFIG> only on Serial INSTR sessions.

=head2 viOpenDefaultRM

    ($status, $sesn)=
        Lab::VISA::viOpenDefaultRM();

The C<viOpenDefaultRM()> function must be called before any VISA operations can be
invoked. The first call to this function initializes the VISA system, including the Default
Resource Manager resource, and also returns a session to that resource. Subsequent calls
to this function return unique sessions to the same Default Resource Manager resource.

When a Resource Manager session is passed to C<viClose()>, not only is that session closed,
but also all find lists and device sessions (which that Resource Manager session was used to
create) are closed.

=head2 viRead

    ($status, $buf, $retCount)=
        Lab::VISA::viRead($vi, $count);

The C<viRead()> operation synchronously transfers data. The data read is to be stored in the
buffer represented by buf. This operation returns only when the transfer terminates. Only one
synchronous read operation can occur at any one time.

=head2 viSetAttribute

    $status=Lab::VISA::viSetAttribute($vi, $attribute, $attrState);

The C<viSetAttribute()> operation is used to modify the state of an attribute for the specified
object.

=head2 viWrite

    ($status, $retCount)=
        Lab::VISA::viWrite($vi, $buf, $count);

The C<viWrite()> operation synchronously transfers data. The data to be written is in the buffer
represented by buf. This operation returns only when the transfer terminates. Only one
synchronous write operation can occur at any one time.

=head1 CAVEATS/BUGS

Probably many.

I have tested this on Linux and Windows. Compilation is a little tricky if you don't have
much experience (I didn't have much), but definitely possible. See the L<README> file for
more information.

Not all API functions are supported, just the ones that I needed. Only GPIB connections
are tested so far.

=head1 SEE ALSO

=over 4

=item L<Lab::Instrument>

=item L<Lab::Tools>

=item L<GPIB>

This module can also provide instrument connectivity from perl, but builds on top
of GPIB instead of the higher level VISA. I could never make it work properly.
It seems to be unmaintained for a while.

=item L<http://pyvisa.sourceforge.net/>

As the website states, the PyVISA package enables you to control all kinds of measurement
equipment through various busses (GPIB, RS232, USB) with Python programs.

This project was indicated to me only recently by a Lab::VISA user. It looks very similar.

=back

=head1 AUTHOR/COPYRIGHT

This is $Id: VISA.pod 656 2010-04-23 20:09:05Z schroeer $

This swig-based interface is

 (c) 2004-2006 Daniel Schröer
 (c) 2007-2010 Daniel Schröer, Andreas Hüttel, Daniela Taubert, and others 

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

For the rest National Instruments or the VXI Consortium will probably have a word to say. See
National Instrument's license for the NI-VISA library.

=cut
