#============================================================ # GPIBDeviceObject #============================================================ package GPIBDeviceObject; use Common2; use GPIB; @ISA = qw(Common GPIB); #公開したいサブルーチン @EXPORT = qw(); use strict; use Deps; #============================================================ # コンストラクタ、デストラクタ #============================================================ BEGIN { } sub new { my ($module, $interface, $devname, $timeout, $EOT, $EOS) = @_; $interface = 'ni' if($interface eq ''); $timeout = ::GPIB->T1s if(!defined $timeout); $EOT = 1 if(!defined $EOT); $EOS = 1 if(!defined $EOS); my $this = {}; bless $this; my ($name, $addr) = ($devname =~ /(\w+):(\d+)/); if(defined $addr) { $this->Open($interface, 0, $name, $addr, 0, $timeout, $EOT, $EOS); } return $this; } sub DESTROY { my $this = shift; } #============================================================ # 変数取得関数 #============================================================ sub GetFunctions { return "|BaseObject|"; } sub SetGPIB { my ($this,$g)=@_; return $this->{GPIB} = $g; }; sub g { return shift->{GPIB}; }; sub SetDeviceName { my ($this,$name)=@_; return $this->{DeviceName} = $name; }; sub DeviceName { return shift->{DeviceName}; }; sub SetGPIBAddress { my ($this,$addr)=@_; return $this->{GPIBAddress} = $addr; }; sub GPIBAddress { return shift->{GPIBAddress}; }; #============================================================ # 一般関数 #============================================================ sub Open { my ($this, $interface, $board, $name, $addr, $subaddr, $timeout, $EOT, $EOS) = @_; my $g = GPIB->new("GPIB::$interface", $board, $addr, $subaddr, $timeout, $EOT, $EOS); return 0 if(!defined $g); $this->SetGPIB($g); $this->SetDeviceName($name); $this->SetGPIBAddress($addr); return $g; } sub print { my ($this, @a) = @_; my $line = ''; for(my $i = 0 ; $i < @a ; $i++) { $line .= $a[$i]; } return $this->g()->ibwrt($line); } sub printf { my ($this, $format, @a) = @_; my $line = sprintf($format, @a); return $this->g()->ibwrt($line); } sub read { my ($this, $bufferlength) = @_; $bufferlength = 1024 if(!defined $bufferlength); my $response = $this->g()->ibrd($bufferlength); chomp $response; return $response; } sub PrintInfo { my ($this) = @_; my $DeviceName = $this->DeviceName(); my $Address = $this->GPIBAddress(); print "Device Information:\n"; print " Device name: $DeviceName\n"; print " Address : $Address\n"; print " Object : $this\n"; } sub NotImplementedError { my ($this, $FuncName) = @_; my $name = DeviceName(); print "GPIBDeviceObject::$FuncName: This function is not implemented for [$name].\n"; return undef; } sub GetSCPIData { my ($this, $command) = @_; $this->print($command); return $this->read(); } sub Initialize { my ($this) = @_; $this->Reset(); $this->Clear(); } sub Finish { my ($this) = @_; } sub Clear { my ($this) = @_; # $this->print("*CLS"); } sub Reset { my ($this) = @_; # $this->print("*RST"); } sub GetIdentification { my ($this) = @_; $this->NotImplementedError("GetIdentification"); return "undefined"; # return shift->GetSCPIData("*IDN?"); } sub GetId { return shift->GetIdentification(); } sub FetchData { my ($this) = @_; return $this->NotImplementedError("FetchData"); # return shift->print(":FETCH?"); } sub ReadData { my ($this) = @_; return $this->NotImplementedError("ReadData"); # return shift->print(":READ?"); } } sub InitDVM { my ($this) = @_; return $this->NotImplementedError("InitDVM"); # $this->print("*RST"); # $this->print("*CLS"); # $this->print(":conf:volt:dc"); # $this->print(":sens:volt:dc:dig 7"); # $this->print(":sens:volt:dc:aper 0.1"); # $this->print(":voltage:dc:average:count 100"); # $this->print(":SYSTEM:ZCHECK 0"); } sub SetZeroCheckDVM { my ($this, $mode) = @_; return $this->NotImplementedError("SetZeroCheckDVM"); # if($mode or uc $mode eq 'ON') { # $mode = 1; # } # else { # $mode = 0; # } # $this->print(":SYSTEM:ZCHECK $mode"); } sub SetZeroCheckDCM { my ($this) = @_; return $this->NotImplementedError("SetZeroCheckDCM"); # $this->SetZeroCheckDVM() } sub InitSource { my ($this) = @_; return $this->NotImplementedError("InitSource"); } sub ApplySource { my ($this, $mode) = @_; return $this->NotImplementedError("ApplySource"); # if($mode or uc $mode eq 'ON') { # $mode = "ON"; # } # else { # $mode = "OFF"; # } # return $this->print(":OUTP:STAT $mode"); } sub StopSource { my ($this) = @_; return $this->NotImplementedError("StopSource"); # return shift->ApplySource(0); } sub SetSource { my ($this, $val) = @_; return $this->NotImplementedError("SetSource"); # return $this->print(":SOUR:VOLT $val"); } sub SetVSourceOutput { my ($this, $f) = @_; # $f = 'on' or 'off'; return $this->ApplySource($f); } sub SetISourceOutput { my ($this, $f) = @_; # $f = 'on' or 'off'; return $this->ApplySource($f); } sub SetCurrentLimit { my ($this, $I) = @_; return $this->NotImplementedError("SetCurrentLimit"); # $this->{IMeasureLimit} = $V } sub SetCurrent { my ($this, $I) = @_; return $this->NotImplementedError("SetCurrent"); # $this->{PresentCurrent} = $V } sub SetSourceCurrent { my ($this, $I) = @_; return $this->SetCurrent($I); } sub SetVoltageLimit { my ($this, $V) = @_; $this->SetSourceVoltage($V); # $this->{VMeasureLimit} = $limit; } sub SetVoltage { my ($this, $V) = @_; return $this->NotImplementedError("SetVoltage"); } sub SetSourceVoltage { my ($this, $V) = @_; retrun $this->SetVoltage($V); # $this->{PresentVoltage} = $V } sub MeasureAveraged { my ($this, $nAverage) = @_; return $this->NotImplementedError("MeasureAveraged"); #$this->{LastMeasureAveragedValue} = ; } sub Measure { my ($this) = @_; return $this->NotImplementedError("Measure"); #$this->{LastMeasuredValue} = ; } 1;