Device-GPIB
view release on metacpan or search on metacpan
lib/Device/GPIB/Generic.pm view on Meta::CPAN
{
my ($self, $s) = @_;
$self->send($s) || return;
return $self->read_binary();
}
# Convert a numeric error into device-specific error string
# Expect ErrorStrings to be defined in the subclass
sub errorToString($$)
{
my ($self, $error) = @_;
return $self->{ErrorStrings}{$error} if exists $self->{ErrorStrings}{$error};
return;
}
# Convert a numeric spoll result into device-specific error string
# Expect SpollStrings to be defined in the subclass
sub spollToString($$)
{
my ($self, $spoll) = @_;
# Mask out the BUSY bit:
$spoll &= 0xf7;
return $self->{SpollStrings}{$spoll} if exists $self->{SpollStrings}{$spoll};
return;
}
# Send Group trigger to this device only
sub trigger()
{
my ($self) = @_;
$self->{Device}->trg($self->{Address});
}
sub actAsDevice()
{
my ($self) = @_;
$self->{Device}->actAsDevice();
}
sub mode()
{
my ($self, $mode) = @_;
print "CALLED generic mode $mode\n";
$self->{Device}->mode($mode);
}
# Set a new address to talk to
sub setAddress()
{
my ($self, $address) = @_;
$self->{Address} = $address;
}
# Return the device ID, or undef if nothing at the address
sub id($)
{
my ($self) = @_;
$self->{Id} = $self->sendAndRead('ID?');
if (!$self->{Id})
{
warn "No GPIB device at address $self->{Address}";
return;
}
return $self->{Id};
}
sub executeCommandsFromFiles($@)
{
my ($self, @files) = @_;
foreach my $file (@files)
{
#print "file $file\n";
my $fh;
open($fh, $file) || die "could not open command filename $file: $!\n";
while (<$fh>)
{
# print "line $_\n";
chomp;
$self->executeCommand($_);
}
close($fh);
}
}
# Execute an array of commands
sub executeCommands($@)
{
my ($self, @commands) = @_;
foreach (@commands)
{
$self->executeCommand($_);
}
}
# Multiple semicolon sparated commands permitted
# Comamnds can begin with comment char # and are ignore
# Can end with a ? and query result is preinted to stdout
sub executeCommand()
{
my ($self, $command) = @_;
$self->{Device}->debug("executeCommand: $command\n") if $main::opt_debug;
return if (index($command, '#') == 0); # Comment
return if length($command) == 0; # Empty
if ($command =~ /query:(.*)/i)
{
# For commands that dont end in a ? but we still want to see the results eg from VREAD
print $self->sendAndRead($1);
print "\n";
}
( run in 1.158 second using v1.01-cache-2.11-cpan-5b529ec07f3 )