Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
obj = self.obj
if physical_values is None:
physical_values = self.get_physical_values()
else:
l_v, l_u = len(physical_values), len(obj.get_user_elements())
if l_v != l_u:
raise IndexError("CalcPseudo(%s): must give %d physical "
"values (you gave %d)" % (obj.name, l_u, l_v))
ctrl, axis = obj.controller, obj.axis
result = ctrl.calc(axis, physical_values)
if result.error:
self._exc_info = result.exc_info
except SardanaException as se:
self._exc_info = se.exc_info
result = SardanaValue(exc_info=se.exc_info)
except:
exc_info = sys.exc_info()
result = SardanaValue(exc_info=exc_info)
self._exc_info = exc_info
return result
def calc_all_physical(self, pseudo_pos, curr_physical_pos):
ctrl = self.ctrl
try:
ctrl_value = ctrl.CalcAllPhysical(pseudo_pos, curr_physical_pos)
if ctrl_value is None:
msg = '%s.CalcAllPhysical() return error: Expected value, ' \
'got None instead' % (self.name,)
raise ValueError(msg)
value = translate_ctrl_value(ctrl_value)
except:
value = SardanaValue(exc_info=sys.exc_info())
return value
try:
obj = self.obj
if physical_positions is None:
physical_positions = self.get_physical_positions()
else:
l_p, l_u = len(physical_positions), len(
obj.get_user_elements())
if l_p != l_u:
raise IndexError("CalcPseudo(%s): must give %d physical "
"positions (you gave %d)" % (obj.name, l_u, l_p))
result = obj.controller.calc_pseudo(
obj.axis, physical_positions, None)
except SardanaException as se:
result = SardanaValue(exc_info=se.exc_info)
except:
result = SardanaValue(exc_info=sys.exc_info())
return result
def calc_all_physical(self, pseudo_pos, curr_physical_pos):
ctrl = self.ctrl
try:
ctrl_value = ctrl.CalcAllPhysical(pseudo_pos, curr_physical_pos)
if ctrl_value is None:
msg = '%s.CalcAllPhysical() return error: Expected value, ' \
'got None instead' % (self.name,)
raise ValueError(msg)
value = translate_ctrl_value(ctrl_value)
except:
value = SardanaValue(exc_info=sys.exc_info())
return value
axes = self._element_axis.keys()
if ctrl_values is None:
ctrl_values = {}
ctrl = self.ctrl
try:
ctrl.PreReadAll()
for axis in axes:
ctrl.PreReadOne(axis)
ctrl.ReadAll()
except:
exc_info = sys.exc_info()
for axis in axes:
element = self.get_element(axis=axis)
ctrl_values[element] = SardanaValue(exc_info=exc_info)
return ctrl_values
for axis in axes:
element = self.get_element(axis=axis)
ctrl_values[element] = self._read_axis_value(element)
return ctrl_values
try:
axis = element.get_axis()
type_ = element.get_type()
ctrl_value = self.ctrl.ReadOne(axis)
if ctrl_value is None:
msg = '%s.ReadOne(%s[%d]) return error: Expected value(s), ' \
'got None instead' % (self.name, element.name, axis)
raise ValueError(msg)
if is_chunk(type_, ctrl_value):
value = [translate_ctrl_value(v) for v in ctrl_value]
else:
value = translate_ctrl_value(ctrl_value)
except:
value = SardanaValue(exc_info=sys.exc_info())
return value
curr_physical_positions = self.get_physical_positions()
if isinstance(new_position, collections.Sequence):
new_positions = new_position
else:
positions = obj.get_siblings_positions()
positions[obj] = new_position
new_positions = len(positions) * [None]
for pseudo, position in positions.items():
new_positions[pseudo.axis - 1] = position
result = obj.controller.calc_all_physical(new_positions,
curr_physical_positions)
except SardanaException as se:
result = SardanaValue(exc_info=se.exc_info)
except:
result = SardanaValue(exc_info=sys.exc_info())
return result
def translate_ctrl_value(value):
if isinstance(value, SardanaValue):
return value
for _, translator in list(__CTRL_VALUE_TRANSLATORS.items()):
try:
return translator(value)
except CannotTranslateException:
continue
# Fallback translator
return SardanaValue(value=value)