Lab::Zhinst - Perl bindings to the LabOne API of Zurich Instruments
use Lab::Zhinst; #################################################### # LabOne's "Getting Started" example in Perl: # Create connection object my ($rv, $connection) = Lab::Zhinst->Init(); if ($rv) { # handle error ... } # Connect to DataServer at localhost, port 8004. ($rv) = $connection->Connect("localhost", 8004); # Set all demodulator rates of device dev1046 to 150 Hz. my ($rv) = $connection->SetValueD("/dev1046/demods/*/rate", 150); #################################################### # Read x and y value from the Lock-In demodulator: my $device = "/dev3281"; my ($rv, $hash_ref) = $connection->GetDemodSample("$device/DEMODS/0/SAMPLE"); printf("x = %g, y = %g\n", $hash_ref->{x}, $hash_ref->{y});
Download the LabOne API for Linux from https://www.zhinst.com.
After unpacking, copy the header API/C/include/ziAPI.h and the library API/C/lib/ziAPI-linux64.so into directories searched by the compiler and linker (e.g. /usr/local/include and /usr/local/lib).
Use your favourite cpan client to install Lab::Zhinst.
you will need something like e.g. local::lib, plenv or perlbrew.
Add the directory which contains the shared library to the LIBRARY_PATH and LD_LIBRARY_PATH environment variables and add the directory which contains the header ziAPI.h to the CPATH environment variable.
You can then install Lab::Zhinst with your favourite cpan client.
See our Travis CI build file for the exact list of needed commands.
For StrawberryPerl, version 5.26 or newer is required. Especially with 64-bit StrawberryPerl it is currently not possible to use earlier versions (see https://rt.cpan.org/Public/Bug/Display.html?id=121219).
Download and install the LabOne API for Windows (MSI installer).
Make sure that the library directory C:\Program Files\Zurich Instruments\LabOne\API\C\lib is included in the PATH environment variable. Otherwise loading the dynamic library Zhinst.xs.dll will fail.
The API provided by this module is basically a one-one mapping of the LabOne C API to Perl5.
For full semantics of the various library functions, we refer to the LabOne manual.
Most ziAPI functions receive a ZIConnection as their first argument. The Init method of this library will create a ZIConnection object and bless it into the Lab::Zhinst class. Most library functions are then called on this Lab::Zhinst object.
Init
Most ziAPI functions return an error code. The Perl functions return lists, where the first element is the error code:
my ($error_code, $first_return_value, $second_return_value) = $connection->foobar(@arguments);
The return values are only valid if $error_code is 0.
$error_code
All non-methods are exported by default.
my ($rv, $connection) = Lab::Zhinst->Init();
Return Lab::Zhinst object. Automatically call ziAPIDestroy on $connection when it goes out of scope.
ziAPIDestroy
$connection
my ($rv) = $connection->Connect($hostname, $port);
my ($rv) = $connection->Disconnect();
my ($rv, $implementations) = ziAPIListImplementations();
my ($rv, $level) = $connection->GetConnectionAPILevel();
my ($rv, $nodes) = $connection->ListNodes($path, $bufferSize, $flags);
$flags has to be bitwise or of ZI_LIST_NODES_NONE, ZI_LIST_NODES_RECURSIVE, ZI_LIST_NODES_ABSOLUTE, ZI_LIST_NODES_LEAFSONLY, ZI_LIST_NODES_SETTINGSONLY.
$flags
my ($rv, $double) = $connection->GetValueD($path);
my ($rv, $integer) = $connection->GetValueI($path);
my ($rv, $hash_ref) = $connection->GetDemodSample($path); # keys: timeStamp, x, y, frequency, phase, dioBits, trigger, auxIn0, auxIn1
my ($rv, $hash_ref) = $connection->GetDIOSample($path); # keys: timeStamp, bits, reserved
my ($rv, $hash_ref) = $connection->GetAuxInSample($path); # keys: timeStamp, ch0, ch1
my ($rv, $byte_string) = $connection->GetValueB($path, $bufferSize);
my ($rv) = $connection->SetValueD($path, $double);
my ($rv) = $connection->SetValueI($path, $integer);
my ($rv) = $connection->SetValueB($path, $byte_string);
my ($rv, $set_value) = $connection->SyncSetValueD($path, $double);
my ($rv, $set_value) = $connection->SyncSetValueI($path, $integer);
my ($rv, $set_value) = $connection->SyncSetValueB($path, $byte_array);
my ($rv) = $connection->Sync();
my ($rv) = $connection->EchoDevice($device_serial);
my ($event) = ziAPIAllocateEventEx();
Return Lab::Zhinst::ZIEvent object or undef on error.
ziAPIDeallocateEventEx will be called on $event when it goes out of scope.
ziAPIDeallocateEventEx
$event
my ($rv) = $connection->Subscribe($path);
my ($rv) = $connection->UnSubscribe($path);
my ($rv, $data) = $connection->PollDataEx($event, $timeout_milliseconds);
$data holds a hashref representing a 'struct ZIEvent'. It has the following structure:
$data
$data = { valueType => $valueType, count => $count, path => $path, values => [@values], };
For scalar data like ZIDoubleData, the elements of @values are scalars. For Samples (Demod, AuxIn, DIO, Impedance, ...) the elements are hashrefs.
@values
my ($rv) = $connection->GetValueAsPollData($path);
my ($rv, $error_string) = ziAPIGetError($result);
my ($rv, $error_string) = $connection->GetLastError($bufferSize);
ziAPISetDebugLevel($level);
ziAPIWriteDebugLog($level, $message);
my ($rv, $device_id) = $connection->DiscoveryFind($device_address);
my ($rv, $json) = $connection->DiscoveryGet($device_id);
Please report bugs at https://github.com/lab-measurement/Lab-Zhinst/issues.
Feel free to contact us at
The #labmeasurement channel on Freenode IRC.
Our mailing list.
Blog post on Lab::Zhinst
Lab::Measurement
USB::TMC
Lab::VXI11
Lab::VISA
Simon Reinhardt, <simon.reinhardt@physik.uni-regensburg.de>
The following license only covers the perl front end to LabOne. LabOne uses different licensing terms, and needs to be installed separately by the user.
Copyright (C) 2017 by Simon Reinhardt
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.24.0 or, at your option, any later version of Perl 5 you may have available.
To install Lab::Zhinst, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lab::Zhinst
CPAN shell
perl -MCPAN -e shell install Lab::Zhinst
For more information on module installation, please visit the detailed CPAN module installation guide.