mxcubecore 1.356.0__py3-none-any.whl → 1.358.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ from tango import (
6
6
  )
7
7
 
8
8
  from mxcubecore.BaseHardwareObjects import HardwareObject
9
+ from mxcubecore.utils.tango import TangoAttributeReadError, add_attribute_channel
9
10
 
10
11
  """
11
12
  The sample changer maintenance hardware object for ISARA2 robot.
@@ -93,14 +94,7 @@ class ISARAMaint(HardwareObject):
93
94
  def init(self):
94
95
  tangoname = self.get_property("tangoname")
95
96
  self.isara_dev = DeviceProxy(tangoname)
96
-
97
- polling = self._get_polling()
98
-
99
- self._poll_attribute(tangoname, "Powered", polling, self._powered_updated)
100
- self._poll_attribute(
101
- tangoname, "PositionName", polling, self._position_name_updated
102
- )
103
- self._poll_attribute(tangoname, "Message", polling, self._message_updated)
97
+ self._setup_attribute_polling(tangoname)
104
98
 
105
99
  def _get_polling(self):
106
100
  """
@@ -113,18 +107,36 @@ class ISARAMaint(HardwareObject):
113
107
  # no polling is specified in the XML, use default polling value
114
108
  return DEFAULT_POLLING
115
109
 
116
- def _poll_attribute(self, tangoname: str, attr_name: str, polling: int, callback):
117
- channel = self.add_channel(
118
- {
119
- "type": "tango",
120
- "name": f"_chn{attr_name}",
121
- "tangoname": tangoname,
122
- "polling": polling,
123
- },
124
- attr_name,
125
- )
110
+ def _setup_attribute_polling(self, tangoname: str):
111
+ polling = self._get_polling()
126
112
 
127
- channel.connect_signal("update", callback)
113
+ try:
114
+ add_attribute_channel(
115
+ self,
116
+ tangoname,
117
+ "Powered",
118
+ polling,
119
+ self._powered_updated,
120
+ )
121
+ add_attribute_channel(
122
+ self,
123
+ tangoname,
124
+ "PositionName",
125
+ polling,
126
+ self._position_name_updated,
127
+ )
128
+ add_attribute_channel(
129
+ self,
130
+ tangoname,
131
+ "Message",
132
+ polling,
133
+ self._message_updated,
134
+ )
135
+ except TangoAttributeReadError as ex:
136
+ self.log.warning(
137
+ "ISARA: could not connect to '%s' tango attribute",
138
+ ex.attribute_name,
139
+ )
128
140
 
129
141
  def _update_state(self):
130
142
  for attr in [self._powered, self._position_name, self._message]:
@@ -0,0 +1,71 @@
1
+ from tango import DevFailed
2
+
3
+ from mxcubecore.BaseHardwareObjects import HardwareObject
4
+ from mxcubecore.Command.Tango import TangoChannel
5
+
6
+
7
+ class TangoAttributeReadError(Exception):
8
+ def __init__(self, attribute_name: str):
9
+ super().__init__()
10
+ self.attribute_name = attribute_name
11
+
12
+
13
+ def add_attribute_channel(
14
+ hwo: HardwareObject,
15
+ tango_device: str,
16
+ attribute_name: str,
17
+ polling: int,
18
+ update_callback=None,
19
+ ) -> TangoChannel:
20
+ """Utility function to add Tango attribute Channel to a hardware object.
21
+
22
+ This function adds a Channel object to specified hardware object and checks
23
+ that it's possible to read the specified tango attribute.
24
+
25
+ If there is errors reading the attribute, the TangoAttributeReadError
26
+ exception is raised.
27
+
28
+ Parameters:
29
+ hwo: The hardware object where to add the Channel object.
30
+ tango_device: Tango device name.
31
+ attribute_name: The tango attribute name.
32
+ polling: Attribute polling periodicity.
33
+ update_callback: Optional callback, if provided it is connected to
34
+ "update" signal of Channel object
35
+ """
36
+
37
+ channel = hwo.add_channel(
38
+ {
39
+ "type": "tango",
40
+ "tangoname": tango_device,
41
+ "name": attribute_name,
42
+ "polling": polling,
43
+ },
44
+ attribute_name,
45
+ )
46
+
47
+ if not channel.is_connected():
48
+ raise TangoAttributeReadError(attribute_name)
49
+
50
+ #
51
+ # check if it's possible to read the Attribute
52
+ #
53
+ try:
54
+ val = channel.get_value()
55
+ except DevFailed:
56
+ raise TangoAttributeReadError(attribute_name) from None
57
+
58
+ #
59
+ # add "update" callback
60
+ #
61
+ if update_callback is not None:
62
+ channel.connect_signal("update", update_callback)
63
+ #
64
+ # We have 'consumed' the initial value of this channel above,
65
+ # when we were testing if it's readable. The standard polling
66
+ # will not invoke the callback with that value now.
67
+ # Make sure initial value is passed to the callback.
68
+ #
69
+ update_callback(val)
70
+
71
+ return channel
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: mxcubecore
3
- Version: 1.356.0
3
+ Version: 1.358.0
4
4
  Summary: Core libraries for the MXCuBE application
