Lab::Moose::Instrument - Base class for instrument drivers.
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();
The Lab::Moose::Instrument module is a thin wrapper around a connection object. All other Lab::Moose::Instrument::* drivers inherit from this module.
The constructor requires a connection object, which provides Read, Write, Query and Clear methods. You can provide any object, which supports these methods.
Read
Write
Query
Clear
$instrument->write(command => '*RST', timeout => 10);
Call the connection's Write method. The timeout parameter is optional.
my $data = $instrument->binary_read(timeout => 10);
Call the connection's Read method. The timeout parameter is optional.
Like binary_read, but trim trailing whitespace and newline from the result.
binary_read
More precisely, this removes the PROGRAM MESSAGE TERMINATOR (IEEE 488.2 section 7.5).
my $data = $instrument->binary_query(command => '*IDN?', timeout => 10)
Call the connection's Query method. The timeout parameter is optional.
Like binary_query, but trim trailing whitespace and newline from the result.
binary_query
$instrument->clear();
Call the connection's Clear method.
The following functions standardise and simplify the use of MooseX::Params::Validate in instrument drivers. They are only exported on request.
Return mandatory validation parameter for timeout.
Return optional validation parameter for channel. A given argument has to be an 'Int'. The default value is the empty string ''.
Return optional validation parameter for floating point precision. The parameter has to be either 'single' (default) or 'double'.
Return list of validation parameters which shell be used in all query operations, eg. timeout, ....
Return list of validation parameters which shell be used in all write operations, eg. timeout, ....
my ($self, %args) = validated_getter(\@_, %additional_parameter_spec);
Call validated_hash with the getter_params.
validated_hash
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.
setter_params
my ($self, %args) = validated_no_param_setter(\@_, %additional_parameter_spec);
Like validated_setter without the 'value' argument.
validated_setter
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_getter
channel_param
$self-
my ($self, $channel, $value, %args) = validated_channel_setter(\@_);
Analog to validated_channel_getter.
validated_channel_getter
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.