]> jspc29.x-matter.uni-frankfurt.de Git - hades_mdc_settings.git/commitdiff
add relative voltage setting
authorJan Michel <michel@physik.uni-frankfurt.de>
Wed, 11 Jan 2023 12:48:30 +0000 (13:48 +0100)
committerJan Michel <michel@physik.uni-frankfurt.de>
Wed, 11 Jan 2023 12:48:30 +0000 (13:48 +0100)
scripts/mdc_voltage.pl

index b6a6d2d7473bcea39215cf50fc583881f8f1eca0..674d7345373321b92c547d741dc4bbca073a4ede 100755 (executable)
@@ -14,6 +14,7 @@ my $channel;
 my $setting;
 my $write;
 my $load;
+my $relative;
 
 Getopt::Long::Configure(qw(gnu_getopt));
 GetOptions(
@@ -21,6 +22,7 @@ GetOptions(
            'board|b=s'   => \$board,
            'channel|c=i' => \$channel,
            'value|v=i'   => \$setting,
+           'relative|r=i'=> \$relative,
            'write|w'     => \$write,
            'load|l'      => \$load,
           ) ;
@@ -37,12 +39,15 @@ mdc_voltage.pl (-board|-b) 0x8nnn (-load|-l)
 mdc_voltage.pl (-load|-l)
         load all settings from file to boards
             
-mdc_voltage.pl (-board|-b) 0x8nnn [(-channel|c) (0|1)] [(-value|-v) (0-7)]
+mdc_voltage.pl (-board|-b) 0x8nnn (-channel|c) (0|1) (-value|-v) (0-7)
         change setting on board only
 
-mdc_voltage.pl (-board|-b) 0x8nnn [(-channel|c) (0|1)] [(-value|-v) (0-7)] (-write|-w)
+mdc_voltage.pl (-board|-b) 0x8nnn (-channel|c) (0|1) (-value|-v) (0-7) (-write|-w)
         change setting on board and store in file
-       
+
+mdc_voltage.pl (-board|-b) 0x8nnn (-channel|c) (0|1) (-relative|-r) (-7..7) [(-write|-w)]
+        change setting relative to the setting in file
+        
 Reads the current voltage setting from configuration file.
 Sets the current voltage (optionally changes configuration file if -w is set).
 Board needs to be a valid OEP address, or FFFF to show/load all channels.
@@ -66,13 +71,17 @@ if(defined $setting && ($setting < 0 || $setting > 7)) {
   die "Wrong setting number (0-7)\n";
   }
 
+if(defined $relative && ($relative < -7 || $relative > 7)) {
+  die "Wrong relative number (-7-7)\n";
+  }  
+  
 #Load all settings  
 if(defined $load && !defined $board) {
   my $ret = MDCPower::set_all_voltages();
   }
 
 #Read settings from file  
-elsif(defined $board && (!defined $setting || !defined $channel)) {
+elsif(defined $board && !defined $channel) {
   my ($v1,$v2) = MDCPower::get_voltage($board);
   die "Settings not found\n" if $v1 == -1 && $v2 == -1;
   
@@ -101,6 +110,27 @@ elsif(defined $board && defined $setting  && defined $channel) {
     }
   }
   
+#change settings relative to value stored in file  
+elsif  (defined $board && defined $relative  && defined $channel) {
+  print("Change Settings relative\n");
+  my ($v1,$v2) = MDCPower::get_voltage($board);
+  die "Settings not found\n" if $v1 == -1 && $v2 == -1;
+    
+  my $newset = $channel?$v1:$v2;
+  $newset += $relative;
+  if($newset>7) { $newset = 7; print "Out of range.\n";}
+  if($newset<0) { $newset = 0; print "Out of range.\n";}  
+  print("Change Settings\n");
+  my $ret = MDCPower::set_voltage($board,$channel,$setting,0);
+  die "Invalid Settings\n" if $ret == -1;
+  die "Power Output not found\n" if $ret == -2;
+  
+  if($write) {
+    print("Store Settings\n");
+    my $found = MDCPower::store_voltage($board,$channel,$newset);
+    print "ERROR: Board not found in database.\n" unless $found;
+    } 
+  }
 #Don't understand  
 else {
   die "Invalid command\n";