| 1 | package Lab::Connection::VICP; | ||
| 2 | #ABSTRACT: VICP ethernet protocol connection | ||
| 3 | $Lab::Connection::VICP::VERSION = '3.899'; | ||
| 4 | use v5.20; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use Time::HiRes qw (usleep sleep); | ||
| 8 | use Lab::Connection::GPIB; | ||
| 9 | use Carp; | ||
| 10 | use Data::Dumper; | ||
| 11 | |||
| 12 | our @ISA = ("Lab::Connection"); | ||
| 13 | |||
| 14 | our %fields = ( | ||
| 15 | bus_class => 'Lab::Bus::VICP', | ||
| 16 | wait_status => 0, # usec; | ||
| 17 | wait_query => 10e-6, # sec; | ||
| 18 | read_length => 1000, # bytes | ||
| 19 | timeout => 1, # seconds | ||
| 20 | ); | ||
| 21 | |||
| 22 | sub new { | ||
| 23 | my $proto = shift; | ||
| 24 | my $class = ref($proto) || $proto; | ||
| 25 | my $twin = undef; | ||
| 26 | my $self = $class->SUPER::new(@_) | ||
| 27 | ; # getting fields and _permitted from parent class | ||
| 28 | $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__); | ||
| 29 | |||
| 30 | return $self; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub Write { | ||
| 34 | my $self = shift; | ||
| 35 | my $options = undef; | ||
| 36 | if ( ref $_[0] eq 'HASH' ) { $options = shift } | ||
| 37 | else { $options = {@_} } | ||
| 38 | |||
| 39 | my $timeout = $options->{'timeout'} || $self->{timeout}; | ||
| 40 | |||
| 41 | # $self->bus()->timeout( $self->connection_handle(), $timeout ); | ||
| 42 | |||
| 43 | return $self->bus() | ||
| 44 | ->connection_write( $self->connection_handle(), $options ); | ||
| 45 | } | ||
| 46 | |||
| 47 | sub Read { | ||
| 48 | my $self = shift; | ||
| 49 | my $options = undef; | ||
| 50 | if ( ref $_[0] eq 'HASH' ) { $options = shift } | ||
| 51 | else { $options = {@_} } | ||
| 52 | |||
| 53 | my $timeout = $options->{'timeout'} || $self->{timeout}; | ||
| 54 | |||
| 55 | # $self->bus()->timeout( $self->connection_handle(), $timeout ); | ||
| 56 | |||
| 57 | return $self->bus() | ||
| 58 | ->connection_read( $self->connection_handle(), $options ); | ||
| 59 | } | ||
| 60 | |||
| 61 | sub Query { | ||
| 62 | my $self = shift; | ||
| 63 | my $options = undef; | ||
| 64 | if ( ref $_[0] eq 'HASH' ) { $options = shift } | ||
| 65 | else { $options = {@_} } | ||
| 66 | |||
| 67 | $self->Write($options); | ||
| 68 | return $self->Read($options); | ||
| 69 | |||
| 70 | # return $self->bus()->connection_query( $self->connection_handle(), $options ); | ||
| 71 | } | ||
| 72 | |||
| 73 | # | ||
| 74 | # Query from Lab::Connection is sufficient | ||
| 75 | # EnableTermChar, SetTermChar from Lab::Connection::GPIB are sufficient. | ||
| 76 | # | ||
| 77 | |||
| 78 | |||
| 79 | 1; | ||
| 80 | |||
| 81 | __END__ |