sub PlotDraw {
my($name) = @_;
if($p->{$name}->{run}>=1) {
- plot_write($p->{$name}->{fh},"set out \"".$p->{$name}->{file}.".png\"");
+ plot_write($p->{$name}->{fh},"set out \"|cat >".
+ $p->{$name}->{file}.".png_tmp && mv ".
+ $p->{$name}->{file}.".png_tmp ".
+ $p->{$name}->{file}.".png ".
+ "\"");
+# # this code makes gnuplot write a temp file first, and after its creation, moves the temp file
+# plot_write($p->{$name}->{fh},"set out \"|base64 >".
+# $p->{$name}->{file}.".png.base64_tmp && mv ".
+# $p->{$name}->{file}.".png.base64_tmp ".
+# $p->{$name}->{file}.".png.base64 ".
+# "\"");
+# plot_write($p->{$name}->{fh},"set out \"".
+# $p->{$name}->{file}.".png".
+# "\"");
plot_write($p->{$name}->{fh},makeTimeString());
plot_write($p->{$name}->{fh},"replot");
}
--- /dev/null
+#!/usr/bin/perl -w
+
+
+my $me = "adcread.pl";
+
+# my $verbose = 1;
+my $suicideTimeout = 5;
+
+
+
+use strict;
+use warnings;
+use POSIX;
+use Storable qw(lock_store lock_retrieve);
+use Data::Dumper;
+use Getopt::Long;
+use Time::HiRes;
+use HADES::TrbNet;
+use AccessXmlDb;
+use CGI ':standard';
+require Common;
+
+
+use FindBin;
+use lib "$FindBin::Bin/..";
+
+
+my $entityFile = "../../daqtools/xml-db/cache/CbController.entity";
+my $xmldb = AccessXmlDb->new( entityFile => $entityFile );
+
+my $isHttpReq = $ENV{HTTP_USER_AGENT};
+
+my $q = CGI->new;
+
+my $channel = $q->param('channel');
+my $chip = $q->param('chip');
+my $FPGA = $q->param('FPGA');
+my $DAQOPSERVER = $q->param('DAQOPSERVER') || $ENV{'DAQOPSERVER'};
+my $n = $q->param('n') || 10;
+my $delay = $q->param('delay') || 5 ; #ms
+my $verbose = $q->param('verbose') || 0;
+
+print header('text/plain') if $isHttpReq;
+print_usage() unless ( defined($channel) && defined($chip) && defined($FPGA));
+
+
+# Getopt::Long::Configure(qw(gnu_getopt));
+# GetOptions(
+# 'chip=s' => \$chip,
+# 'channel=s' => \$channel,
+# 'FPGA=s' => \$FPGA,
+# 'delay=s' => \$delay,
+# 'DAQOPSERVER=s' => \$DAQOPSERVER,
+# 'n=s' => \$n
+# );
+
+
+
+$ENV{'DAQOPSERVER'} = $DAQOPSERVER;
+
+
+my $self = $xmldb->channelParm($chip,$channel);
+$self->{FPGA} = any2dec($FPGA);
+trb_init_ports() or die trb_strerror();
+
+
+my @vals;
+
+minMax();
+
+$delay /= 1000;
+
+for (my $i = 0; $i < $n; $i++){
+ Time::HiRes::sleep( $delay );
+ my $val=getVal();
+ print $val."\n" if $verbose;
+ push(@vals,$val);
+}
+
+my( $min, $max) = minMax();
+
+my $mean = average(\@vals);
+my $stdev = stdev(\@vals);
+print "unit = 1 ".$self->{unit}."\n" if $verbose;
+print "mean:\tstdev:\tmin:\tmax:\n" if $verbose;
+print "$mean\t$stdev\t$min\t$max\n";
+
+
+
+sub getVal{
+ my $read = trb_register_read($self->{FPGA},$self->{address});
+ my $value = ($read->{$self->{FPGA}} & 0xFFFF ) * $self->{scale};
+ return $value;
+}
+
+sub minMax{
+# read min and max
+ my $read = trb_register_read($self->{FPGA},$self->{address}+0x30);
+ my $minmax = ($read->{$self->{FPGA}} ) ;
+ my $min = ($minmax & 0x0000FFFF) * $self->{scale}; # lower 16 bit
+ my $max = ($minmax >> 16 ) * $self->{scale}; # upper 16 bit
+ return ($min, $max);
+}
+
+sub print_usage{
+
+my $text = q%
+Usage (cmdline): adcread.pl FPGA=<address> chip=<number> channel=<channelName> [OPTIONS]
+Usage (CGI) : adcread.pl?FPGA=<address>&chip=<number>&channel=<channelName>[&OPTIONS]
+
+Reads n (default=10) values from selected ConverterBoard(v2013) ADCs and prints out their
+mean and stdev, as well as the minimum and maximum value that the FPGA has seen during
+readout time (regardless of whether min and max have been sampled by this script).
+
+Results will have the following format:
+ <mean>\t<stdev>\t<min>\t<max>\n
+
+Options:
+ n = <number> sample <number> values
+ delay = <ms> delay between samples (default=5ms)
+ DAQOPSERVER = <host>:<port> sets the DAQOPSERVER (server which hosts TRBnet daemon)
+ if left out, will use DAQOPSERVER ENV variable
+ verbose = <0|1> if verbose=1 then script will print all sampled values
+ as well as the channel unit and other debug data
+
+available ADC channels:
+
+ %.
+join("\n ", @{$xmldb->channelList()})
+.q%
+
+Example:
+ cmdline: adcread.pl DAQOPSERVER=localhost:88 FPGA=0xd882 chip=0 channel=CurrentDigital
+ CGI : adcread.pl?DAQOPSERVER=localhost:88&FPGA=0xd882&chip=0&channel=CurrentDigital
+%;
+
+
+
+ if ( $isHttpReq ){
+ print "you have called this script via CGI\n";
+ } else {
+ print "you have called this script via command line\n";
+ }
+ print $text;
+ exit;
+
+}
+
+
+sub text2html {
+
+my $text = shift;
+$text = escapeHTML($text);
+$text =~ s/\n/<br>/g;
+return $text;
+
+}
\ No newline at end of file
$plot->{output} = HPlot::OUT_PNG;
$plot->{titles}->[0] = $self->{requestString};
$plot->{ylabel} = $self->{unit};
+ $plot->{curves} = 3;
+ $plot->{titles}->[1] = "min";
+ $plot->{titles}->[2] = "max";
+
## uncomment for resizing y axis to full adc range
# $plot->{ymin} = 0;
# $plot->{ymax} = $self->{scale} * 65536;
# HPlot::PlotAdd($self->{requestString},rand());
my $read = trb_register_read($self->{FPGA},$self->{address});
my $value = ($read->{$self->{FPGA}} & 0xFFFF ) * $self->{scale};
+# read min and max
+ my $read = trb_register_read($self->{FPGA},$self->{address}+0x30);
+ my $minmax = ($read->{$self->{FPGA}} ) ;
+ my $min = ($minmax & 0x0000FFFF) * $self->{scale}; # lower 16 bit
+ my $max = ($minmax >> 16 ) * $self->{scale}; # upper 16 bit
# print $value."\n" if $myverbose;
- HPlot::PlotAdd($self->{requestString},$value);
+ HPlot::PlotAdd($self->{requestString},$value,0);
+ HPlot::PlotAdd($self->{requestString},$min,1);
+ HPlot::PlotAdd($self->{requestString},$max,2);
}
sub draw {