5
5
  License: LGPL-3.0-or-later
6
6
  Keywords: mxcube,mxcube3,mxcubecore
@@ -198,7 +198,7 @@ mxcubecore/HardwareObjects/GrobSampleChanger.py,sha256=LMetcL45fWrwP4C8rtENrEDNy
198
198
  mxcubecore/HardwareObjects/Harvester.py,sha256=0TYUXmz-Pmfd7Dhz7ToUGHzJRuJmnga8-4BK4B0KGQA,26524
199
199
  mxcubecore/HardwareObjects/HarvesterMaintenance.py,sha256=8s4yHDEFG-C1WYyW_RlwrFPSpc8o5hGi14aQuFQFrHs,9405
200
200
  mxcubecore/HardwareObjects/ICATLIMS.py,sha256=kxIkpKhAkU7BeI-v45rMtjOZerO_q9f7-SpCHoj6z84,51103
201
- mxcubecore/HardwareObjects/ISARAMaint.py,sha256=dCfVckK_qo-9m4sUicwyxXjkrRsMxkOWujMG0f4JtDM,8661
201
+ mxcubecore/HardwareObjects/ISARAMaint.py,sha256=I8LHXK6wCfzixsxWmmcqWlrdaL3AOX91XmVeAwT7GPk,8959
202
202
  mxcubecore/HardwareObjects/LNLS/EPICSActuator.py,sha256=3dDj6aXyTz03m8osdA6udq_a4bch-KNcUMrXSNvbG5Q,2587
203
203
  mxcubecore/HardwareObjects/LNLS/EPICSMotor.py,sha256=lRTc1t32rJKNTIcnKCECrqo2m9BhlYvLq9NWg4Y0w0Q,3576
204
204
  mxcubecore/HardwareObjects/LNLS/EPICSNState.py,sha256=xZ2sQFeRpZIdn29e7pCFF24KT2cYsoe7VNTD2z-F_IU,3103
@@ -464,9 +464,10 @@ mxcubecore/saferef.py,sha256=lbUbzojjg1XM6gKtGKug48CD_LeuQXpZ7R3r1fMjCKw,7164
464
464
  mxcubecore/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
465
465
  mxcubecore/utils/conversion.py,sha256=G1bk2Mi2ZwGbZa5pEeiFaKWxhSVXVGqu1L9_SioyUOk,4513
466
466
  mxcubecore/utils/qt_import.py,sha256=0lPmqok_oYQZ059kJCq7RWdg490T8YKyRvoZGyWDy4M,14486
467
+ mxcubecore/utils/tango.py,sha256=lAl7Su_GgyXFEEKZ1yu_2gU18wXHVaBbGR8RYcIOVYk,2100
467
468
  mxcubecore/utils/units.py,sha256=2D1QlTwe8eSs2UYRm4VVxSTosZZHeM-Pfw9KlcLbDAg,1251
468
- mxcubecore-1.356.0.dist-info/COPYING,sha256=u-Mc8zCecwyo4YoP8UulmzCiZZ_MmCLROd_NBtOcRj0,35148
469
- mxcubecore-1.356.0.dist-info/COPYING.LESSER,sha256=46mU2C5kSwOnkqkw9XQAJlhBL2JAf1_uCD8lVcXyMRg,7652
470
- mxcubecore-1.356.0.dist-info/METADATA,sha256=l24dhYoxUY4YbmRlETfTlWdONsRSbktBzW51LbOlTsQ,4262
471
- mxcubecore-1.356.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
472
- mxcubecore-1.356.0.dist-info/RECORD,,
469
+ mxcubecore-1.358.0.dist-info/COPYING,sha256=u-Mc8zCecwyo4YoP8UulmzCiZZ_MmCLROd_NBtOcRj0,35148
470
+ mxcubecore-1.358.0.dist-info/COPYING.LESSER,sha256=46mU2C5kSwOnkqkw9XQAJlhBL2JAf1_uCD8lVcXyMRg,7652
471
+ mxcubecore-1.358.0.dist-info/METADATA,sha256=svWlpZfbEGVbUhxxSHs1t_5EUfvB3_QYDgjB3vIIvAw,4262
472
+ mxcubecore-1.358.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
473
+ mxcubecore-1.358.0.dist-info/RECORD,,