#============================================================ # GPIBComm #============================================================ package GPIBComm; use Exporter; use GPIB; @ISA = qw(Exporter 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); $EOT=0; $EOS=0x140a; 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 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) = @_; #print "GPIB::$interface, $board, $addr, $subaddr, $timeout, $EOT, $EOS\n"; 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 read { my ($this, $bufferlength) = @_; $bufferlength = 1024 if(!defined $bufferlength); my $response = $this->g()->ibrd($bufferlength); chomp $response; return $response; } 1;