| 1 | package Lab::Connection::GPIB; | ||
| 2 | #ABSTRACT: GPIB Connection base class | ||
| 3 | $Lab::Connection::GPIB::VERSION = '3.899'; | ||
| 4 | use v5.20; | ||
| 5 | |||
| 6 | # | ||
| 7 | # This is the GPIB Connection base class. It provides the interface definition for all | ||
| 8 | # connections implementing the GPIB protocol. | ||
| 9 | # | ||
| 10 | # In your scripts, use the implementing classes (e.g. Lab::Connection::LinuxGPIB). | ||
| 11 | # | ||
| 12 | # Instruments using a GPIB connection will check the inheritance tree of the provided connection | ||
| 13 | # for this class. | ||
| 14 | # | ||
| 15 | # | ||
| 16 | # TODO: Access to GPIB attributes, device clear, ... | ||
| 17 | # | ||
| 18 | |||
| 19 | use Lab::Connection; | ||
| 20 | use strict; | ||
| 21 | use Lab::Exception; | ||
| 22 | |||
| 23 | our @ISA = ("Lab::Connection"); | ||
| 24 | |||
| 25 | our %fields = ( | ||
| 26 | bus_class => undef, # 'Lab::Bus::LinuxGPIB', 'Lab::Bus::VISA', ... | ||
| 27 | gpib_address => undef, | ||
| 28 | gpib_saddress => undef, # secondary address, if needed | ||
| 29 | brutal => 0, # brutal as default? | ||
| 30 | wait_status => 0, # sec; | ||
| 31 | wait_query => 10e-6, # sec; | ||
| 32 | read_length => 1000, # bytes | ||
| 33 | ); | ||
| 34 | |||
| 35 | sub new { | ||
| 36 | my $proto = shift; | ||
| 37 | my $class = ref($proto) || $proto; | ||
| 38 | my $self = $class->SUPER::new(@_) | ||
| 39 | ; # getting fields and _permitted from parent class | ||
| 40 | $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__); | ||
| 41 | |||
| 42 | # # Parameter checking | ||
| 43 | # if( !defined $self->config('gpib_address') || $self->config('gpib_address') !~ /^[0-9]*$/ ) { | ||
| 44 | # Lab::Exception::CorruptParameter->throw( error => "No GPIB address specified! I can't work like this.\n" ); | ||
| 45 | # } | ||
| 46 | |||
| 47 | return $self; | ||
| 48 | } | ||
| 49 | |||
| 50 | # | ||
| 51 | # These are the method stubs you have to overwrite when implementing the GPIB connection for your | ||
| 52 | # hardware/driver. See documentation for detailed description of the parameters, expected exceptions | ||
| 53 | # and expected return values. | ||
| 54 | # | ||
| 55 | # You might just be satisfied with the generic ones from Lab::Connection, take a look at them. | ||
| 56 | # | ||
| 57 | |||
| 58 | # sub Clear { # @_ = () | ||
| 59 | # return 0; | ||
| 60 | # } | ||
| 61 | |||
| 62 | # sub Write { # @_ = ( command => $cmd, wait_status => $wait_status, brutal => 1/0 ) | ||
| 63 | # return 0; # status true/false | ||
| 64 | # } | ||
| 65 | |||
| 66 | # sub Read { # @_ = ( read_length => $read_length, brutal => 1/0 ) | ||
| 67 | # return 0; # result | ||
| 68 | # } | ||
| 69 | # now comes GPIB-specific stuff | ||
| 70 | |||
| 71 | sub EnableTermChar { # 0/1 off/on | ||
| 72 | my $self = shift; | ||
| 73 | my $enable = shift; | ||
| 74 | my $result = $self->bus() | ||
| 75 | ->connection_enabletermchar( $self->connection_handle(), $enable ); | ||
| 76 | return $result; | ||
| 77 | } | ||
| 78 | |||
| 79 | sub SetTermChar { # the character as string | ||
| 80 | my $self = shift; | ||
| 81 | my $termchar = shift; | ||
| 82 | my $result = $self->bus() | ||
| 83 | ->connection_settermchar( $self->connection_handle(), $termchar ); | ||
| 84 | return $result; | ||
| 85 | } | ||
| 86 | |||
| 87 | # | ||
| 88 | # perform a serial poll on the bus and return the status byte | ||
| 89 | # Returns an array with index 0=>LSB, 8=>MSB of the status byte | ||
| 90 | # | ||
| 91 | sub serial_poll { | ||
| 92 | use bytes; | ||
| 93 | my $self = shift; | ||
| 94 | my $statbyte = $self->bus()->serial_poll( $self->connection_handle() ); | ||
| 95 | my @stat = (); | ||
| 96 | |||
| 97 | for ( my $i = 0; $i < 8; $i++ ) { | ||
| 98 | $stat[$i] = 0x01 & ( $statbyte >> $i ); | ||
| 99 | } | ||
| 100 | return @stat; | ||
| 101 | |||
| 102 | #return (split(//, unpack('b*', pack('N',$self->bus()->serial_poll($self->connection_handle())))))[-8..-1]; | ||
| 103 | } | ||
| 104 | |||
| 105 | 1; | ||
| 106 | |||
| 107 | |||
| 108 | 1; | ||
| 109 | |||
| 110 | __END__ |