| 1 | package Lab::Moose::Connection::VISA::GPIB; | ||
| 2 | $Lab::Moose::Connection::VISA::GPIB::VERSION = '3.931'; | ||
| 3 | #ABSTRACT: GPIB frontend to National Instruments' VISA library. | ||
| 4 | |||
| 5 | use v5.20; | ||
| 6 | |||
| 7 | |||
| 8 | |||
| 9 | use Moose; | ||
| 10 | use Moose::Util::TypeConstraints qw(enum); | ||
| 11 | |||
| 12 | use Carp; | ||
| 13 | |||
| 14 | use namespace::autoclean; | ||
| 15 | |||
| 16 | extends 'Lab::Moose::Connection::VISA'; | ||
| 17 | |||
| 18 | has pad => ( | ||
| 19 | is => 'ro', | ||
| 20 | isa => enum( [ ( 0 .. 30 ) ] ), | ||
| 21 | predicate => 'has_pad', | ||
| 22 | writer => '_pad' | ||
| 23 | ); | ||
| 24 | |||
| 25 | has gpib_address => ( | ||
| 26 | is => 'ro', | ||
| 27 | isa => enum( [ ( 0 .. 30 ) ] ), | ||
| 28 | predicate => 'has_gpib_address' | ||
| 29 | ); | ||
| 30 | |||
| 31 | has sad => ( | ||
| 32 | is => 'ro', | ||
| 33 | isa => enum( [ 0, ( 96 .. 126 ) ] ), | ||
| 34 | predicate => 'has_sad', | ||
| 35 | ); | ||
| 36 | |||
| 37 | has board_index => ( | ||
| 38 | is => 'ro', | ||
| 39 | isa => 'Int', | ||
| 40 | default => 0, | ||
| 41 | ); | ||
| 42 | |||
| 43 | has '+resource_name' => ( | ||
| 44 | required => 0, | ||
| 45 | ); | ||
| 46 | |||
| 47 | sub gen_resource_name { | ||
| 48 | my $self = shift; | ||
| 49 | if ( $self->has_gpib_address() ) { | ||
| 50 | $self->_pad( $self->gpib_address() ); | ||
| 51 | } | ||
| 52 | |||
| 53 | if ( not $self->has_pad() ) { | ||
| 54 | croak "no primary GPIB address provided"; | ||
| 55 | } | ||
| 56 | |||
| 57 | my $resource_name = "GPIB" . $self->board_index() . '::' . $self->pad(); | ||
| 58 | if ( $self->has_sad ) { | ||
| 59 | $resource_name .= '::' . $self->sad(); | ||
| 60 | } | ||
| 61 | $resource_name .= '::INSTR'; | ||
| 62 | return $resource_name; | ||
| 63 | } | ||
| 64 | |||
| 65 | __PACKAGE__->meta->make_immutable(); | ||
| 66 | |||
| 67 | 1; | ||
| 68 | |||
| 69 | __END__ |