]> jspc29.x-matter.uni-frankfurt.de Git - coral.git/commitdiff
device can now handle reconnection of table control tty, when udev symlink stays...
authorMichael Wiebusch <m.wiebusch@gsi.de>
Mon, 23 Feb 2015 18:11:54 +0000 (19:11 +0100)
committerMichael Wiebusch <m.wiebusch@gsi.de>
Mon, 23 Feb 2015 18:11:54 +0000 (19:11 +0100)
user_interface/coral_scanner.pm
user_interface/table_control.pm

index 0cb88fb753ddc4ec931e6abaa5c127bb8c050688..aec62a61f5116fbf020a5eeeca483cdb6a8cb09e 100644 (file)
@@ -46,6 +46,8 @@ sub new {
     plot_upper_limit  => 4000,
     pid_file           => "./".__PACKAGE__.".pid",
     log_file           => "./".__PACKAGE__.".log",
+    table_control_number_retries => 3,
+    table_control_retry_delay => 5,
   };
   
   $self->{settings_desc} = {
@@ -57,6 +59,8 @@ sub new {
     pid_file         => "/path/to/file of the lockfile for the scanning background process",
     stdout           => "/path/to/file of the stdout logfile",
     stderr           => "/path/to/file of the stderr logfile",
+    table_control_number_retries => "number of retries, when communication with the table fails",
+    table_control_retry_delay => "number of seconds to wait for new connection with table",
   };
 
   $self->{has_run} = {}; # remember which subs already have run
@@ -268,7 +272,35 @@ sub scan_sample {
     eval {
       $tc->go_xy( x => $point->{x}, y => $point->{y});
     };
-    warn "error from table\n$@" if $@;
+    if($@) {
+      warn "error from table\n$@";
+      print "attempting to reconnect with table\n";
+      my $tries = $self->{settings}->{table_control_number_retries};
+      for my $try (1..$tries) {
+        print "try $try of $tries\n:";
+        sleep $self->{settings}->{table_control_retry_delay};
+        eval {
+          $tc->init_port();
+          $tc->home();
+          $tc->go_xy( x => $point->{x}, y => $point->{y});
+        };
+        
+        if($@) {
+          warn "not successful: $@\n";
+          if($try == $tries){
+            $self->{status_shm}->updateShm({
+              action => "error"
+            });
+            die "cannot talk to the table after $try tries, giving up\n";
+          }
+        } else {
+          print "table can be controlled again!\ncontinuing scan\n";
+          last;
+        }
+      
+      }
+    
+    }
     
     
     my $delay = $self->{settings}->{time_per_pixel};
@@ -414,7 +446,7 @@ sub record_spectrum {
   my $name = $options{name} || "signal";
   
   #start daemon
-  die "service could not be started (already running?)\n" unless ($self->daemon_start());
+  $self->daemon_start() or die "service could not be started (already running?)\n";
   $self->{pmt_ro}->spectral_scan_onesided(
     name => $name
   );
@@ -425,20 +457,29 @@ sub record_spectrum {
 sub home {
   my $self= shift;
   #start daemon
-  die "service could not be started (already running?)\n" unless ($self->daemon_start());
+  $self->daemon_start() or die "service could not be started (already running?)\n";
   
-  print "homing the table\n";
+  print ">>> homing the table\n\n";
   
   $self->{status_shm}->updateShm({
     action => "homing"
   });
   
-  $self->{table_control}->home();
-  
-  $self->{status_shm}->updateShm({
-    action => "idle"
-  });
-  print "homing completed\n";
+  eval {
+    $self->{table_control}->home();
+  };
+  if ($@) {
+    warn "could not home table\n";
+    warn $@;
+    $self->{status_shm}->updateShm({
+      action => "error"
+    });
+  } else {
+    $self->{status_shm}->updateShm({
+      action => "idle"
+    });
+    print ">>> homing completed\n";
+  }
   
   return "";
 }
index ddb264de7ed5b7dd2e7577a4864dfbc6fa2fc7aa..6cde5f5083de48ed2132d25d7aee61b813c4ed90 100644 (file)
@@ -128,11 +128,8 @@ sub init_port {
   $self->{port} = new Device::SerialPort($tty);
   my $port = $self->{port};
   
-  unless ($port)
-  {
-    print "can't open serial interface $tty\n";
-    exit;
-  }
+  die "can't open serial interface $tty\n" unless(defined($port));
+
 
   $port->user_msg('ON'); 
   $port->baudrate($baudrate);