Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DynamicAttributes
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
spe
ds
DynamicAttributes
Commits
45eb1d2a
Commit
45eb1d2a
authored
3 years ago
by
Martin Scarcia
Browse files
Options
Downloads
Patches
Plain Diff
pyhton3 + new config changes
parent
34d2e59c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dynamic-srv.py
+34
-35
34 additions, 35 deletions
src/dynamic-srv.py
with
34 additions
and
35 deletions
src/dynamic-srv.py
+
34
−
35
View file @
45eb1d2a
...
...
@@ -7,7 +7,7 @@ import sys
import
os
sys
.
path
.
insert
(
0
,
os
.
path
.
abspath
(
'
.
'
))
from
UserDict
import
UserDict
from
collections
import
UserDict
import
PyTango
import
numpy
as
np
import
importlib
...
...
@@ -217,6 +217,9 @@ class Dynamic(PyTango.Device_4Impl):
self
.
myattrs
=
CaseLessDict
()
self
.
read_functions
=
CaseLessDict
()
self
.
write_functions
=
CaseLessDict
()
#link to the Tango DB
self
.
db
=
PyTango
.
Database
()
aux
=
self
.
FiltersScript
.
split
(
'
/
'
)
path
=
'
/
'
.
join
(
aux
[:
-
1
])
if
path
:
...
...
@@ -247,11 +250,9 @@ class Dynamic(PyTango.Device_4Impl):
self
.
set_state
(
PyTango
.
DevState
.
OFF
)
return
#link to the Tango DB
self
.
db
=
PyTango
.
Database
()
#creation of dynamic attributes from cfg script
dynattrs
=
self
.
cfg_module
.
createDynAttrsDict
()
#creation of dynamic attributes.
for
attr
in
dynattrs
:
attr_obj
=
dynattrs
[
attr
]
...
...
@@ -276,25 +277,16 @@ class Dynamic(PyTango.Device_4Impl):
PyTango
.
Except
.
throw_exception
(
"
Exist
"
,
"
Attribute
"
+
attr_obj
.
name
+
"
already defined
"
,
"
NewAttribute
"
)
tango_type
=
dataType2TangoType
(
attr_obj
.
type
.
upper
())
permission
=
READ_ONLY
if
attr_obj
.
flag
==
READ_ONLY
:
permission
=
PyTango
.
AttrWriteType
.
READ
elif
attr_obj
.
flag
==
READ_WRITE
:
permission
=
PyTango
.
AttrWriteType
.
READ_WRITE
elif
attr_obj
.
flag
==
WRITE_ONLY
:
#FIXME: check if it is possible to have write only
permission
=
PyTango
.
AttrWriteType
.
READ_WRITE
# It's possible to define python methods for calculating the attribute value
self
.
read_functions
[
attr_obj
.
name
]
=
attr_obj
.
read_function
self
.
write_functions
[
attr_obj
.
name
]
=
attr_obj
.
write_function
if
attr_obj
.
dimension
==
1
:
attr
=
PyTango
.
Attr
(
str
(
attr_obj
.
name
),
tango_type
,
permission
)
attr
=
PyTango
.
Attr
(
str
(
attr_obj
.
name
),
attr_obj
.
datatype
,
attr_obj
.
permission
)
if
attr_obj
.
memorized
==
1
:
attr
.
set_memorized
()
self
.
add_attribute
(
attr
,
self
.
read_Scalar
,
self
.
write_Scalar
)
if
tango_
type
==
PyTango
.
ArgType
.
DevString
:
if
attr_obj
.
data
type
==
PyTango
.
ArgType
.
DevString
:
self
.
myattrs
[
attr_obj
.
name
]
=
""
else
:
self
.
myattrs
[
attr_obj
.
name
]
=
0
...
...
@@ -304,37 +296,37 @@ class Dynamic(PyTango.Device_4Impl):
dev_attr_props
=
self
.
db
.
get_device_attribute_property
(
self
.
get_name
(),[
attr_obj
.
name
])
attr_prop
=
dev_attr_props
[
attr_obj
.
name
]
for
pr
in
attr_prop
.
keys
():
if
(
pr
==
'
__value
'
)
and
(
tango_
type
==
PyTango
.
ArgType
.
DevString
):
if
(
pr
==
'
__value
'
)
and
(
attr_obj
.
data
type
==
PyTango
.
ArgType
.
DevString
):
self
.
myattrs
[
attr_obj
.
name
]
=
attr_prop
[
'
__value
'
][
0
]
elif
(
pr
==
'
__value
'
)
and
(
tango_
type
==
PyTango
.
ArgType
.
DevFloat
):
elif
(
pr
==
'
__value
'
)
and
(
attr_obj
.
data
type
==
PyTango
.
ArgType
.
DevFloat
):
self
.
myattrs
[
attr_obj
.
name
]
=
float
(
attr_prop
[
'
__value
'
][
0
])
elif
(
pr
==
'
__value
'
)
and
(
tango_
type
==
PyTango
.
ArgType
.
DevDouble
):
elif
(
pr
==
'
__value
'
)
and
(
attr_obj
.
data
type
==
PyTango
.
ArgType
.
DevDouble
):
self
.
myattrs
[
attr_obj
.
name
]
=
float
(
attr_prop
[
'
__value
'
][
0
])
elif
(
pr
==
'
__value
'
)
and
(
tango_
type
==
PyTango
.
ArgType
.
DevBoolean
):
elif
(
pr
==
'
__value
'
)
and
(
attr_obj
.
data
type
==
PyTango
.
ArgType
.
DevBoolean
):
self
.
myattrs
[
attr_obj
.
name
]
=
bool
(
attr_prop
[
'
__value
'
][
0
]
==
"
True
"
)
elif
(
pr
==
'
__value
'
):
self
.
myattrs
[
attr_obj
.
name
]
=
int
(
attr_prop
[
'
__value
'
][
0
])
elif
isinstance
(
attr_obj
.
dimension
,
tuple
):
sizx
=
attr_obj
.
dimension
[
0
]
sizy
=
attr_obj
.
dimension
[
1
]
attr
=
PyTango
.
ImageAttr
(
str
(
attr_obj
.
name
),
tango_type
,
permission
,
sizx
,
sizy
)
attr
=
PyTango
.
ImageAttr
(
str
(
attr_obj
.
name
),
attr_obj
.
datatype
,
attr_obj
.
permission
,
sizx
,
sizy
)
self
.
add_attribute
(
attr
,
self
.
read_Image
,
self
.
write_Image
)
if
attr_obj
.
default
:
self
.
myattrs
[
attr_obj
.
name
]
=
eval
(
attr_obj
.
default
)
elif
tango_
type
==
PyTango
.
ArgType
.
DevString
:
elif
attr_obj
.
data
type
==
PyTango
.
ArgType
.
DevString
:
self
.
myattrs
[
attr_obj
.
name
]
=
[[],[]]
else
:
self
.
myattrs
[
attr_obj
.
name
]
=
np
.
zeros
((
sizy
,
sizx
),
fromPyTango2NumpyType
(
tango_
type
))
self
.
myattrs
[
attr_obj
.
name
]
=
np
.
zeros
((
sizy
,
sizx
),
fromPyTango2NumpyType
(
attr_obj
.
data
type
))
else
:
self
.
debug_stream
(
"
Creation of attribute %s, dimension = %s
"
%
(
attr_obj
.
name
,
str
(
attr_obj
.
dimension
)))
attr
=
PyTango
.
SpectrumAttr
(
str
(
attr_obj
.
name
),
tango_type
,
permission
,
attr_obj
.
dimension
)
attr
=
PyTango
.
SpectrumAttr
(
str
(
attr_obj
.
name
),
attr_obj
.
datatype
,
attr_obj
.
permission
,
attr_obj
.
dimension
)
self
.
add_attribute
(
attr
,
self
.
read_Spectrum
,
self
.
write_Spectrum
)
if
attr_obj
.
default
:
self
.
myattrs
[
attr_obj
.
name
]
=
eval
(
attr_obj
.
default
)
elif
tango_
type
==
PyTango
.
ArgType
.
DevString
:
elif
attr_obj
.
data
type
==
PyTango
.
ArgType
.
DevString
:
self
.
myattrs
[
attr_obj
.
name
]
=
[]
else
:
self
.
myattrs
[
attr_obj
.
name
]
=
np
.
zeros
(
attr_obj
.
dimension
,
fromPyTango2NumpyType
(
tango_
type
))
self
.
myattrs
[
attr_obj
.
name
]
=
np
.
zeros
(
attr_obj
.
dimension
,
fromPyTango2NumpyType
(
attr_obj
.
data
type
))
self
.
set_state
(
PyTango
.
DevState
.
ON
)
...
...
@@ -438,14 +430,18 @@ class Dynamic(PyTango.Device_4Impl):
# argin: DevVarStringArray Name - of the new scalar attribute\nDOUBLE, SHORT, LONG for the type of the attribute\n
#------------------------------------------------------------------
def
NewScalar
(
self
,
argin
):
#print "In ", self.get_name(), "::NewScalar()
"
#print "In ", self.get_name(), "::NewScalar()
(
name
,
typ
)
=
processInputStringArray
(
argin
)
attr
=
PyTango
.
Attr
(
name
,
typ
,
PyTango
.
AttrWriteType
.
READ_WRITE
)
if
self
.
myattrs
.
has_key
(
name
)
:
if
name
in
self
.
myattrs
:
PyTango
.
Except
.
throw_exception
(
"
Exist
"
,
"
Attribute
"
+
name
+
"
already defined
"
,
"
NewAttribute
"
)
self
.
add_attribute
(
attr
,
self
.
read_Scalar
,
self
.
write_Scalar
,
None
)
self
.
myattrs
[
name
]
=
0
# init missing entries in dictionaries
self
.
read_functions
[
name
]
=
""
self
.
write_functions
[
name
]
=
""
#------------------------------------------------------------------
...
...
@@ -462,13 +458,14 @@ class Dynamic(PyTango.Device_4Impl):
PyTango
.
AttrWriteType
.
READ_WRITE
,
siz
)
if
self
.
myattrs
.
has_key
(
name
)
:
if
name
in
self
.
myattrs
:
PyTango
.
Except
.
throw_exception
(
"
Exist
"
,
"
Attribute
"
+
name
+
"
already defined
"
,
"
NewAttribute
"
)
self
.
add_attribute
(
attr
,
self
.
read_Spectrum
,
self
.
write_Spectrum
,
None
)
self
.
myattrs
[
name
]
=
np
.
zeros
(
siz
,
fromPyTango2NumpyType
(
typ
))
self
.
myattrs
[
name
]
=
np
.
zeros
(
siz
,
fromPyTango2NumpyType
(
typ
))
# init missing entries in dictionaries
self
.
read_functions
[
name
]
=
""
self
.
write_functions
[
name
]
=
""
#------------------------------------------------------------------
# NewImage command:
#
...
...
@@ -482,11 +479,13 @@ class Dynamic(PyTango.Device_4Impl):
attr
=
PyTango
.
ImageAttr
(
name
,
typ
,
PyTango
.
AttrWriteType
.
READ_WRITE
,
sizx
,
sizy
)
if
self
.
myattrs
.
has_key
(
name
)
:
if
name
in
self
.
myattrs
:
PyTango
.
Except
.
throw_exception
(
"
Exist
"
,
"
Attribute
"
+
name
+
"
already defined
"
,
"
NewAttribute
"
)
self
.
add_attribute
(
attr
,
self
.
read_Image
,
self
.
write_Image
,
None
)
self
.
myattrs
[
name
]
=
np
.
zeros
((
sizy
,
sizx
),
fromPyTango2NumpyType
(
typ
))
#print self.myattrs[name].dtype
# init missing entries in dictionaries
self
.
read_functions
[
name
]
=
""
self
.
write_functions
[
name
]
=
""
#------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment