++ed by:
AMBA

1 PAUSE user
1 non-PAUSE user.

Andreas K. Hüttel
and 4 contributors

NAME

Lab::Moose::Instrument - Base class for instrument drivers.

SYNOPSIS

A complete device driver based on Lab::Moose::Instrument:

 package Lab::Moose::Instrument::FooBar;
 use Moose;
 
 use Lab::Moose::Instrument qw/validated_getter validated_setter/;

 use namespace::autoclean;
 
 extends 'Lab::Moose::Instrument';

 sub get_foo {
     my ($self, %args) = validated_getter(\@_);
     return $self->query(command => "Foo?", %args);
 }
 
 sub set_foo {
     my ($self, $value, %args) = validated_setter(\@_);
     return $self->write(command => "Foo $value", %args);
 }

 __PACKAGE__->meta->make_immutable();

DESCRIPTION

The Lab::Moose::Instrument module is a thin wrapper around a connection object. All other Lab::Moose::Instrument::* drivers inherit from this module.

METHODS

new

The constructor requires a connection object, which provides Read, Write, Query and Clear methods. You can provide any object, which supports these methods.

write

 $instrument->write(command => '*RST', timeout => 10);

Call the connection's Write method. The timeout parameter is optional.

binary_read

 my $data = $instrument->binary_read(timeout => 10);

Call the connection's Read method. The timeout parameter is optional.

read

Like binary_read, but trim trailing whitespace and newline from the result.

More precisely, this removes the PROGRAM MESSAGE TERMINATOR (IEEE 488.2 section 7.5).

binary_query

 my $data = $instrument->binary_query(command => '*IDN?', timeout => 10)

Call the connection's Query method. The timeout parameter is optional.

query

Like binary_query, but trim trailing whitespace and newline from the result.

More precisely, this removes the PROGRAM MESSAGE TERMINATOR (IEEE 488.2 section 7.5).

clear

 $instrument->clear();

Call the connection's Clear method.

Functions

The following functions standardise and simplify the use of MooseX::Params::Validate in instrument drivers. They are only exported on request.

timeout_param

Return mandatory validation parameter for timeout.

channel_param

Return optional validation parameter for channel. A given argument has to be an 'Int'. The default value is the empty string ''.

precision_param

Return optional validation parameter for floating point precision. The parameter has to be either 'single' (default) or 'double'.

getter_params

Return list of validation parameters which shell be used in all query operations, eg. timeout, ....

setter_params

Return list of validation parameters which shell be used in all write operations, eg. timeout, ....

validated_getter

 my ($self, %args) = validated_getter(\@_, %additional_parameter_spec);

Call validated_hash with the getter_params.

validated_setter

 my ($self, $value, %args) = validated_setter(\@_, %additional_parameter_spec);

Call validated_hash with the setter_params and a mandatory 'value' argument, which must be of 'Str' type.

validated_no_param_setter

 my ($self, %args) = validated_no_param_setter(\@_, %additional_parameter_spec);

Like validated_setter without the 'value' argument.

validated_channel_getter

 my ($self, $channel, %args) = validated_channel_getter(\@_);

Like validated_getter with an additional channel_param argument. If the no channel argument is given, try to call $self-cached_instrument_nselect>. If this method is not available, return the empty string for the channel.

validated_channel_setter

 my ($self, $channel, $value, %args) = validated_channel_setter(\@_);

Analog to validated_channel_getter.