system ("clear");
# serielle schnittstelle oeffnen (genauso wie eine datei)
open (lockin, "+>/dev/ttyS1");
# '+' steht fuer 'update'
use IO::Handle;
lockin->autoflush(1);
#Sampligrate eingeben
print "Samplingrate: ";
$sampl = <stdin>;
#Lock-In reset ('\015' ist der ASCII- Wert von '\n')
print lockin "REST\015";
#Samplingrate an Lock-In senden
print lockin "SRAT $sampl\015";
# Zeitbasis aus der Samplingrate berechnen
$tbase = 32;
for ($i=0; $i <= $sampl; $i++)
{$tbase /= 2;}
#Messung starten und warten. Nach Eingabe stoppen
print lockin "STRT\015";
$test = <stdin>;
print lockin "PAUS\015";
#Anzahl der Punkte im Puffer abfragen und ausgeben
print lockin "SPTS ?\015";
while ($a ne "\015"){
read lockin,$a,1;
$pts .= $a;
}
$pts -=$a;
print "$pts \n ";
#Alle Datenbytes auf einmal auslesen und in $buf speichern
$buf='';
print lockin "TRCB ? 0,$pts\015"; # $pts Werte
binaer anfordern
$anzBytes = 4 * $pts;
# 4 Bytes pro Wert
read lockin,$buf,$anzBytes;
# soviele Bytes einlesen in $buf
#serielle Schnittstelle schliessen
close (lockin);
#Bytes in $buf sollen als $pts floats interpretiert werden
@dataArr = '';
@dataArr = unpack("f$pts", $buf); # ab damit
in den Array
#Daten und Zeit in ein File schreiben
open (outfile, ">./test.tmp");
$time = '';
for ($i = 0; $i < $pts; $i++){
$time = $tbase * $i;
print outfile "$time\t $dataArr[$i]\n";
# print "$time\t $dataArr[$i]\n";
}
close (outfile);
system("gnuplot test.gnu"); # plottet die Werte mit Gnuplot
# test.gnu enthält folgende Zeile:plot "test.tmp";pause -1
print"\n";