Index: /fact/tools/PyDimCtrl/pyfactctrl.py
===================================================================
--- /fact/tools/PyDimCtrl/pyfactctrl.py	(revision 13812)
+++ /fact/tools/PyDimCtrl/pyfactctrl.py	(revision 13813)
@@ -213,5 +213,8 @@
 
 #============ BIAS VOLTAGE ====================================================
-def VoltageOn( mode = None, Watchdog = None, verbose = True):
+time_of_last_overcurrent = -1. * float('inf')
+number_of_overcurrent_occurences = 0
+
+def VoltageOn( mode = None, Watchdog = None, timeout = 30, verbose = True):
     """ High Level Method for switching on the bias Voltage
         can be called, in whatever state the bias and the feedback might be.
@@ -228,16 +231,55 @@
         raise ValueError("mode must be 'temperature', 'current' or 'feedback'")
 
-    
-    
-    bias.set_global_dac(1)
-    if not bias.wait(9, 10):
-        msg.warn("bias not in Voltage ON after 10sec")
-        return False
-    if not bias.wait(5, 10):
-        msg.warn("bias not Ramping after 10sec")
-        return False
-    if not bias.wait(9, 30):
-        msg.warn("bias not fully ramped up after 30sec")
-        return False
+    if mode == 'temperature':
+        fb_target = 10 #TempControl
+    elif mode == 'feedback':
+        fb_target = 11 # FeedbackControl
+    elif mode == 'current':
+        fb_target = 12 #CurrentControl
+    
+    bias_target = 9 # VoltageOn
+    
+    starttime = time.time()
+    
+    while not ((bias.stn == bias_target) and (fb.stn == fb_target)):
+        if time.time() - starttime > timeout:
+            msg.fail("VoltageOn did not succeed after "+str(timeout)+' seconds')
+            return False
+            
+        elif fb.stn == fb_target-3: # everything fine, but output disabled
+            fb.enable_output(1)
+            bias.set_global_dac(1)
+        
+        elif fb.stn == fb_target and bias.stn == 5: # feedback ok, but we are Ramping
+            # lets try to wait
+            time.sleep(0.5)
+        
+        elif bias.stn == 1: #Disconnected
+            bias.reconnect()
+            
+        elif bias.stn == 6: # Overcurrent
+            if number_of_overcurrent_occurences < 3:
+                bias.set_zero_voltage()
+                bias.reset_over_current_status()
+            elif time.time() - time_of_last_overcurrent > 60:
+                number_of_overcurrent_occurences = 0
+            
+            number_of_overcurrent_occurences += 1
+            time_of_last_overcurrent = time.time()
+        
+        elif bias.stn == 7: # VoltageOff
+            bias.set_global_dac(1)
+            
+        elif bias.stn == 8: # NotReferenced
+            bias.set_zero_voltage()
+            bias.set_global_dac(1)
+        
+        
+        else:
+            # if nothing was done. sleep a while
+            time.sleep(0.5)
+    
+    
+ 
 
     msg("waiting 45sec...")    
@@ -245,4 +287,21 @@
     return True
 
+
+
+def VoltageOff
+def std_bias_watchdog( state, verbose=True ):
+    msg = MSG(verbose)
+    if state == 1: #Disconnected
+        msg.warn("BIAS just DISCONNECTED .. trying to reconnect")
+        msg.warn("current runnumber:"+fad_control.runnumber() )
+        bias.reconnect()
+        time.sleep(1)
+        bias.set_zero_voltage()
+        # TODO: This should work, but it is stupid.
+        bias.reset_over_current_status()
+        bias.reset_over_current_status()
+        bias.set_zero_voltage()
+        bias.reset_over_current_status()
+        bias.set_global_dac(1)
 
 
