put try/catch for all monitor callbacks (suggestion Xiaoqiang)
This commit is contained in:
82
swissmx.py
82
swissmx.py
@@ -717,30 +717,33 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
||||
cam.run(self.cb_new_frame_pv)
|
||||
|
||||
def cb_new_frame_pv(self, **kwargs):
|
||||
#thrd=threading.current_thread()
|
||||
#_log.debug(f'thread:{thrd.getName()}, {thrd.native_id}')
|
||||
#_log.debug(f"{kwargs['timestamp']}")
|
||||
try: #pv-monitor-func
|
||||
#thrd=threading.current_thread()
|
||||
#_log.debug(f'thread:{thrd.getName()}, {thrd.native_id}')
|
||||
#_log.debug(f"{kwargs['timestamp']}")
|
||||
|
||||
app=QApplication.instance()
|
||||
cam=app._camera
|
||||
sz=cam._sz
|
||||
if kwargs['count']==sz[0]*sz[1]:
|
||||
pic=kwargs['value'].reshape(sz[::-1])
|
||||
else:
|
||||
sz=app._camera.update_size()
|
||||
pic=kwargs['value'].reshape(sz[::-1])
|
||||
if pic.dtype==np.int16:
|
||||
pic.dtype=np.uint16
|
||||
camera.epics_cam.set_fiducial(pic, 255)
|
||||
cam._pic=pic
|
||||
cam._timestamp=kwargs['timestamp']
|
||||
try:
|
||||
cam.process()
|
||||
except AttributeError as e:
|
||||
pass
|
||||
# self._goImg.setImage(cam._pic) caused some deadlocks.
|
||||
# therefore try to update the image with signals instead
|
||||
self.sigNewCamImg.emit()
|
||||
app=QApplication.instance()
|
||||
cam=app._camera
|
||||
sz=cam._sz
|
||||
if kwargs['count']==sz[0]*sz[1]:
|
||||
pic=kwargs['value'].reshape(sz[::-1])
|
||||
else:
|
||||
sz=app._camera.update_size()
|
||||
pic=kwargs['value'].reshape(sz[::-1])
|
||||
if pic.dtype==np.int16:
|
||||
pic.dtype=np.uint16
|
||||
camera.epics_cam.set_fiducial(pic, 255)
|
||||
cam._pic=pic
|
||||
cam._timestamp=kwargs['timestamp']
|
||||
try:
|
||||
cam.process()
|
||||
except AttributeError as e:
|
||||
pass
|
||||
# self._goImg.setImage(cam._pic) caused some deadlocks.
|
||||
# therefore try to update the image with signals instead
|
||||
self.sigNewCamImg.emit()
|
||||
except Exception as e:
|
||||
_log.critical(f'{e}')
|
||||
|
||||
def cb_update_img(self):
|
||||
#thrd=threading.current_thread()
|
||||
@@ -748,22 +751,43 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
||||
|
||||
app=QApplication.instance()
|
||||
cam=app._camera
|
||||
|
||||
self._goImg.setImage(cam._pic)
|
||||
#vb.setRange(QRectF(-1300,-1100,1400,1200))
|
||||
|
||||
#force a segmentation fault
|
||||
#try:
|
||||
# dbgSegFault=self._dbgSegFault
|
||||
#except AttributeError as e:
|
||||
# dbgSegFault=self._dbgSegFault=0
|
||||
#_log.warning(f'dbgSegFault:{dbgSegFault}')
|
||||
#if dbgSegFault>100:
|
||||
# _log.critical('Xforce a segmentation fault')
|
||||
# import ctypes
|
||||
# ctypes.string_at(0)
|
||||
#self._dbgSegFault+=1
|
||||
|
||||
def cb_new_frame_sim(self, **kwargs):
|
||||
app=QApplication.instance()
|
||||
sim=app._camera._sim
|
||||
imgSeq=sim['imgSeq']
|
||||
idx=sim['imgIdx']
|
||||
sim['imgIdx']=(idx+1)%imgSeq.shape[0]
|
||||
sim['imgIdx']=(idx+1)
|
||||
imgIdx=idx%imgSeq.shape[0]
|
||||
# _log.info('simulated idx:{}'.format(idx))
|
||||
pic=imgSeq[idx]
|
||||
pic=imgSeq[imgIdx]
|
||||
self._goImg.setImage(pic)
|
||||
|
||||
delay=500 # ms -> 2fps
|
||||
QtCore.QTimer.singleShot(delay, self.cb_new_frame_sim)
|
||||
|
||||
#force a segmentation fault
|
||||
#_log.warning(f'imgIdx:{imgIdx},idx:{idx}')
|
||||
#if idx==20:
|
||||
# _log.critical('force a segmentation fault')
|
||||
# import ctypes
|
||||
# ctypes.string_at(0)
|
||||
|
||||
def load_stylesheet(self):
|
||||
with open("swissmx.css", "r") as sheet:
|
||||
self.setStyleSheet(sheet.read())
|
||||
@@ -969,6 +993,14 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
||||
]
|
||||
qutilities.add_item_to_toolbox(toolbox,"Fast Stage",widget_list=widgets)
|
||||
|
||||
#pv-monitor-func
|
||||
#_log.info('modify monitors')
|
||||
#for w in widgets[1:-1]: #ignore last item
|
||||
# for k,pv in w._motor._pvs.items():
|
||||
# pv.auto_monitor=False
|
||||
# for k,pv in w._motor._pvs.items():
|
||||
# pv.auto_monitor=True
|
||||
|
||||
def build_group_collimator(self, toolbox):
|
||||
pfx=QApplication.instance()._cfg.value(AppCfg.GBL_DEV_PREFIX)[1]
|
||||
c=QWidget()
|
||||
|
||||
Reference in New Issue
Block a user