#!/usr/bin/perl 

require "../oscpl/osc.pl";


osc_connect("infocalypse.al.cl.cam.ac.uk", 4500, "GPIB0::7::INSTR") ||
    die "osc_connect: $!";

# osc_write("*idn?") || die "osc_write: $!";
# (($bytes, $data) = osc_read()) || die "osc_read: $!";
# print "device identification: $data\n";

osc_write(":waveform:data?") || die "osc_write: $!";
(($bytes, $data) = osc_read()) || die "osc_read: $!";
print STDERR "Waveform returned $bytes bytes\n";

($header, $realdata) = osc_waveform_parse($data);

print "Read $bytes bytes from the oscilloscope, data is ".length($realdata).
    " bytes\n";

osc_write(":waveform:preamble?") || die "osc_write: $!";
(($bytes, $preamble) = osc_read()) || die "osc_read: $!";


($format, $type, $points, $count, $xinc, $xorig, $xref, $yinc, $yorig, $yref) =
    osc_parse_preamble($preamble);

print "Preamble: $preamble\n";

open(OUT, ">out.dat");
print OUT osc_waveform_to_text($realdata, $xinc, $xorig, $xref, $yinc,
    $yorig, $yref)."\n";
close(OUT);


