abstract
AbstractHardwareProperty2
Implement an automomous property.
Source code in daiquiri/core/hardware/abstract/__init__.py
connect_hardware(self, obj)
emit_update(self, value)
To be called by the property itself when the hardware property have changed
read_hardware(self, obj)
HardwareObject
Base HardwareObject from which all inherit
The base hardware object defines the objects procotol, type, its properties and callables schema, and mechanisms to subscribe to property changes
Attributes:
Name | Type | Description |
---|---|---|
_object |
obj |
The instance of the control system object. |
_protocol |
str |
The protocol for this object, i.e. bliss |
_type |
str |
The object type, i.e. motor, shutter |
Source code in daiquiri/core/hardware/abstract/__init__.py
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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
|
call(self, function, value, **kwargs)
Calls a function on a hardware object
First checks the function is defined in the objects callables schema, then delegates to the local call implementation _call
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function |
str |
The function to call. |
required |
value |
The value to call the function with. |
required |
Returns:
Type | Description |
---|---|
The the result from the object function if the function exists otherwise rasises an exception |
Source code in daiquiri/core/hardware/abstract/__init__.py
def call(self, function, value, **kwargs):
"""Calls a function on a hardware object
First checks the function is defined in the objects
callables schema, then delegates to the local call
implementation _call
Args:
function (str): The function to call.
value: The value to call the function with.
Returns:
The the result from the object function if the function exists
otherwise rasises an exception
"""
if not self._online:
return
if function in self._callables:
value = self._callables.validate(function, value)
# try:
ret = self._call(function, value, **kwargs)
if ret:
return ret
else:
return True
# except Exception as e:
# return e
else:
raise KeyError("Unknown function {fn}".format(fn=function))
get(self, prop)
Get a property from a hardware object
First checks the property is defined in the objects property schema, then delegates to the local getter implementation _get
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prop |
str |
The property to retreive. |
required |
Returns:
Type | Description |
---|---|
The property value if the property exists, otherwise rasises an exception |
Source code in daiquiri/core/hardware/abstract/__init__.py
def get(self, prop: str):
"""Get a property from a hardware object
First checks the property is defined in the objects
property schema, then delegates to the local getter
implementation _get
Arguments:
prop: The property to retreive.
Returns:
The property value if the property exists, otherwise
rasises an exception
"""
if not self._online:
return
if prop in self._properties:
value = self._get(prop)
return value
else:
raise KeyError(f"Unknown property '{prop}' from object {self._name}")
get_subobject_configs(self)
schema(self)
Returns the schema for the current hardware object
The hardware schema is built from the HardwareObjectBaseSchema
and the object specific _property and _callable schema
(both instances of HardwareSchema
)
Returns:
Type | Description |
---|---|
An instance of a schema |
Source code in daiquiri/core/hardware/abstract/__init__.py
def schema(self):
"""Returns the schema for the current hardware object
The hardware schema is built from the `HardwareObjectBaseSchema`
and the object specific _property and _callable schema
(both instances of `HardwareSchema`)
Returns:
An instance of a schema
"""
schema = type(
f"HW{self.schema_name()}Schema",
(HardwareObjectBaseSchema,),
{
"properties": fields.Nested(self._properties.__class__),
"callables": fields.Nested(self._callables.__class__),
},
)
return schema()
set(self, prop, value)
Set a property on a hardware object
First checks the property is defined in the objects property schema, then delegates to the local setter implementation _set
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prop |
str |
The property to set. |
required |
value |
The property to set. |
required |
Returns:
Type | Description |
---|---|
The the result from the object setter if the property exists otherwise raises an exception |
Source code in daiquiri/core/hardware/abstract/__init__.py
def set(self, prop: str, value):
"""Set a property on a hardware object
First checks the property is defined in the objects
property schema, then delegates to the local setter
implementation _set
Arguments:
prop: The property to set.
value: The property to set.
Returns:
The the result from the object setter if the property exists
otherwise raises an exception
"""
if not self._online:
return
if prop in self._properties:
if self._properties.read_only(prop):
raise AttributeError("Property {p} is read only".format(p=prop))
value = self._properties.validate(prop, value)
return self._set(prop, value)
else:
raise KeyError("Unknown property {p}".format(p=prop))
set_locked(self, reason)
Set the device locked for a reason.
Argument
reason: Locking reason. If none the device is not locked.
Source code in daiquiri/core/hardware/abstract/__init__.py
set_online(self, state)
Set the online state of the device
Sets the state and execute any registered callbacks
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state |
boolean |
Set the online state |
required |
Source code in daiquiri/core/hardware/abstract/__init__.py
state(self, **kwargs)
Gets the current state of a hardware object
Builds a dictionary of the basic info of the object, plus its properties, and callables.
Returns:
Type | Description |
---|---|
A dict of the hardware object status |
Source code in daiquiri/core/hardware/abstract/__init__.py
def state(self, **kwargs):
"""Gets the current state of a hardware object
Builds a dictionary of the basic info of the object, plus its properties, and
callables.
Returns:
A dict of the hardware object status
"""
info = {
k: getattr(self, "_" + k)
for k in ["name", "type", "id", "protocol", "online", "locked"]
}
info["callables"] = [k for k in self._callables]
info["errors"] = []
properties = {}
for p in self._properties:
try:
properties[p] = self.get(p)
except Exception as e:
properties[p] = None
info["online"] = False
info["errors"].append(
{
"property": p,
"exception": str(e),
"traceback": "".join(traceback.format_tb(e.__traceback__)),
}
)
logger.exception(f"Couldn't get property `{p}` for `{self.name()}`")
try:
info["properties"] = self._properties.dump(properties)
except Exception:
logger.error(
"Error while serializing %s (%s)",
self._name,
properties,
exc_info=True,
)
info["properties"] = {}
info["online"] = False
try:
info["properties"]["state_ok"] = self.state_ok()
except Exception:
logger.debug(
f"Could not determine `state_ok` for {self._name}", exec_info=True
)
info["require_staff"] = self.require_staff()
info["alias"] = self.alias()
info["user_tags"] = self.user_tags()
return info
state_ok(self)
Returns if the current object state is ok
subscribe(self, prop, fn)
Subscribe to property changes on the hardware object
Add a function to a list of callbacks for when properties on the object change
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prop |
str |
The property to subscribe to. Can pass 'all' to subscribe to all changes |
required |
fn |
(:callable) The function to call when this property changes. |
required |
Source code in daiquiri/core/hardware/abstract/__init__.py
def subscribe(self, prop: str, fn):
"""Subscribe to property changes on the hardware object
Add a function to a list of callbacks for when properties on the object change
Arguments:
prop: The property to subscribe to. Can pass 'all' to subscribe to all changes
fn: (:callable) The function to call when this property changes.
"""
if not callable(fn):
raise AttributeError("Callback function must be callable")
if prop in self._properties or prop == "all":
if not (prop in self._callbacks):
self._callbacks[prop] = []
if not (fn in self._callbacks[prop]):
self._callbacks[prop].append(fn)
else:
raise KeyError(f"No such property: {prop}")
subscribe_locked(self, fn)
Subscribe to the locked state of the hardware object
Add a function to a list of callbacks for when the locked state of the object change
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
(:callable) The function to call when this property changes. |
required |
Source code in daiquiri/core/hardware/abstract/__init__.py
def subscribe_locked(self, fn):
"""Subscribe to the locked state of the hardware object
Add a function to a list of callbacks for when the locked state of the object change
Args:
fn: (:callable) The function to call when this property changes.
"""
if not callable(fn):
raise AttributeError("Callback function must be callable")
if fn not in self._locked_callbacks:
self._locked_callbacks.append(fn)
subscribe_online(self, fn)
Subscribe to the online state of the hardware object
Add a function to a list of callbacks for when the online state of the object change
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
(:callable) The function to call when this property changes. |
required |
Source code in daiquiri/core/hardware/abstract/__init__.py
def subscribe_online(self, fn):
"""Subscribe to the online state of the hardware object
Add a function to a list of callbacks for when the online state of the object change
Args:
fn: (:callable) The function to call when this property changes.
"""
if not callable(fn):
raise AttributeError("Callback function must be callable")
if fn not in self._online_callbacks:
self._online_callbacks.append(fn)
unsubscribe(self, prop, fn)
Unsubscribe from a property change on the hardware object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prop |
str |
The property to unsubscribe from. |
required |
fn |
(:callable) The function to unsubscribe |
required |
Source code in daiquiri/core/hardware/abstract/__init__.py
def unsubscribe(self, prop: str, fn):
"""Unsubscribe from a property change on the hardware object
Arguments:
prop: The property to unsubscribe from.
fn: (:callable) The function to unsubscribe
"""
if prop in self._callbacks:
if fn in self._callbacks[prop]:
# logger.debug("Unsubscribe from property %s, %s", prop, fn)
self._callbacks[prop].remove(fn)
return True
return False
HardwareProperty
Describe a property from the device controls system.
Provides translation function between the controls system specific nomenclature and the abstract one. This can be overwritten.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str |
Name used by the controls system |
required |
Source code in daiquiri/core/hardware/abstract/__init__.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 |
MappedHardwareObject
Hardware object that maps properties via a simple dict
HardwareObject that has a simple map between abstract properties and their actual properties on the object with fallback to a function on the parent
Source code in daiquiri/core/hardware/abstract/__init__.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
|
ProtocolHandler
A protocol handler instantiates a hardware object from a specific protocol
i.e. initialise a motor object from bliss, or a shutter from tango
Source code in daiquiri/core/hardware/abstract/__init__.py
create_monitor(self)
disconnect(self)
get(self, *args, **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/abstract/__init__.py
@abstractmethod
def get(self, *args, **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:
The hardware object instance for the specific protocol
"""
pass
camera
Camera
Source code in daiquiri/core/hardware/abstract/camera.py
presetmanager
PresetmanagerCallablesSchema
marshmallow-model
scansource
ScanSource
The scan source interface
Source code in daiquiri/core/hardware/abstract/scansource.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 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 |
|
close(self)
get_conversion(self)
Get the mca conversion factors to convert bins to energy
energy = zero + bin * scale
Source code in daiquiri/core/hardware/abstract/scansource.py
get_scan_data(self, scanid, per_page=25, page=1)
Return scan data for the specific scan
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scanid |
int |
The scan id |
required |
per_page |
int |
Number of items to return per page |
25 |
page |
int |
Page of data to return |
1 |
Returns:
Type | Description |
---|---|
data (dict) |
A valid |
Source code in daiquiri/core/hardware/abstract/scansource.py
get_scan_image(self, scanid, node_name, image_no)
Return a scan image for the specific scan
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scanid |
int |
The scan id |
required |
node_name |
str |
The node for the requested image |
required |
image_no |
int |
The image number to return |
required |
Returns:
Type | Description |
---|---|
data (dict) |
A valid |
Source code in daiquiri/core/hardware/abstract/scansource.py
@abstractmethod
def get_scan_image(self, scanid, node_name, image_no):
"""Return a scan image for the specific scan
Args:
scanid (int): The scan id
node_name (str): The node for the requested image
image_no (int): The image number to return
Returns:
data (dict): A valid `ScanDataSchema` dict
"""
pass
get_scan_spectra(self, scanid, point=0, allpoints=False)
Return a scan specific for the specific scan
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scanid |
int |
The scan id |
required |
point |
int |
The image number to return |
0 |
Returns:
Type | Description |
---|---|
data (dict) |
A valid |
Source code in daiquiri/core/hardware/abstract/scansource.py
get_scans(self, scanid=None)
Get a list of scans
Returns a list of scan dicts, can be filtered to only scanid to return details of a specific scan
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scanid |
int |
Scan id to return |
None |
Returns:
Type | Description |
---|---|
scans (list) |
A list of valid |
Source code in daiquiri/core/hardware/abstract/scansource.py
watch_end_scan(self, fn)
Register a callback for a scan ends
Source code in daiquiri/core/hardware/abstract/scansource.py
def watch_end_scan(self, fn):
"""Register a callback for a scan ends"""
if not callable(fn):
raise AttributeError("Callback function must be callable")
if not (fn in self._end_scan_watchers):
self._end_scan_watchers.append(fn)
else:
logger.warning(
"Function {f} is already subscribed to end scan".format(f=fn)
)
watch_new_0d_data(self, fn)
Register a callback for when there is new 0d data for a scan
Source code in daiquiri/core/hardware/abstract/scansource.py
def watch_new_0d_data(self, fn):
"""Register a callback for when there is new 0d data for a scan"""
if not callable(fn):
raise AttributeError("Callback function must be callable")
if not (fn in self._new_0d_data_watchers):
self._new_0d_data_watchers.append(fn)
else:
logger.warning(
"Function {f} is already subscribed to new 0d data".format(f=fn)
)
watch_new_data(self, fn)
Register a callback for when there is new data for a scan
Source code in daiquiri/core/hardware/abstract/scansource.py
def watch_new_data(self, fn):
"""Register a callback for when there is new data for a scan"""
if not callable(fn):
raise AttributeError("Callback function must be callable")
if not (fn in self._new_data_watchers):
self._new_data_watchers.append(fn)
else:
logger.warning(
"Function {f} is already subscribed to new data".format(f=fn)
)
watch_new_scan(self, fn)
Register a callback for when a new scan is started
Source code in daiquiri/core/hardware/abstract/scansource.py
def watch_new_scan(self, fn):
"""Register a callback for when a new scan is started"""
if not callable(fn):
raise AttributeError("Callback function must be callable")
if not (fn in self._new_scan_watchers):
self._new_scan_watchers.append(fn)
else:
logger.warning(
"Function {f} is already subscribed to new scan".format(f=fn)
)
service
ServiceStates
See http://supervisord.org/subprocess.html#process-states