1 2 3 4 5 6 7 8 9 10 11 12 13 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
|
/*
* SPDX-FileCopyrightText: All Contributors to the PyTango project
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "common_header.h"
#include "pyutils.h"
#include "server/attribute_utils.h"
#include "convertors/type_casters.h"
#include "convertors/attributes/scalar_python_to_cpp.h"
#include "convertors/attributes/array_python_to_cpp.h"
#include "convertors/attributes/scalar_cpp_to_python.h"
#include "convertors/attributes/array_cpp_to_python.h"
namespace PyWAttribute {
inline void set_write_value(Tango::WAttribute &att,
py::object &value) {
long type = att.get_data_type();
Tango::AttrDataFormat format = att.get_data_format();
const bool is_image = (format == Tango::IMAGE);
if(format == Tango::SCALAR) {
TANGO_CALL_ON_ATTRIBUTE_DATA_TYPE_ID(type, scalar_value_from_python_into_cpp, att, value);
} else {
TANGO_CALL_ON_ATTRIBUTE_DATA_TYPE_ID(type, array_value_from_python_into_cpp, att, is_image, value);
}
}
inline py::object get_write_value(Tango::WAttribute &att, PyTango::ExtractAs extract_as) {
long type = att.get_data_type();
py::object value;
Tango::AttrDataFormat fmt = att.get_data_format();
const bool isScalar = fmt == Tango::SCALAR;
if(isScalar) {
TANGO_CALL_ON_ATTRIBUTE_DATA_TYPE_ID(type, scalar_value_from_cpp_into_python, att, value);
} else {
TANGO_CALL_ON_ATTRIBUTE_DATA_TYPE_ID(type, array_value_from_cpp_into_python, att, value, extract_as);
}
return value;
}
/// @}
} // namespace PyWAttribute
void export_wattribute(py::module &m) {
py::class_<Tango::WAttribute,
Tango::Attribute>(m,
"WAttribute",
py::dynamic_attr(),
"This class represents a Tango writable attribute")
.def(
"set_min_value",
[](Tango::WAttribute &attr, py::object &value) {
set_value_limit(attr, value, TargetValue::VALUE_MIN);
},
R"doc(
set_min_value(self, value)
Set attribute minimum value.
:param value: the attribute minimum value. python data type must be compatible
with the attribute data format and type.)doc",
py::arg("value"))
.def(
"set_max_value",
[](Tango::WAttribute &attr, py::object &value) {
set_value_limit(attr, value, TargetValue::VALUE_MAX);
},
R"doc(
set_max_value(self, value)
Set attribute maximum value.
:param value: the attribute maximum value. python data type must be compatible
with the attribute data format and type.)doc",
py::arg("value"))
.def(
"get_min_value",
[](Tango::WAttribute &attr) {
return get_value_limit(attr, TargetValue::VALUE_MIN);
},
R"doc(
get_min_value(self) -> obj
Get attribute minimum value or throws an exception if the
attribute does not have a minimum value.
:returns: an object with the python minimum value
:rtype: obj)doc")
.def(
"get_max_value",
[](Tango::WAttribute &attr) {
return get_value_limit(attr, TargetValue::VALUE_MAX);
},
R"doc(
get_max_value(self) -> obj
Get attribute maximum value or throws an exception if the
attribute does not have a maximum value.
:returns: an object with the python maximum value
:rtype: obj)doc")
.def("is_min_value",
&Tango::WAttribute::is_min_value,
R"doc(
is_min_value(self) -> bool
Check if the attribute has a minimum value.
:returns: true if the attribute has a minimum value defined
:rtype: bool)doc")
.def("is_max_value",
&Tango::WAttribute::is_max_value,
R"doc(
is_max_value(self) -> bool
Check if the attribute has a maximum value.
:returns: true if the attribute has a maximum value defined
:rtype: bool)doc")
.def("get_write_value_length",
&Tango::WAttribute::get_write_value_length,
R"doc(
get_write_value_length(self) -> int
Retrieve the new value length (data number) for writable attribute.
:returns: the new value data length
:rtype: int)doc")
.def(
"set_write_value",
[](Tango::WAttribute &attr, py::object &value) {
PyWAttribute::set_write_value(attr, value);
},
R"doc(
set_write_value(self, value)
Set the writable attribute value.
:param value: the data to be set. Data must be compatible with the attribute type and format.
for SPECTRUM and IMAGE attributes, data can be any type of sequence of elements
compatible with the attribute type
.. versionchanged:: 10.1.0
The dim_x and dim_y parameters were removed.)doc",
py::arg("value"))
.def("get_write_value",
&PyWAttribute::get_write_value,
R"doc(
get_write_value(self, extract_as=ExtractAs.Numpy) -> obj
Retrieve the new value for writable attribute.
:param extract_as: defaults to ExtractAs.Numpy
:type extract_as: ExtractAs
:returns: the attribute write value.
:rtype: obj)doc",
py::arg_v("extract_as", PyTango::ExtractAsNumpy, "ExtractAs.Numpy"));
fix_dynamic_attr_dealloc<Tango::WAttribute>();
}
|