tango
TangoHOConfig
marshmallow-model
The Tango Hardware Object Config Schema
Source code in daiquiri/core/hardware/tango/__init__.py
Fields:
Name | Type | Properties | Description |
---|---|---|---|
attrname |
String |
Used by TangoAttr object | |
tango_url |
String |
URL to tango device/attribute | |
type |
String |
Required | The object type |
TangoHandler
Source code in daiquiri/core/hardware/tango/__init__.py
get(self, **kwargs)
Get the specific object from the protocol handler.
This function checks that kwargs conforms to Schema defined for the protocol handler (see core/hardware/bliss/init.py for a concrete example)
Returns:
Type | Description |
---|---|
The hardware object instance for the specific protocol |
Source code in daiquiri/core/hardware/tango/__init__.py
def get(self, **kwargs):
# Discover tangoattr using from url
if "url" in kwargs:
url = kwargs["url"]
if "type" not in kwargs or kwargs["type"] == "tangoattr":
if url.count("/") == 6:
url, attrname = url.rsplit("/", 1)
kwargs["url"] = url
kwargs["attrname"] = attrname
if "type" not in kwargs:
kwargs["type"] = "tangoattr"
try:
kwargs = TangoHOConfig().load(kwargs)
except ValidationError as err:
raise InvalidYAML(
{
"message": "Tango hardware object definition is invalid",
"file": "hardware.yml",
"obj": kwargs,
"errors": err.messages,
}
) from err
try:
return loader(
"daiquiri.core.hardware.tango",
"",
kwargs.get("type"),
app=self._app,
**kwargs
)
except ModuleNotFoundError:
logger.error(
"Could not find class for tango object {type}".format(
type=kwargs.get("type")
)
)
raise
frontend
FrontendStateProperty
Source code in daiquiri/core/hardware/tango/frontend.py
translate_from(self, value)
Translate the value from the controls layer to the abstraction layer i.e for getters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |
Source code in daiquiri/core/hardware/tango/frontend.py
ItlkStateProperty
Source code in daiquiri/core/hardware/tango/frontend.py
translate_from(self, value)
Translate the value from the controls layer to the abstraction layer i.e for getters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |
gauge
GaugeStateProperty
Source code in daiquiri/core/hardware/tango/gauge.py
translate_from(self, value)
Translate the value from the controls layer to the abstraction layer i.e for getters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |
lima
ImageFormatNotSupported
Lima
Source code in daiquiri/core/hardware/tango/lima.py
frame(self)
Return a frame from the camera
Source code in daiquiri/core/hardware/tango/lima.py
LimaStateProperty
Source code in daiquiri/core/hardware/tango/lima.py
translate_from(self, value)
Translate the value from the controls layer to the abstraction layer i.e for getters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |
VIDEO_MODES
An enumeration.
Source code in daiquiri/core/hardware/tango/lima.py
VideoCodec
dataclass
parse_video_frame(raw_data, bpp=None, rotation=0)
Parse a lima video frame and convert to rgb
Lima frame decoding in bliss https://gitlab.esrf.fr/bliss/bliss/-/blob/master/bliss/data/lima_image.py
Available lima pixel formats: https://gitlab.esrf.fr/limagroup/lima/-/blob/master/common/include/lima/VideoUtils.h
OpenCV formats: https://docs.opencv.org/master/d1/d4f/imgproc_2include_2opencv2_2imgproc_8hpp.html
Source code in daiquiri/core/hardware/tango/lima.py
def parse_video_frame(
raw_data: bytes, bpp: int = None, rotation: int = 0
) -> numpy.ndarray:
"""Parse a lima video frame and convert to rgb
Lima frame decoding in bliss
https://gitlab.esrf.fr/bliss/bliss/-/blob/master/bliss/data/lima_image.py
Available lima pixel formats:
https://gitlab.esrf.fr/limagroup/lima/-/blob/master/common/include/lima/VideoUtils.h
OpenCV formats:
https://docs.opencv.org/master/d1/d4f/imgproc_2include_2opencv2_2imgproc_8hpp.html
"""
(
magic,
header_version,
image_mode,
image_frame_number,
image_width,
image_height,
endian,
header_size,
pad0,
pad1,
) = struct.unpack(VIDEO_HEADER_FORMAT, raw_data[:HEADER_SIZE])
if magic != VIDEO_MAGIC:
raise ImageFormatNotSupported(f"Magic header not supported (found {magic:0x})")
if header_version != 1:
raise ImageFormatNotSupported(
f"Image header version not supported (found {header_version})"
)
if image_frame_number < 0:
raise IndexError("Image from lima video_live interface not available yet.")
try:
mode = VIDEO_MODES(image_mode)
except KeyError:
raise ImageFormatNotSupported(f"Video format unsupported (found {image_mode})")
try:
codec = VIDEO_CODECS[mode]
except KeyError:
raise ImageFormatNotSupported(f"Video codec unsupported (found {mode})")
data = numpy.frombuffer(raw_data[HEADER_SIZE:], dtype=codec.dtype)
# flip w and h as this is how images are saved
shape = list(codec.shape(image_width, image_height))
shape[0], shape[1] = shape[1], shape[0]
data.shape = shape
if bpp is not None:
if codec.dtype == numpy.uint16:
if bpp < 16:
logger.debug(f"Scaling to 16bit from {bpp}")
data = data << (16 - bpp)
if codec.dtype == numpy.uint8:
if bpp > 8:
logger.warning(f"Scaling to 8bit from {bpp}, trimming {16 - bpp} bits")
data = data >> (bpp - 8)
if cv2:
if codec.opencv_code is not None:
logger.debug(
f"Decoding frame with mode {image_mode} using {codec.opencv_code}"
)
data = cv2.cvtColor(data, codec.opencv_code)
if rotation != 0:
ninties = rotation / 90
data = numpy.rot90(data, -ninties)
return data
object
TangoAttrProperty
Source code in daiquiri/core/hardware/tango/object.py
__init__(self, name, attrname)
special
Attribute name: Name of the attribute property attrname: Callable returning the attribute name
get_attrname(self, obj)
translate_from(self, value)
Translate the value from the controls layer to the abstraction layer i.e for getters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |
Source code in daiquiri/core/hardware/tango/object.py
translate_to(self, value)
Translate the value to the controls layer from the abstraction layer i.e for setters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |
TangoObject
Source code in daiquiri/core/hardware/tango/object.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
try_device(self)
Watch dog trying to reconnect to the remote hardware if it was disconnected
Source code in daiquiri/core/hardware/tango/object.py
def try_device(self):
"""Watch dog trying to reconnect to the remote hardware if it was
disconnected"""
while True:
log_failure = logger.exception if self._app.debug else logger.info
if not self._online:
try:
self._connect()
except Exception:
log_failure(
f"Could not connect to {self._tango_url}. Retrying in 10s"
)
gevent.sleep(10)
TangoStateProperty
Source code in daiquiri/core/hardware/tango/object.py
translate_from(self, value)
Translate the value from the controls layer to the abstraction layer i.e for getters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |
translate_to(self, value)
Translate the value to the controls layer from the abstraction layer i.e for setters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |
pump
PumpStateProperty
Source code in daiquiri/core/hardware/tango/pump.py
translate_from(self, value)
Translate the value from the controls layer to the abstraction layer i.e for getters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |
shutter
ShutterStateProperty
Source code in daiquiri/core/hardware/tango/shutter.py
translate_from(self, value)
Translate the value from the controls layer to the abstraction layer i.e for getters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |
Source code in daiquiri/core/hardware/tango/shutter.py
def translate_from(self, value):
val_map = {
DevState.CLOSE: "CLOSED",
DevState.DISABLE: "DISABLED",
DevState.OPEN: "OPEN",
DevState.FAULT: "FAULT",
DevState.UNKNOWN: "UNKNOWN",
DevState.RUNNING: "OPEN", # The RUNNING state is not very useful in user point of view
DevState.STANDBY: "STANDBY",
DevState.MOVING: "MOVING",
}
for k, v in val_map.items():
if k == value:
return v
return "UNKNOWN"
valve
ValveStateProperty
Source code in daiquiri/core/hardware/tango/valve.py
translate_from(self, value)
Translate the value from the controls layer to the abstraction layer i.e for getters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |
wago
WagoStateProperty
Source code in daiquiri/core/hardware/tango/wago.py
translate_from(self, value)
Translate the value from the controls layer to the abstraction layer i.e for getters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |
WagoStateProperty
Source code in daiquiri/core/hardware/tango/wago.py
translate_from(self, value)
Translate the value from the controls layer to the abstraction layer i.e for getters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
The property value to translate. |
required |
Returns:
Type | Description |
---|---|
The translated value |