| 1 | package Lab::Instrument::ITC; | ||
| 2 | #ABSTRACT: Oxford Instruments ITC Intelligent Temperature Control | ||
| 3 | $Lab::Instrument::ITC::VERSION = '3.899'; | ||
| 4 | use v5.20; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use Lab::Instrument; | ||
| 8 | use Lab::MultiChannelInstrument; | ||
| 9 | |||
| 10 | our @ISA = ( 'Lab::MultiChannelInstrument', 'Lab::Instrument' ); | ||
| 11 | |||
| 12 | our %fields = ( | ||
| 13 | supported_connections => [ | ||
| 14 | 'VISA', 'VISA_GPIB', 'GPIB', 'VISA_RS232', 'RS232', 'IsoBus', 'DEBUG' | ||
| 15 | ], | ||
| 16 | |||
| 17 | # default settings for the supported connections | ||
| 18 | connection_settings => { | ||
| 19 | gpib_board => undef, | ||
| 20 | gpib_address => undef, | ||
| 21 | baudrate => 9600, | ||
| 22 | databits => 8, | ||
| 23 | stopbits => 2, | ||
| 24 | parity => 'none', | ||
| 25 | handshake => 'none', | ||
| 26 | termchar => "\r", | ||
| 27 | timeout => 2, | ||
| 28 | }, | ||
| 29 | |||
| 30 | device_settings => { | ||
| 31 | id => 'Oxford ITC', | ||
| 32 | read_default => 'device', | ||
| 33 | channels => { | ||
| 34 | Ch1 => 1, | ||
| 35 | Ch2 => 2, | ||
| 36 | Ch3 => 3 | ||
| 37 | }, | ||
| 38 | channel_default => 'Ch1', | ||
| 39 | channel => undef | ||
| 40 | }, | ||
| 41 | |||
| 42 | device_cache => { | ||
| 43 | T => undef, | ||
| 44 | proportional => undef, | ||
| 45 | integral => undef, | ||
| 46 | derivative => undef | ||
| 47 | |||
| 48 | }, | ||
| 49 | |||
| 50 | multichannel_shared_cache => | ||
| 51 | [ "id", "proportional", "integral", "derivative" ], | ||
| 52 | |||
| 53 | ); | ||
| 54 | |||
| 55 | sub new { | ||
| 56 | my $proto = shift; | ||
| 57 | my $class = ref($proto) || $proto; | ||
| 58 | my $self = $class->SUPER::new(@_); | ||
| 59 | $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__); | ||
| 60 | |||
| 61 | return $self; | ||
| 62 | } | ||
| 63 | |||
| 64 | sub _device_init { | ||
| 65 | my $self = shift; | ||
| 66 | |||
| 67 | $self->_set_control(3); # REMOTE & unlocked | ||
| 68 | $self->clear(); | ||
| 69 | } | ||
| 70 | |||
| 71 | sub _get_parameter { # internal only | ||
| 72 | |||
| 73 | # 0 Demand SET TEMPERATURE | ||
| 74 | # 1 Sensor 1 Temperature | ||
| 75 | # 2 Sensor 2 Temperature | ||
| 76 | # 3 Sensor 3 Temperature | ||
| 77 | # 4 Temperature Error (+ve when SET>Measured) | ||
| 78 | # 5 Heater O/P (as % of current limit) | ||
| 79 | # 6 Heater O/P (as Volts, approx) | ||
| 80 | # 7 Gas Flow O/P (arbitratry units) | ||
| 81 | # 8 Proportional Band | ||
| 82 | # 9 Integral Action Time | ||
| 83 | #10 Derivative Actionb Time | ||
| 84 | #11 Channel 1 Freq/4 | ||
| 85 | #12 Channel 2 Freq/4 | ||
| 86 | #13 Channel 3 Freq/4 | ||
| 87 | |||
| 88 | my $self = shift; | ||
| 89 | my ( $parameter, $tail ) = $self->_check_args( \@_, ['parameter'] ); | ||
| 90 | |||
| 91 | if ( $parameter != 0 | ||
| 92 | and $parameter != 1 | ||
| 93 | and $parameter != 2 | ||
| 94 | and $parameter != 3 | ||
| 95 | and $parameter != 4 | ||
| 96 | and $parameter != 5 | ||
| 97 | and $parameter != 6 | ||
| 98 | and $parameter != 7 | ||
| 99 | and $parameter != 8 | ||
| 100 | and $parameter != 9 | ||
| 101 | and $parameter != 10 | ||
| 102 | and $parameter != 11 | ||
| 103 | and $parameter != 12 | ||
| 104 | and $parameter != 13 ) { | ||
| 105 | Lab::Exception::CorruptParameter->throw( error => | ||
| 106 | "unexpected value for MODE in sub read_parameter. Expected values are:\n 0 --> Demand SET TEMPERATURE\n 1 --> Sensor 1 Temperature\n 2 --> Sensor 2 Temperature\n 3 --> Sensor 3 Temperature\n 4 --> Temperature Error (+ve when SET>Measured)\n 5 --> Heater O/P (as % of current limit)\n 6 --> Heater O/P (as Volts, approx)\n 7 --> Gas Flow O/P (arbitratry units)\n 8 --> Proportional Band\n 9 --> Integral Action Time\n10 --> Derivative Actionb Time\n11 --> Channel 1 Freq/4\n12 --> Channel 2 Freq/4\n13 --> Channel 3 Freq/4" | ||
| 107 | ); | ||
| 108 | } | ||
| 109 | |||
| 110 | my $cmd = sprintf( "R%d\r", $parameter ); | ||
| 111 | my $result = $self->query( $cmd, $tail ); | ||
| 112 | chomp $result; | ||
| 113 | $result =~ s/^R//; | ||
| 114 | return sprintf( "%e", $result ); | ||
| 115 | } | ||
| 116 | |||
| 117 | sub get_value { | ||
| 118 | my $self = shift; | ||
| 119 | return $self->get_T(@_); | ||
| 120 | } | ||
| 121 | |||
| 122 | sub get_T { # basic | ||
| 123 | my $self = shift; | ||
| 124 | my ( $sensor, $tail ) = $self->_check_args( \@_, ['channel'] ); | ||
| 125 | |||
| 126 | if ( $sensor != 1 and $sensor != 2 and $sensor != 3 ) { | ||
| 127 | $sensor = $self->{channel} || 1; | ||
| 128 | } | ||
| 129 | |||
| 130 | my $cmd = sprintf( "R%d\r", $sensor ); | ||
| 131 | |||
| 132 | my $result = $self->request($cmd); | ||
| 133 | chomp $result; | ||
| 134 | $result =~ s/^R//; | ||
| 135 | return $result; | ||
| 136 | |||
| 137 | } | ||
| 138 | |||
| 139 | sub set_T { # basic | ||
| 140 | |||
| 141 | # Setpoint | ||
| 142 | my $self = shift; | ||
| 143 | my ( $value, $tail ) = $self->_check_args( \@_, ['value'] ); | ||
| 144 | |||
| 145 | if ( not defined $value or $value > 200 or $value < 0 ) { | ||
| 146 | Lab::Exception::CorruptParameter->throw( error => | ||
| 147 | "unexpected value for SETPOINT in sub set_T. Expected values are between 0 .. 200 K" | ||
| 148 | ); | ||
| 149 | } | ||
| 150 | |||
| 151 | $value = sprintf( "%.3f", $value ); | ||
| 152 | $self->query( "T$value\r", $tail ); | ||
| 153 | } | ||
| 154 | |||
| 155 | sub _get_version { # internal only | ||
| 156 | my $self = shift; | ||
| 157 | my ($tail) = $self->_check_args( \@_, [] ); | ||
| 158 | return $self->query( "V\r", $tail ); | ||
| 159 | } | ||
| 160 | |||
| 161 | sub _get_status { # internal only | ||
| 162 | |||
| 163 | # Examine Status | ||
| 164 | my $self = shift; | ||
| 165 | my ($tail) = $self->_check_args( \@_, [] ); | ||
| 166 | |||
| 167 | my $result = $self->query("X\r"); | ||
| 168 | |||
| 169 | $result =~ m/^X([0-9])A([0-9])C([0-9])S([0-9]{1,2})H([0-9])L([0-9])$/; | ||
| 170 | |||
| 171 | $result = { | ||
| 172 | status => $1, | ||
| 173 | auto => $2, | ||
| 174 | control => $3, | ||
| 175 | sweep_status => $4, | ||
| 176 | heater_control => $5, | ||
| 177 | auto_pid => $6 | ||
| 178 | }; | ||
| 179 | |||
| 180 | if ( wantarray() ) { | ||
| 181 | return ( $1, $2, $3, $4, $5, $6 ); | ||
| 182 | } | ||
| 183 | else { | ||
| 184 | return $result; | ||
| 185 | } | ||
| 186 | |||
| 187 | } | ||
| 188 | |||
| 189 | sub _set_control | ||
| 190 | { # don't use it if you get an error message during reading out sensors:"Cading Sensor"; # internal only | ||
| 191 | |||
| 192 | # 0 Local & Locked | ||
| 193 | # 1 Remote & Locked | ||
| 194 | # 2 Local & Unlocked | ||
| 195 | # 3 Remote & Unlocked | ||
| 196 | my $self = shift; | ||
| 197 | my ( $mode, $tail ) = $self->_check_args( \@_, ['mode'] ); | ||
| 198 | |||
| 199 | if ( $mode != 0 and $mode != 1 and $mode != 2 and $mode != 3 ) { | ||
| 200 | Lab::Exception::CorruptParameter->throw( error => | ||
| 201 | "unexpected value for MODE in sub _set_control. Expected values are:\n 0 --> Local & Locked\n 1 --> Remote & Locked\n 2 --> Local & Unlocked\n 3 --> Remote & Unlocked" | ||
| 202 | ); | ||
| 203 | } | ||
| 204 | my $cmd = sprintf( "C%d\r", $mode ); | ||
| 205 | $self->query( $cmd, $tail ); | ||
| 206 | |||
| 207 | #sleep(1); | ||
| 208 | } | ||
| 209 | |||
| 210 | # | ||
| 211 | sub _set_communicationsprotocol { # internal only | ||
| 212 | |||
| 213 | # 0 "Normal" (default) | ||
| 214 | # 2 Sends <LF> after each <CR> | ||
| 215 | my $self = shift; | ||
| 216 | my ( $mode, $tail ) = $self->_check_args( \@_, ['mode'] ); | ||
| 217 | |||
| 218 | if ( $mode != 0 and $mode != 2 ) { | ||
| 219 | Lab::Exception::CorruptParameter->throw( error => | ||
| 220 | "unexpected value for MODE in sub set_comunicationsprotocol. Expected values are:\n 0 --> Normal (default)\n 2 --> Sends <LF> after each <CR>" | ||
| 221 | ); | ||
| 222 | } | ||
| 223 | |||
| 224 | $self->write( "Q$mode\r", $tail ); #no aswer from ITC expected | ||
| 225 | } | ||
| 226 | |||
| 227 | sub set_heatercontrol { # basic | ||
| 228 | |||
| 229 | # 0 Heater Manual, Gas Manual; | ||
| 230 | # 1 Heater Auto, Gas Manual | ||
| 231 | # 2 Heater Manual, Gas Auto | ||
| 232 | # 3 Heater Auto, Gas Auto | ||
| 233 | my $self = shift; | ||
| 234 | my ( $mode, $tail ) = $self->_check_args( \@_, ['mode'] ); | ||
| 235 | |||
| 236 | if ( $mode =~ /\b(MANUAL|manual|MAN|man)\b/ ) { | ||
| 237 | $self->query( "A0\r", $tail ); | ||
| 238 | } | ||
| 239 | elsif ( $mode =~ /\b(AUTOMATIC|automatic|AUTO|auto)\b/ ) { | ||
| 240 | $self->query( "A1\r", $tail ); | ||
| 241 | } | ||
| 242 | else { | ||
| 243 | Lab::Exception::CorruptParameter->throw( error => | ||
| 244 | "unexpected value for MODE in sub set_heatercontrol. Expected values are:\n 0 --> Heater Manual, Gas Manual\n 1 --> Heater Auto" | ||
| 245 | ); | ||
| 246 | } | ||
| 247 | |||
| 248 | } | ||
| 249 | |||
| 250 | sub set_proportional { # internal only | ||
| 251 | my $self = shift; | ||
| 252 | my ( $value, $tail ) = $self->_check_args( \@_, ['value'] ); | ||
| 253 | |||
| 254 | $value = sprintf( "%.3f", $value ); | ||
| 255 | $self->query( "P$value\r", $tail ); | ||
| 256 | } | ||
| 257 | |||
| 258 | sub get_proportional { | ||
| 259 | my $self = shift; | ||
| 260 | my ($tail) = $self->_check_args( \@_, [] ); | ||
| 261 | |||
| 262 | return $self->_get_parameter( 8, $tail ); | ||
| 263 | } | ||
| 264 | |||
| 265 | sub set_integral { # internal only | ||
| 266 | my $self = shift; | ||
| 267 | my ( $value, $tail ) = $self->_check_args( \@_, ['value'] ); | ||
| 268 | |||
| 269 | $value = sprintf( "%.1f", $value ); | ||
| 270 | $self->query( "I$value\r", $tail ); | ||
| 271 | } | ||
| 272 | |||
| 273 | sub get_integral { | ||
| 274 | my $self = shift; | ||
| 275 | my ($tail) = $self->_check_args( \@_, [] ); | ||
| 276 | |||
| 277 | return $self->_get_parameter( 9, $tail ); | ||
| 278 | } | ||
| 279 | |||
| 280 | sub set_derivative { # internal only | ||
| 281 | my $self = shift; | ||
| 282 | my ( $value, $tail ) = $self->_check_args( \@_, ['value'] ); | ||
| 283 | |||
| 284 | $value = sprintf( "%.1f", $value ); | ||
| 285 | $self->query( "D$value\r", $tail ); | ||
| 286 | } | ||
| 287 | |||
| 288 | sub get_derivative { | ||
| 289 | my $self = shift; | ||
| 290 | my ($tail) = $self->_check_args( \@_, [] ); | ||
| 291 | |||
| 292 | return $self->_get_parameter( 10, $tail ); | ||
| 293 | } | ||
| 294 | |||
| 295 | sub set_PID { # basic | ||
| 296 | my $self = shift; | ||
| 297 | my ( $P, $I, $D ) = $self->_check_args( \@_, [ 'P', 'I', 'D' ] ); | ||
| 298 | |||
| 299 | if ( ( defined $P ) and ( $P eq "auto" or $P eq "AUTO" ) ) { | ||
| 300 | $self->query("L1\r"); # enable AUTO-PID | ||
| 301 | } | ||
| 302 | elsif ( ( defined $P ) and ( $P eq "man" or $P eq "MAN" ) ) { | ||
| 303 | $self->query("L0\r"); # disable AUTO-PID | ||
| 304 | } | ||
| 305 | elsif ( ( not defined $P or not defined $I or not defined $D ) ) { | ||
| 306 | Lab::Exception::CorruptParameter->throw( error => | ||
| 307 | "unexpected values for PID in sub set_PID. Exactly three arguments are required." | ||
| 308 | ); | ||
| 309 | } | ||
| 310 | else { | ||
| 311 | $self->query("L0\r"); # disable AUTO-PID | ||
| 312 | $self->set_proportional($P); | ||
| 313 | $self->set_integral($I); | ||
| 314 | $self->set_derivative($D); | ||
| 315 | } | ||
| 316 | |||
| 317 | } | ||
| 318 | |||
| 319 | sub set_heatersensor { # basic | ||
| 320 | |||
| 321 | # 1 Sensor 1 | ||
| 322 | # 2 Sensor 2 | ||
| 323 | # 3 Sensor 3 | ||
| 324 | my $self = shift; | ||
| 325 | my ( $sensor, $tail ) = $self->_check_args( \@_, ['channel'] ); | ||
| 326 | |||
| 327 | if ( $sensor != 1 and $sensor != 2 and $sensor != 3 ) { | ||
| 328 | Lab::Exception::CorruptParameter->throw( error => | ||
| 329 | "unexpected value for SENSOR in sub set_heatersensor. Expected values are:\n 1 --> Sensor #1\n 2 --> Sensor #2\n 3 --> Sensor #3" | ||
| 330 | ); | ||
| 331 | } | ||
| 332 | |||
| 333 | $self->query( "H$sensor\r", $tail ); | ||
| 334 | } | ||
| 335 | |||
| 336 | sub get_heatersensor { | ||
| 337 | |||
| 338 | my $self = shift; | ||
| 339 | my ($tail) = $self->_check_args( \@_, [] ); | ||
| 340 | |||
| 341 | return $self->_get_parameter( 10, $tail ); | ||
| 342 | } | ||
| 343 | |||
| 344 | sub _set_heaterlimit { # internal only | ||
| 345 | |||
| 346 | # in steps of 0.1 V; MAX = 40V --> 80W at 20 Ohm load | ||
| 347 | # 0 dynamical varying limit | ||
| 348 | my $self = shift; | ||
| 349 | my ( $limit, $tail ) = $self->_check_args( \@_, ['value'] ); | ||
| 350 | |||
| 351 | if ( not defined $limit or $limit > 40 or $limit < 0 ) { | ||
| 352 | Lab::Exception::CorruptParameter->throw( error => | ||
| 353 | "unexpected value for LIMIT in sub _set_heaterlimit. Expected values are between 0 .. 40 V" | ||
| 354 | ); | ||
| 355 | } | ||
| 356 | |||
| 357 | $self->query( "M$limit\r", $tail ); | ||
| 358 | } | ||
| 359 | |||
| 360 | sub set_heateroutput { # basic | ||
| 361 | |||
| 362 | # from 0 to 99.9 % of HEATERLIMIT. | ||
| 363 | my $self = shift; | ||
| 364 | my ( $value, $tail ) = $self->_check_args( \@_, ['value'] ); | ||
| 365 | |||
| 366 | if ( not defined $value or $value > 99.9 or $value < 0 ) { | ||
| 367 | Lab::Exception::CorruptParameter->throw( error => | ||
| 368 | "unexpected value for OUTPUT in sub set_heateroutput. Expected values are between 0 .. 999. (100 == 10.0% * HEATERLIMIT.)" | ||
| 369 | ); | ||
| 370 | } | ||
| 371 | |||
| 372 | $self->query( "O$value\r", $tail ); | ||
| 373 | } | ||
| 374 | |||
| 375 | sub get_heateroutput { | ||
| 376 | my $self = shift; | ||
| 377 | my ($tail) = $self->_check_args( \@_, [] ); | ||
| 378 | |||
| 379 | return $self->_get_parameter(5); | ||
| 380 | } | ||
| 381 | |||
| 382 | #################################################################################################### | ||
| 383 | #### TEMPERATURE-SWEEP not implemented yet ###################################################### | ||
| 384 | #################################################################################################### | ||
| 385 | |||
| 386 | #sub itc_sweep { | ||
| 387 | # 0 Stop Sweep | ||
| 388 | # 1 Start Sweep | ||
| 389 | #nn=2P-1 Sweeping to step P | ||
| 390 | #nn=2P Sweeping to step P | ||
| 391 | # my $self=shift; | ||
| 392 | # my $value=shift; | ||
| 393 | # $value=sprintf("%d",$value); | ||
| 394 | # $self->query("S$value\r"); | ||
| 395 | #} | ||
| 396 | |||
| 397 | #sub itc_set_pointer{ | ||
| 398 | # Sets Pointer in internal ITC memory | ||
| 399 | # my $self=shift; | ||
| 400 | # my $x=shift; | ||
| 401 | # my $y=shift; | ||
| 402 | # if ($x<0 or $x>128){ printf "x=$x no valid ITC Pointer value\n";die }; | ||
| 403 | # if ($y<0 or $y>128){ printf "y=$y no valid ITC Pointer value\n";die }; | ||
| 404 | # my $cmd=sprintf("x%d\r",$x); | ||
| 405 | # $self->query($cmd); | ||
| 406 | # $cmd=sprintf("y%d\r",$y); | ||
| 407 | # $self->query($cmd); | ||
| 408 | #} | ||
| 409 | |||
| 410 | #sub itc_program_sweep_table{ | ||
| 411 | # my $self=shift; | ||
| 412 | # my $setpoint=shift; #K Sweep Stop Point | ||
| 413 | # my $sweeptime=shift; #Min. Total Sweep Time | ||
| 414 | # my $holdtime=shift; #sec. Hold Time | ||
| 415 | |||
| 416 | # if ($setpoint<0. or $setpoint >9.9){printf "Cannot reach setpoint: $setpoint\n";die}; | ||
| 417 | |||
| 418 | # $self->itc_set_pointer(1,1); | ||
| 419 | # $setpoint=sprintf("%1.4f",$setpoint); | ||
| 420 | # $self->query("s$setpoint\r"); | ||
| 421 | |||
| 422 | # $self->itc_set_pointer(1,2); | ||
| 423 | # $sweeptime=sprintf("%.4f",$sweeptime); | ||
| 424 | # $self->query("s$sweeptime\r"); | ||
| 425 | |||
| 426 | # $self->itc_set_pointer(1,3); | ||
| 427 | # $holdtime=sprintf("%.4f",$holdtime); | ||
| 428 | # $self->query("s$holdtime\r"); | ||
| 429 | |||
| 430 | # $self->itc_set_pointer(0,0); | ||
| 431 | #} | ||
| 432 | |||
| 433 | #sub itc_read_sweep_table { | ||
| 434 | # Clears Sweep Program Table | ||
| 435 | # my $self=shift; | ||
| 436 | # $self->query("r\r"); | ||
| 437 | #} | ||
| 438 | |||
| 439 | #sub itc_clear_sweep_table { | ||
| 440 | # Clears Sweep Program Table | ||
| 441 | # my $self=shift; | ||
| 442 | # $self->query("w\r"); | ||
| 443 | #} | ||
| 444 | |||
| 445 | 1; | ||
| 446 | |||
| 447 | __END__ |