#============================================================ # Keithley6517A #============================================================ package Keithley6517A; use Device::DeviceObject; @ISA = qw(DeviceObject); #公開したいサブルーチン @EXPORT = qw(); use strict; use Deps; #============================================================ # コンストラクタ、デストラクタ #============================================================ BEGIN { } sub new { my ($module, @args) = @_; my $this = {}; bless $this; return $this; } sub DESTROY { my $this = shift; $this->Finish(); } #============================================================ # 変数取得関数 #============================================================ sub GetFunctions { return "|DCISource|DCVSource|DCIMeasure|DCVMeasure|ACVMeasure|ACIMeasure|"; } #============================================================ # 一般関数 #============================================================ sub Initialize { my ($this) = @_; $this->{IMeasureLimit} = 1.0e-3; $this->Clear(); $this->Reset(); $this->SetVSourceOutput("off"); $this->SetSourceVoltage(0.0); $this->print(":syst:zcheck off\n"); } sub Finish { my ($this) = @_; $this->SetVSourceOutput("off"); $this->SetSourceVoltage(0.0); } sub Clear { my ($this) = @_; $this->print("*CLS\n"); } sub Reset { my ($this) = @_; $this->print("*RST\n"); } sub GetId { my ($this) = @_; $this->print("*IDN?\n"); return $this->read(); } sub Measure2 { my ($this) = @_; $this->print(":read?\n"); my $ReturnStr = $this->read(); Utils::DelSpace($ReturnStr); my ($ValueStr) = split(/,/, $ReturnStr); $ValueStr =~ s/NADC//; #print "Ret (v=$v): $ReturnStr: $ValueStr\n"; return $ValueStr if(abs($ValueStr) < 1.0e5); } sub Measure { my ($this) = @_; $this->{IMeasureLimit} = 1.0e-3 if($this->{IMeasureLimit} <= 0.0); #print "l: $this->{IMeasureLimit}\n"; for(my $v = 20e-12 ; $v <= $this->{IMeasureLimit}*10.0 ; $v *= 10.0) { $this->SetCurrentRange($v); $this->print(":read?\n"); my $ReturnStr = $this->read(); Utils::DelSpace($ReturnStr); my ($ValueStr) = split(/,/, $ReturnStr); $ValueStr =~ s/NADC//; print "Ret (v=$v): $ReturnStr: $ValueStr\n"; return $ValueStr if(abs($ValueStr) < 1.0e5); } return undef; } sub MeasureAveraged { my ($this, $nAverage) = @_; $this->{IMeasureLimit} = 1.0e-3 if($this->{IMeasureLimit} <= 0.0); my $currange = 20e-12; my $avrI = 0.0; for(my $i = 0 ; $i < $nAverage ; $i++) { my $ValueStr = undef; for(my $v = $currange ; $v <= $this->{IMeasureLimit}*10.0 ; $v *= 10.0) { $this->SetCurrentRange($v); $this->print(":read?\n"); my $ReturnStr = $this->read(); Utils::DelSpace($ReturnStr); ($ValueStr) = split(/,/, $ReturnStr); $ValueStr =~ s/NADC//; print "Ret1 (v=$v) [$i:$nAverage]: $ReturnStr\n"; #: $sValueStr\n"; next if(abs($ValueStr) > 1.0e5); $currange = $v; last; } return undef if($ValueStr > 1.0e5); $avrI += $ValueStr; } return $avrI / $nAverage; } sub SetDCCurrentMode { my ($this, $ZeroCheck) = @_; $this->print(':sens:func "curr:dc"' . "\n"); $this->print(":syst:zcheck $ZeroCheck\n"); $this->print(":syst:zcorrect:state on\n"); $this->print(":syst:zcheck off\n"); $this->print(":sens:curr:range:auto on\n"); } sub SetSourceVoltage { my ($this, $V) = @_; if(defined $this->{VSourceLimit} and $V > $this->{VSourceLimit}) { $V = $this->{VSourceLimit}; } elsif(defined $this->{VSourceLimit} and $V < -$this->{VSourceLimit}) { $V = -$this->{VSourceLimit}; } #print(":sour:volt $V\n"); $this->print(":sour:volt $V\n"); } sub SetVSourceOutput { my ($this, $f) = @_; # $f = 'on' or 'off'; $this->print(":outp:stat $f\n"); } sub SetVSourceLimit { my ($this, $VSourceLimit) = @_; $this->{VSourceLimit} = $VSourceLimit; $this->print(":sour:volt:limit:AMPL 1000\n"); # $this->print(":sour:volt:limit $VSourceLimit\n"); $this->print(":sour:volt:limit:stat off\n"); } sub SetIMeasureLimit { my ($this, $limit) = @_; $this->{IMeasureLimit} = $limit; } sub SetVMeasureLimit { my ($this, $limit) = @_; $this->{VMeasureLimit} = $limit; } sub SetIReference { my ($this, $f) = @_; if($f eq 'on') { $this->print(":sens:curr:dc:ref:acq\n"); $this->print(":sens:curr:dc:ref:stat on\n"); } else { $this->print(":sens:curr:dc:ref:stat off\n"); } } sub SetVReference { my ($this, $f) = @_; if($f eq 'on') { $this->print(":sens:volt:dc:ref:acq\n"); $this->print(":sens:volt:dc:ref:stat on\n"); } else { $this->print(":sens:volt:dc:ref:stat off\n"); } } sub SetVoltageRange { my ($this, $v) = @_; if($v > 100.0) { $this->print(":sour:volt:rang 1000\n"); } else { $this->print(":sour:volt:rang 100\n"); } } sub SetCurrentRange { my ($this, $v) = @_; $this->print(":sens:curr:rang:upp $v\n"); } sub SetAutoRangeForCurrent { my ($this, $f) = @_; # $f = 'ON' or 'OFF' $this->print(":sens:curr:rang:auto $f\n"); } sub MeterConnect { my ($this, $f) = @_; # $f = 'on' or 'off' $this->print(":sour:volt:mcon $f\n"); } 1;