| 1 | package Lab::Connection::IsoBus; | ||
| 2 | #ABSTRACT: Oxford Instruments IsoBus connection | ||
| 3 | $Lab::Connection::IsoBus::VERSION = '3.881'; | ||
| 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__ | ||
| 88 | |||
| 89 | =pod | ||
| 90 | |||
| 91 | =encoding utf-8 | ||
| 92 | |||
| 93 | =head1 NAME | ||
| 94 | |||
| 95 | Lab::Connection::IsoBus - Oxford Instruments IsoBus connection | ||
| 96 | |||
| 97 | =head1 VERSION | ||
| 98 | |||
| 99 | version 3.881 | ||
| 100 | |||
| 101 | =head1 SYNOPSIS | ||
| 102 | |||
| 103 | This is not called directly. To make an Isobus instrument use Lab::Connection::IsoBus, set | ||
| 104 | the connection_type parameter accordingly: | ||
| 105 | |||
| 106 | $instrument = new ILM210( | ||
| 107 | connection_type => 'IsoBus', | ||
| 108 | isobus_address => 3, | ||
| 109 | ) | ||
| 110 | |||
| 111 | =head1 DESCRIPTION | ||
| 112 | |||
| 113 | C<Lab::Connection::IsoBus> provides a connection with L<Lab::Bus::IsoBus>, | ||
| 114 | transparently handled via a pre-existing bus and connection object (e.g. serial or GPIB). | ||
| 115 | |||
| 116 | It inherits from L<Lab::Connection>. | ||
| 117 | |||
| 118 | =head1 CONSTRUCTOR | ||
| 119 | |||
| 120 | =head2 new | ||
| 121 | |||
| 122 | my $connection = new Lab::Connection::IsoBus( | ||
| 123 | connection_type => 'IsoBus', | ||
| 124 | isobus_address => 3, | ||
| 125 | } | ||
| 126 | |||
| 127 | =head1 METHODS | ||
| 128 | |||
| 129 | This just falls back on the methods inherited from L<Lab::Connection>. | ||
| 130 | |||
| 131 | =head2 config | ||
| 132 | |||
| 133 | Provides unified access to the fields in initial @_ to all the child classes. | ||
| 134 | E.g. | ||
| 135 | |||
| 136 | $IsoBus_Address=$instrument->Config(isobus_address); | ||
| 137 | |||
| 138 | Without arguments, returns a reference to the complete $self->Config aka @_ of the constructor. | ||
| 139 | |||
| 140 | $Config = $connection->Config(); | ||
| 141 | $IsoBus_Address = $connection->Config()->{'isobus_address'}; | ||
| 142 | |||
| 143 | =head1 CAVEATS/BUGS | ||
| 144 | |||
| 145 | Probably few. Mostly because there's not a lot to be done here. Please report. | ||
| 146 | |||
| 147 | =head1 SEE ALSO | ||
| 148 | |||
| 149 | =over 4 | ||
| 150 | |||
| 151 | =item * L<Lab::Connection> | ||
| 152 | |||
| 153 | =item * L<Lab::Bus::IsoBus> | ||
| 154 | |||
| 155 | =back | ||
| 156 | |||
| 157 | =head1 COPYRIGHT AND LICENSE | ||
| 158 | |||
| 159 | This software is copyright (c) 2023 by the Lab::Measurement team; in detail: | ||
| 160 | |||
| 161 | Copyright 2011 Andreas K. Huettel, Florian Olbrich | ||
| 162 | 2012 David Kalok, Florian Olbrich, Stefan Geissler | ||
| 163 | 2013 Stefan Geissler | ||
| 164 | 2016 Simon Reinhardt | ||
| 165 | 2017 Andreas K. Huettel | ||
| 166 | 2020 Andreas K. Huettel | ||
| 167 | |||
| 168 | |||
| 169 | This is free software; you can redistribute it and/or modify it under | ||
| 170 | the same terms as the Perl 5 programming language system itself. | ||
| 171 | |||
| 172 | =cut |