From fb425a519c755a260f1fde870a76d19bf826b9df Mon Sep 17 00:00:00 2001 From: "maps@jspc10" Date: Wed, 5 Nov 2014 17:55:47 +0100 Subject: [PATCH] multiple tries to record a bin, when it fails --- user_interface/pmt_ro.pl | 27 +++++++++++++++++---------- user_interface/regio.pm | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/user_interface/pmt_ro.pl b/user_interface/pmt_ro.pl index 6f25066..6879e5c 100755 --- a/user_interface/pmt_ro.pl +++ b/user_interface/pmt_ro.pl @@ -201,6 +201,8 @@ sub spectral_scan { my $spec_width = $stop-$start; my $bin_width = $spec_width/$bins; + my $file = FileHandle->new("./test.dat", 'w'); + my $counts; my $bin_pos; my $spectrum; @@ -216,6 +218,7 @@ sub spectral_scan { bin_pos => $bin_pos }; print "$i\t$bin_pos\t$counts\n" if $verbose; + print $file "$i\t$bin_pos\t$counts\n"; } return $spectrum; @@ -398,6 +401,8 @@ sub count { # count for a given time on a given channel my $channel = $options{channel}; # can be "signal" or "veto" or "net" my $delay = $options{delay} || 1; + my $tries = $options{tries} || 3; + my $counter_addr; my $threshold_addr; @@ -414,16 +419,18 @@ sub count { # count for a given time on a given channel die "$channel is not a valid channel!\n possible channels are \"signal\",\"veto\" and \"net\"\n!"; } - $self->{regio}->write($self->{regaddr_lookup}->{acquisition},0); # stop acquisition - $self->{regio}->read($self->{regaddr_lookup}->{reset_counter}); # reset counter - $self->{regio}->write($self->{regaddr_lookup}->{acquisition},1); # start acquisition - Time::HiRes::sleep($delay); # let the counter count - $self->{regio}->write($self->{regaddr_lookup}->{acquisition},0); # stop acquisition - my $counts = $self->{regio}->read($counter_addr); # read counter value - $self->{regio}->write($self->{regaddr_lookup}->{acquisition},1); # start acquisition - - die "Padiwa does not answer!\n" unless defined($counts); - return $counts; + for ( my $try=0; $try < $tries; $try++) { + $self->{regio}->write($self->{regaddr_lookup}->{acquisition},0); # stop acquisition + $self->{regio}->read($self->{regaddr_lookup}->{reset_counter}); # reset counter + $self->{regio}->write($self->{regaddr_lookup}->{acquisition},1); # start acquisition + Time::HiRes::sleep($delay); # let the counter count + $self->{regio}->write($self->{regaddr_lookup}->{acquisition},0); # stop acquisition + my $counts = $self->{regio}->read($counter_addr); # read counter value +# $self->{regio}->write($self->{regaddr_lookup}->{acquisition},1); # start acquisition + return $counts if defined($counts); + } + die "Padiwa does not answer after $tries tries!\n"; + } sub signal_range { # determine the range and the position the signal/noise in terms of diff --git a/user_interface/regio.pm b/user_interface/regio.pm index abb23f5..f46f01e 100644 --- a/user_interface/regio.pm +++ b/user_interface/regio.pm @@ -114,7 +114,7 @@ sub communicate { $self->{port}->are_match(""); $self->{port}->read_char_time(1); # avg time between read char - $self->{port}->read_const_time(0); # const time for read (milliseconds) + $self->{port}->read_const_time(2); # const time for read (milliseconds) $self->{port}->lookclear; $self->{port}->write("$command\n"); -- 2.43.0