#!/usr/bin/perl
#
# hp8566b-plot.pl

#----------

use strict;
use POSIX qw(setsid);
use Getopt::Std;
use Time::HiRes qw(usleep time gettimeofday);
use LinuxGpib;
use Number::Format;
use n8ur qw(trim squash parse_value);
use hp3585b qw(get_settings fix_freq fix_db fix_sweep);

my $device = "hp8566b";
my $command;

#----------
# handle signals and errors -- mainly to clear lockfile on termination
sub sig_handler {
	sleep 2;
	close LOG;
	exit(0);
}

# there's got to be a better way!
$SIG{'HUP'} = 'sig_handler';
$SIG{'INT'} = 'sig_handler';
$SIG{'KILL'} = 'sig_handler';
$SIG{'STOP'} = 'sig_handler';
$SIG{'TERM'} = 'sig_handler';
#----------

my $logfile;
$logfile = "test.hpgl";

# set up logfile
open (LOG, ">>$logfile") ||
	die "Can't open logfile $logfile!\n";
# set nonbuffered mode
select(LOG), $| = 1;

#----------------------
# initialize instrument
my $dev = LinuxGpib::ibfind($device) ||
	die "Can't open device $device!\n";

#----------
# Send command
$command = "PLOT 0,0,40000,25000;";
LinuxGpib::ibwrt($dev,$command,length($command));

my $plot;

LinuxGpib::ibrd($dev,$plot,65535);
print $plot,"\n";

