Commit deee15ea authored by Claudio Scafuri's avatar Claudio Scafuri 💬
Browse files

fix handling of sequencers termination

parent 18760bc3
This diff is collapsed.
......@@ -97,12 +97,12 @@
<deviceProperties name="Pesp_device_name" description="Tango device name of PADRES spectrometer">
<type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<DefaultPropValue>srv-padres-srf:20000/pos/pesp/pesp-pesp_pos.01</DefaultPropValue>
<DefaultPropValue>srv-tango-padres-01:20000/pos/pesp/pesp-pesp_pos.01</DefaultPropValue>
</deviceProperties>
<deviceProperties name="Ccd_device_name" description="Tango device name of PADRES spectrometer ccd">
<type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<DefaultPropValue>srv-padres-srf:20000/pos/pesp/ccd-pesp_pos.01</DefaultPropValue>
<DefaultPropValue>srv-tango-padres-01:20000/pos/pesp/ccd-pesp_pos.01</DefaultPropValue>
</deviceProperties>
<deviceProperties name="MaxPespLambda" description="Maximum wavelength [nm] for PADRES spectrometer using firsdt diffraction order">
<type xsi:type="pogoDsl:DoubleType"/>
......@@ -359,12 +359,13 @@
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="Calculated wavelength for OPA seed laser. This attribute is used internally for the setting of the OPA." label="lambda OPA (calculated)" unit="nm" standardUnit="1" displayUnit="nm" format="%6.2f" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="CalculatedHarmon" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="1" maxY="1">
<attributes name="CalculatedHarmon" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="1" maxY="1" allocReadMember="false" isDynamic="false">
<dataType xsi:type="pogoDsl:ShortType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="FEL harmonic number for OPA operations. Pushed internally to Harmon during OPA setting" label="hamon OPA" unit="" standardUnit="1" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
<properties description="FEL harmonic number for OPA operations. Pushed internally to Harmon during OPA setting" label="harmon OPA" unit="" standardUnit="1" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="CalculatedDelay" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="1" maxY="1">
<dataType xsi:type="pogoDsl:DoubleType"/>
......
......@@ -7,7 +7,7 @@ Created on May 18, 2020
import threading
import tango
import time
import traceback
#import traceback
class applyvaluesthread(threading.Thread):
......@@ -32,15 +32,17 @@ class applyvaluesthread(threading.Thread):
self.master.info_stream('step 1: start pre sequencer rd.')
self.master.pre_sequencer_3Hc.command_inout('Start')
pre_started = True
except:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.error_stream('Pre sequencer 3Hc Start FAILED')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'Pre sequencer 3Hc Start FAILED'
if pre_started:
self.master.set_status('step 1: wait pre sequencer 3Hc termination.')
self.master.info_stream('step 1: wait pre sequencer 3Hc termination.')
pre_seq_tot_sleep = 0
pre_wait = 2 * self.master.Pre_sequencer_3Hc_wait_time #loop ever 1/2 sec
self.master.info_stream('step 1: wait pre sequencer 3Hc termination. %f' % self.master.Pre_sequencer_3Hc_wait_time)
time.sleep(0.5)
while pre_seq_tot_sleep <= pre_wait :
try:
pre_state = self.master.pre_sequencer_3Hc.state()
......@@ -51,14 +53,7 @@ class applyvaluesthread(threading.Thread):
self.master.attr_LastSetMsg += 'failed reading pre sequencer state\n'
self.master.error_stream('failed reading pre sequencer state')
pre_state = tango.DevState.RUNNING #presume running...
except Exception:
traceback.print_exc()
self.master.set_status('failed reading pre sequencer state')
self.master.attr_LastSetMsg += 'failed reading pre sequencer state\n'
self.master.error_stream('failed reading pre sequencer state')
pre_state = tango.DevState.RUNNIG #presume running...
if pre_state == tango.DevState.RUNNING :
if pre_state == tango.DevState.RUNNING or pre_state == tango.DevState.STANDBY :
time.sleep(0.5)
pre_seq_tot_sleep += 1
else:
......@@ -66,7 +61,7 @@ class applyvaluesthread(threading.Thread):
try:
self.master.radiator_group.ping()
self.master.phase_shifter_group.ping()
self.master.modulator.command_inout('ApplyGapPhaTap')
self.master.modulator_dev.command_inout('ApplyGapPhaTap')
self.master.radiator_group.command_inout('ApplyGapPhaTap')
self.master.phase_shifter_group.command_inout('ApplyCalculatedGap')
self.master.attr_PhaseShifterState_read = tango.DevState.MOVING
......@@ -92,14 +87,6 @@ class applyvaluesthread(threading.Thread):
'command_inout failed on at least one sub device')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg = "DevFailed excuting ApplyGap on a device"
except Exception as e:
self.master.error_stream('Unforessen exception excuting ApplyGap on at least one sub device')
# tango.Except.print_exception(e)
tango.Except.throw_exception('command_inout failed',
'ApplyGap failed',
'command_inout failed on at least one sub device')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg = "exception excuting ApplyGap on a device"
try:
self.master.attr_global_harmon.write(self.master.attr_Harmon_read)
self.master.attr_global_polarization.write(self.master.attr_Polarization_read)
......@@ -141,46 +128,41 @@ class applyvaluesthread(threading.Thread):
while gap_move_tot_wait <= gap_move_wait:
if self.master.attr_PhshState_read == tango.DevState.MOVING or self.master.attr_UndulatorState_read == tango.DevState.MOVING:
self.master.set_status('step 3: wait undulators and phshs to stop moving.')
self.master.info_stream('step 3: wait undulatorss and phshs to stop moving.')
self.master.info_stream('step 3: wait undulators and phshs to stop moving.')
time.sleep(0.5)
gap_move_tot_wait += 1
else:
break
try:
self.master.set_status('step 3: start post sequencer 3Hc.')
self.master.info_stream('step 3: start post sequencer rd.')
self.master.info_stream('step 3: start post sequencer 3Hc.')
self.master.post_sequencer_3Hc.command_inout('Start')
post_started = True
except:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.error_stream('Post sequencer 3Hc Start FAILED')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'Post sequencer 3Hc Start FAILED'
if post_started and self.master.attr_Wait3HcPostSequenceEnd_read :
self.master.set_status('step 3: wait post sequencer 3Hc termination.')
self.master.info_stream('step 3: wait post sequencer 3Hc termination.')
self.master.info_stream('step 3: wait post sequencer 3Hc termination. %f' % self.master.Post_sequencer_3Hc_wait_time )
post_seq_tot_sleep = 0
post_wait = 2 * self.master.Post_sequencer_3Hc_wait_time #loop every 1/2 sec
time.sleep(0.5)
while post_seq_tot_sleep <= post_wait :
try:
post_state = self.master.post_sequencer_opa.state()
self.master.info_stream('step 3: check post sequencer 3Hc termination.')
post_state = self.master.post_sequencer_3Hc.state()
self.master.info_stream('step 3: check post sequencer 3Hc termination. %d' % post_state)
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.set_status('failed reading post sequencer state')
self.master.attr_LastSetMsg += 'failed reading post sequencer state\n'
self.master.error_stream('failed reading post sequencer state')
post_state = tango.DevState.RUNNING #presume running...
except Exception:
traceback.print_exc()
self.master.set_status('failed reading post sequencer state')
self.master.attr_LastSetMsg += 'failed reading post sequencer state\n'
self.master.error_stream('failed reading post sequencer state')
post_state = tango.DevState.RUNNIG #presume running...
if post_state == tango.DevState.RUNNING :
if post_state == tango.DevState.RUNNING or post_state == tango.DevState.STANDBY :
time.sleep(0.5)
post_seq_tot_sleep += 1
self.master.info_stream('step 3: wait post sequencer 3Hc termination - after sleep')
else:
break
......
......@@ -45,12 +45,7 @@ class opathread(threading.Thread):
self.master.attr_LastSetMsg += 'step 1: failed reading l0\n'
self.master.error_stream('step 1: failed reading l0')
tango.Except.print_exception(e)
except Exception:
self.master.set_status('step 1: exception reading l0')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 1: exception reading l0\n'
self.master.error_stream('step 1: exception reading l0 %s' % (traceback.format_exc()))
if self.master.delay_line_compensation_enabled :
try:
delaycomp = self.master.delay_calc.get_compensation_delay(lmb0, self.lmb)
......@@ -80,7 +75,8 @@ class opathread(threading.Thread):
self.master.ltf.command_inout('Standby')
self.master.info_stream('LTF Standby OK')
restart_LTF = True
except:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.error_stream('LTF Standby FAILED')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'LTF Standby FAILED'
......@@ -94,15 +90,17 @@ class opathread(threading.Thread):
self.master.info_stream('step 1: start pre sequencer OPA.')
self.master.pre_sequencer_opa.command_inout('Start')
pre_started = True
except:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.error_stream('Pre sequencer OPA Start FAILED')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'Pre sequencer OPA Start FAILED'
if pre_started:
self.master.set_status('step 1: wait pre sequencer OPA termination.')
self.master.info_stream('step 1: wait pre sequencer OPA termination.')
self.master.info_stream('step 1: wait pre sequencer OPA termination. %f' % self.master.Pre_sequencer_OPA_wait_time )
pre_seq_tot_sleep = 0
pre_wait = 2 * self.master.Pre_sequencer_OPA_wait_time #loop every 1/2 sec
time.sleep(0.5)
while pre_seq_tot_sleep <= pre_wait :
try:
pre_state = self.master.pre_sequencer_opa.state()
......@@ -113,15 +111,10 @@ class opathread(threading.Thread):
self.master.attr_LastSetMsg += 'failed reading pre sequencer state\n'
self.master.error_stream('failed reading pre sequencer state')
pre_state = tango.DevState.RUNNING #presume running...
except Exception:
self.master.set_status('failed reading pre sequencer state')
self.master.attr_LastSetMsg += 'failed reading pre sequencer state\n'
self.master.error_stream('failed reading pre sequencer state %s' % (traceback.format_exc()))
pre_state = tango.DevState.RUNNIG #presume running...
if pre_state == tango.DevState.RUNNING :
if pre_state == tango.DevState.RUNNING or pre_state == tango.DevState.STANDBY:
time.sleep(0.5)
pre_seq_tot_sleep += 1
self.master.debug_stream('step 1: check pre sequencer OPA termination. - after sleep')
else:
break
......@@ -138,7 +131,8 @@ class opathread(threading.Thread):
self.master.sl_optimizer.command_inout('Off')
self.master.info_stream('SL optimizer OFF OK')
restart_SLO = True
except:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.error_stream('SL optimizer OFF FAILED')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'SL optimizer OFF FAILED'
......@@ -150,7 +144,6 @@ class opathread(threading.Thread):
if self.master.set_compressor and not (math.isnan(compressor_position)):
self.master.set_status('step 2: set compressor position')
try:
self.master.compressor.write_attribute('Position', compressor_position)
self.master.info_stream('step 2 compressor: %f' % compressor_position)
self.master.set_status('step 2: compressor setting done')
......@@ -160,12 +153,6 @@ class opathread(threading.Thread):
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 2: failed setting compressor\n'
self.master.error_stream('step 2: failed setting compressor')
except Exception:
print('line 731 -print_exc() postion=', compressor_position)
self.master.set_status('step 2: exception setting compressor')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 2: exception setting compressro.\n'
self.master.error_stream('step 2: exception setting compressor: ' + traceback.format_exc())
self.master.set_status('step 5: set OPA wavelength')
try:
......@@ -222,17 +209,13 @@ class opathread(threading.Thread):
self.master.attr_LastSetMsg += 'step 4: DevFailed setting new lambda on energy meter\n'
self.master.warn_stream('step 4: DevFailed setting new lambda on energy meter')
tango.Except.print_exception(e)
except:
self.master.set_status('step 4: failed to set new lambda on energy meter')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 4: failed to set new lambda on energy meter\n'
self.master.warn_stream('step 4: failed to set new lambda on energy meter')
# we can survive even without setting wavelength on energy meter
self.master.set_status('step 4: export SL wavelength')
try:
self.master.spctm.command_inout('ExportWavelength')
except:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.set_status('step 4: export SL wavelength failed')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 4: export SL wavelength failed\n'
......@@ -268,11 +251,7 @@ class opathread(threading.Thread):
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 5: failed setting delay line\n'
self.master.error_stream('step 5: failed setting delay line')
except Exception:
self.master.set_status('step 5: exception setting delay comp.')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 5: exception setting delay comp.\n'
self.master.error_stream('step 5: exception setting delay comp: ' + traceback.format_exc())
else:
self.master.set_status('step 5: ok ')
......@@ -286,7 +265,8 @@ class opathread(threading.Thread):
self.master.error_stream('step 6: PADRES spectrometer: no valid diffr. order for %f' % (self.pespwl))
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 6: PADRES spectrometer: no valid diffr. order\n'
except Exception:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.set_status('step 6: failed adjusting PADRES spectrometer')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'step 6: failed adjusting PADRES spectrometer\n'
......@@ -299,7 +279,8 @@ class opathread(threading.Thread):
self.master.ltf.command_inout('On')
self.master.set_status('step 7: LTF ON ok')
self.master.info_stream('LTF ON')
except:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.error_stream('LTF ON FAILED')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'LTF ON FAILED\n'
......@@ -311,7 +292,8 @@ class opathread(threading.Thread):
self.master.sl_optimizer.command_inout('On',0)
self.master.set_status('step 8:SL optimizer ON ok')
self.master.info_stream('SL optimizer ON')
except:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.error_stream('SL optimizer ON FAILED')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'SL optimizer ON FAILED\n'
......@@ -339,15 +321,17 @@ class opathread(threading.Thread):
self.master.info_stream('step 9: start post sequencer OPA.')
self.master.post_sequencer_opa.command_inout('Start')
post_started = True
except:
except tango.DevFailed as e:
tango.Except.print_exception(e)
self.master.error_stream('Post sequencer OPA Start FAILED')
self.master.attr_LastSetOk = False
self.master.attr_LastSetMsg += 'Post sequencer OPA Start FAILED'
if post_started and self.master.attr_WaitOpaPostSequenceEnd_read :
self.master.set_status('step 9: wait post sequencer OPA termination.')
self.master.info_stream('step 9: wait post sequencer OPA termination.')
self.master.info_stream('step 9: wait post sequencer OPA termination. %f' % self.master.Post_sequencer_OPA_wait_time)
post_seq_tot_sleep = 0
post_wait = 2 * self.master.Post_sequencer_OPA_wait_time #loop every 1/2 sec.
time.sleep(0.5)
while post_seq_tot_sleep <= post_wait :
try:
post_state = self.master.post_sequencer_opa.state()
......@@ -358,20 +342,16 @@ class opathread(threading.Thread):
self.master.attr_LastSetMsg += 'failed reading post sequencer state\n'
self.master.error_stream('failed reading post sequencer state')
post_state = tango.DevState.RUNNING #presume running...
except Exception:
self.master.set_status('failed reading post sequencer state')
self.master.attr_LastSetMsg += 'failed reading post sequencer state\n'
self.master.error_stream('failed reading post sequencer state %s' % (traceback.format_exc()))
post_state = tango.DevState.RUNNIG #presume running...
if post_state == tango.DevState.RUNNING :
if post_state == tango.DevState.RUNNING or post_state == tango.DevState.STANDBY :
time.sleep(0.5)
post_seq_tot_sleep += 1
self.master.debug_stream('step 9: wait post sequencer OPA termination - after sleep')
else:
break
self.master.set_status('ApplyCalculatedValues OPA thread done.')
self.master.info_stream('ApplyCalculatedValues OPA thread done.')
self.master.internal_state = self.master.prev_state
return
......@@ -73,7 +73,7 @@ class Test(unittest.TestCase):
print('lambda fel min:', self.opa.get_fel_min())
print('lambda fel max:', self.opa.get_fel_max())
print('=======================================')
pass
if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment