| 1 | package Lab::Connection::IsoBus; | ||
| 2 | #ABSTRACT: Oxford Instruments IsoBus connection | ||
| 3 | $Lab::Connection::IsoBus::VERSION = '3.899'; | ||
| 4 | use v5.20; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use Lab::Bus::VISA; | ||
| 8 | use Lab::Connection; | ||
| 9 | use Lab::Exception; | ||
| 10 | |||
| 11 | our @ISA = ("Lab::Connection"); | ||
| 12 | |||
| 13 | our %fields = ( | ||
| 14 | bus_class => 'Lab::Bus::IsoBus', | ||
| 15 | isobus_address => undef, | ||
| 16 | wait_status => 0, # usec; | ||
| 17 | wait_query => 10e-6, # sec; | ||
| 18 | read_length => 1000, # bytes | ||
| 19 | ); | ||
| 20 | |||
| 21 | sub new { | ||
| 22 | my $proto = shift; | ||
| 23 | my $class = ref($proto) || $proto; | ||
| 24 | my $twin = undef; | ||
| 25 | my $self = $class->SUPER::new(@_) | ||
| 26 | ; # getting fields and _permitted from parent class, parameter checks | ||
| 27 | $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__); | ||
| 28 | |||
| 29 | return $self; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub _configurebus { # $self->setbus() create new or use existing bus | ||
| 33 | my $self = shift; | ||
| 34 | |||
| 35 | my $base = $self->config('base_connection'); | ||
| 36 | |||
| 37 | # add predefined connection settings to connection config: | ||
| 38 | # no overwriting of user defined connection settings | ||
| 39 | |||
| 40 | my $new_config = $base->config(); | ||
| 41 | for my $key ( keys %{ $self->config() } ) { | ||
| 42 | if ( not defined $base->config($key) ) { | ||
| 43 | $new_config->{$key} = $self->config($key); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | $new_config->{'base_connection'} | ||
| 47 | = undef; # aviod recursive definition of bas_connection | ||
| 48 | $base->config($new_config); | ||
| 49 | $self->config('base_connection')->_configurebus(); | ||
| 50 | |||
| 51 | } | ||
| 52 | |||
| 53 | sub block_connection { | ||
| 54 | my $self = shift; | ||
| 55 | |||
| 56 | $self->{connection_blocked} = 1; | ||
| 57 | $self->{config}->{base_connection}->block_connection(); | ||
| 58 | |||
| 59 | } | ||
| 60 | |||
| 61 | sub unblock_connection { | ||
| 62 | my $self = shift; | ||
| 63 | |||
| 64 | $self->{connection_blocked} = undef; | ||
| 65 | $self->{config}->{base_connection}->unblock_connection(); | ||
| 66 | |||
| 67 | } | ||
| 68 | |||
| 69 | sub is_blocked { | ||
| 70 | my $self = shift; | ||
| 71 | |||
| 72 | if ( $self->{connection_blocked} == 1 | ||
| 73 | or $self->{config}->{base_connection}->is_blocked() ) { | ||
| 74 | return 1; | ||
| 75 | } | ||
| 76 | else { | ||
| 77 | return 0; | ||
| 78 | } | ||
| 79 | |||
| 80 | } | ||
| 81 | |||
| 82 | 1; | ||
| 83 | |||
| 84 | |||
| 85 | 1; | ||
| 86 | |||
| 87 | __END__ |