#============================================================ # TR6143 #============================================================ package TR6143; 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|"; } #============================================================ # 一般関数 #============================================================ sub Initialize { my ($this) = @_; $this->Reset(); $this->Clear(); } sub Finish { my ($this) = @_; $this->print("H\r\n"); $this->print("D0\r\n"); } sub Clear { my ($this) = @_; $this->print("C\r\n"); $this->print("C4\r\n"); $this->print("OM1 OM6\r\n"); $this->print("M0\r\n"); } sub Reset { my ($this) = @_; # $this->print("*RST\n"); } sub GetId { my ($this) = @_; return "TR6143"; # $this->print("*IDN?\n"); # return $this->read(); } sub SetAutoSampling { my ($this, $f) = @_; # $f = 'on' or 'off'; if($f =~ /off/i) { $this->print("M1\r\n"); } else { $this->print("M0\r\n"); } } sub SetVSourceOutput { my ($this, $f) = @_; # $f = 'on' or 'off'; if($f =~ /on/i) { $this->print("E\r\n"); } else { $this->print("H\r\n"); } } sub SetISourceOutput { my ($this, $f) = @_; # $f = 'on' or 'off'; if($f =~ /on/i) { $this->print("E\r\n"); } else { $this->print("H\r\n"); } } sub SetAutoRange { my ($this, $f) = @_; if($f) { $this->print("R0\r\n"); } else { $this->print("R1\r\n"); } } sub SetDCCurrentMode { # $Range: in mA my ($this, $Range) = @_; #print "TR6143::SetDCCurrentMode Range=$Range\n"; if(!defined $Range) { $this->print("I4\r\n"); $this->print("R0\r\n"); return; } if($Range =~ /uA/) { $Range = $Range * 1.0e-6; } elsif($Range =~ /mA/) { $Range = $Range * 1.0e-3; } else { $Range += 0.0; } if($Range <= 32e-6) { $this->print("I-1\r\n"); } elsif($Range <= 320e-6) { $this->print("I0\r\n"); } elsif($Range <= 3.2e-3) { $this->print("I1\r\n"); } elsif($Range <= 32e-3) { $this->print("I2\r\n"); } elsif($Range <= 320e-3) { $this->print("I3\r\n"); } else { $this->print("I4\r\n"); } } sub SetCurrentLimit { my ($this, $I) = @_; $this->{IMeasureLimit} = $I; $this->SetSourceCurrent($I); } sub SetSourceCurrent { my ($this, $I) = @_; $this->{PresentCurrent} = $I = uc $I; # $this->print("D$I\r\n"); #print "I(S)= [$I]\n"; #return; my ($val, $unit) = ($I+0.0, ''); if($I =~ /^\s*[\d\.+-Ee]+\s*$/) { } else { my ($val, $unit) = ($I =~ /^([\d\.+-Ee]+)\s*(\S+)/); if(!defined $unit) { $val = $I + 0.0; $unit = ''; } } my $s = sprintf("D%8.6g %s\r\n", $val, $unit); #print "I(S)= [$val] [$unit] [$s]\n"; $this->print($s); } sub SetDCVoltageMode { # $Range: in mV my ($this, $Range) = @_; if(!defined $Range) { $this->print("V6\r\n"); $this->print("R0\r\n"); return; } if($Range =~ /mV/) { $Range = $Range * 1.0e-3; } { $Range += 0.0; } if($Range <= 0.32) { $this->print("V3\r\n"); } elsif($Range <= 3.2) { $this->print("V4\r\n"); } elsif($Range <= 32) { $this->print("V5\r\n"); } else { $this->print("V6\r\n"); } } sub SetVoltageLimit { my ($this, $V) = @_; $this->{VMeasureLimit} = $V; $this->SetSourceVoltage($V); } sub SetVSource { my ($this, $V) = @_; return $this->SetSourceVoltage($V); } sub SetSourceVoltage { my ($this, $V) = @_; $this->{PresentVoltage} = $V = uc $V; # $this->print("D$V\r\n"); #print "V(set)=$V\n"; #return; my ($val, $unit) = ($V+0.0, ''); if($V =~ /^\s*[\d\.+-Ee]+\s*$/) { } else { ($val, $unit) = ($V =~ /^([\d\.+-Ee]+)\s*(\S)+/); if(!defined $unit) { $val = $V + 0.0; $unit = ''; } } my $s = sprintf("D%8.6g %s\r\n", $val, $unit); #print "V(S)= [$V] [$val] [$unit] [$s]\n"; $this->print($s); } sub Measure { my ($this) = @_; # return rand(); #$this->print("C4\r\n"); # ヘッダーがDV,DI以外を空読みする。リミッタやディレーが測定されないので削除 #for(my $i = 0 ; $i < 100 ; $i++) { # my $ret = $this->read(); #$ret =~ s/\s+$//; #print "i=$i: $ret\n"; # last if($ret =~ /DV/ or $ret =~ /DI/ or $ret =~ /LM/); #} # 念のため、5回空読みする for(my $i = 0 ; $i < 5 ; $i++) { $this->read(); } my $str = $this->{LastMeasuredValue} = $this->read(); my $str2 = $str; $str2 =~ s/\0//g; $str2 =~ s/[\r\n]//g; $this->{ReadString} = $str2; my ($val) = ($str2 =~ /\s([\d\.+-Ee]+)/); return $val; } 1;