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
e75d1e58
Commit
e75d1e58
authored
3 years ago
by
Martin Scarcia
Browse files
Options
Downloads
Patches
Plain Diff
indentation fix
parent
0b4f3b94
No related branches found
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
+69
-75
69 additions, 75 deletions
src/dynamic-srv.py
with
69 additions
and
75 deletions
src/dynamic-srv.py
+
69
−
75
View file @
e75d1e58
...
...
@@ -46,7 +46,6 @@ import PyTango
import
time
import
numpy
as
np
import
signal
def
fromPyTango2NumpyType
(
pytango_type
):
...
...
@@ -242,7 +241,7 @@ class Dynamic(PyTango.Device_4Impl):
# Device destructor
#------------------------------------------------------------------
def
delete_device
(
self
):
self
.
debug_stream
(
"
In %s::delete_device()
"
%
self
.
get_name
())
self
.
debug_stream
(
"
In %s::delete_device()
"
%
self
.
get_name
())
#------------------------------------------------------------------
# Device initialization
...
...
@@ -262,20 +261,20 @@ class Dynamic(PyTango.Device_4Impl):
module_name
=
aux
[
-
1
].
replace
(
'
.py
'
,
''
)
try
:
self
.
module
=
__import__
(
module_name
)
except
ImportError
,
ex
:
except
ImportError
as
ex
:
sys
.
stderr
.
write
(
str
(
ex
)
+
"
\n
"
)
self
.
module
=
None
self
.
set_state
(
PyTango
.
DevState
.
FAULT
)
self
.
set_status
(
"
Invalid Filters Script
"
+
self
.
FiltersScript
)
return
#link to the Tango DB
#link to the Tango DB
self
.
db
=
PyTango
.
Database
()
#creation of dynamic attributes.
try
:
xml_file
=
ScriptXmlConfig
(
self
.
XmlConfigurator
)
except
InvalidFileError
,
ex
:
except
InvalidFileError
as
ex
:
self
.
warn_stream
(
"
Invalid xml file
\n
"
)
self
.
set_state
(
PyTango
.
DevState
.
OFF
)
return
...
...
@@ -289,15 +288,14 @@ class Dynamic(PyTango.Device_4Impl):
attr_config
=
attr_proxy
.
get_config
()
#
if
str
(
attr_config
.
data_format
)
==
"
SCALAR
"
:
attr
=
PyTango
.
Attr
(
str
(
value
.
name
),
attr_config
.
data_type
,
attr_config
.
writable
)
elif
str
(
attr_config
.
data_format
)
==
"
SPECTRUM
"
:
attr
=
PyTango
.
SpectrumAttr
(
str
(
value
.
name
),
attr_config
.
data_type
,
attr_config
.
writable
,
attr_config
.
max_dim_x
)
elif
str
(
attr_config
.
data_format
)
==
"
IMAGE
"
:
attr
=
PyTango
.
ImageAttr
(
str
(
value
.
name
),
attr_config
.
data_type
,
attr_config
.
writable
,
attr_config
.
max_dim_x
,
attr_config
.
max_dim_y
)
#
self
.
add_attribute
(
attr
,
self
.
read_proxy
,
self
.
write_proxy
)
attr
=
PyTango
.
Attr
(
str
(
value
.
name
),
attr_config
.
data_type
,
attr_config
.
writable
)
elif
str
(
attr_config
.
data_format
)
==
"
SPECTRUM
"
:
attr
=
PyTango
.
SpectrumAttr
(
str
(
value
.
name
),
attr_config
.
data_type
,
attr_config
.
writable
,
attr_config
.
max_dim_x
)
elif
str
(
attr_config
.
data_format
)
==
"
IMAGE
"
:
attr
=
PyTango
.
ImageAttr
(
str
(
value
.
name
),
attr_config
.
data_type
,
attr_config
.
writable
,
attr_config
.
max_dim_x
,
attr_config
.
max_dim_y
)
self
.
add_attribute
(
attr
,
self
.
read_proxy
,
self
.
write_proxy
)
self
.
myattrs
[
value
.
name
]
=
attr_proxy
except
PyTango
.
DevFailed
,
ex
:
except
PyTango
.
DevFailed
as
ex
:
self
.
warn_stream
(
"
%s
"
%
str
(
ex
))
continue
if
self
.
myattrs
.
has_key
(
value
.
name
):
...
...
@@ -327,44 +325,44 @@ class Dynamic(PyTango.Device_4Impl):
else
:
self
.
myattrs
[
value
.
name
]
=
0
if
value
.
default
:
self
.
myattrs
[
value
.
name
]
=
eval
(
value
.
default
)
self
.
myattrs
[
value
.
name
]
=
eval
(
value
.
default
)
if
value
.
memorized
==
1
:
dev_attr_props
=
self
.
db
.
get_device_attribute_property
(
self
.
get_name
(),[
value
.
name
])
attr_prop
=
dev_attr_props
[
value
.
name
]
for
pr
in
attr_prop
.
keys
():
if
(
pr
==
'
__value
'
)
and
(
tango_type
==
PyTango
.
ArgType
.
DevString
):
self
.
myattrs
[
value
.
name
]
=
attr_prop
[
'
__value
'
][
0
]
elif
(
pr
==
'
__value
'
)
and
(
tango_type
==
PyTango
.
ArgType
.
DevFloat
):
self
.
myattrs
[
value
.
name
]
=
float
(
attr_prop
[
'
__value
'
][
0
])
elif
(
pr
==
'
__value
'
)
and
(
tango_type
==
PyTango
.
ArgType
.
DevDouble
):
self
.
myattrs
[
value
.
name
]
=
float
(
attr_prop
[
'
__value
'
][
0
])
elif
(
pr
==
'
__value
'
)
and
(
tango_type
==
PyTango
.
ArgType
.
DevBoolean
):
self
.
myattrs
[
value
.
name
]
=
bool
(
attr_prop
[
'
__value
'
][
0
]
==
"
True
"
)
elif
(
pr
==
'
__value
'
):
self
.
myattrs
[
value
.
name
]
=
int
(
attr_prop
[
'
__value
'
][
0
])
dev_attr_props
=
self
.
db
.
get_device_attribute_property
(
self
.
get_name
(),[
value
.
name
])
attr_prop
=
dev_attr_props
[
value
.
name
]
for
pr
in
attr_prop
.
keys
():
if
(
pr
==
'
__value
'
)
and
(
tango_type
==
PyTango
.
ArgType
.
DevString
):
self
.
myattrs
[
value
.
name
]
=
attr_prop
[
'
__value
'
][
0
]
elif
(
pr
==
'
__value
'
)
and
(
tango_type
==
PyTango
.
ArgType
.
DevFloat
):
self
.
myattrs
[
value
.
name
]
=
float
(
attr_prop
[
'
__value
'
][
0
])
elif
(
pr
==
'
__value
'
)
and
(
tango_type
==
PyTango
.
ArgType
.
DevDouble
):
self
.
myattrs
[
value
.
name
]
=
float
(
attr_prop
[
'
__value
'
][
0
])
elif
(
pr
==
'
__value
'
)
and
(
tango_type
==
PyTango
.
ArgType
.
DevBoolean
):
self
.
myattrs
[
value
.
name
]
=
bool
(
attr_prop
[
'
__value
'
][
0
]
==
"
True
"
)
elif
(
pr
==
'
__value
'
):
self
.
myattrs
[
value
.
name
]
=
int
(
attr_prop
[
'
__value
'
][
0
])
elif
isinstance
(
value
.
dimension
,
tuple
):
sizx
=
value
.
dimension
[
0
]
sizy
=
value
.
dimension
[
1
]
attr
=
PyTango
.
ImageAttr
(
str
(
value
.
name
),
tango_type
,
permission
,
sizx
,
sizy
)
self
.
add_attribute
(
attr
,
self
.
read_Image
,
self
.
write_Image
)
if
value
.
default
:
self
.
myattrs
[
value
.
name
]
=
eval
(
value
.
default
)
self
.
myattrs
[
value
.
name
]
=
eval
(
value
.
default
)
elif
tango_type
==
PyTango
.
ArgType
.
DevString
:
self
.
myattrs
[
value
.
name
]
=
[[],[]]
else
:
self
.
myattrs
[
value
.
name
]
=
np
.
zeros
((
sizy
,
sizx
),
fromPyTango2NumpyType
(
tango_type
))
else
:
self
.
debug_stream
(
"
Creation of attribute %s, dimension = %s
"
%
(
value
.
name
,
str
(
value
.
dimension
)))
self
.
myattrs
[
value
.
name
]
=
[[],[]]
else
:
self
.
myattrs
[
value
.
name
]
=
np
.
zeros
((
sizy
,
sizx
),
fromPyTango2NumpyType
(
tango_type
))
else
:
self
.
debug_stream
(
"
Creation of attribute %s, dimension = %s
"
%
(
value
.
name
,
str
(
value
.
dimension
)))
attr
=
PyTango
.
SpectrumAttr
(
str
(
value
.
name
),
tango_type
,
permission
,
value
.
dimension
)
self
.
add_attribute
(
attr
,
self
.
read_Spectrum
,
self
.
write_Spectrum
)
if
value
.
default
:
self
.
myattrs
[
value
.
name
]
=
eval
(
value
.
default
)
self
.
myattrs
[
value
.
name
]
=
eval
(
value
.
default
)
elif
tango_type
==
PyTango
.
ArgType
.
DevString
:
self
.
myattrs
[
value
.
name
]
=
[]
else
:
self
.
myattrs
[
value
.
name
]
=
np
.
zeros
(
value
.
dimension
,
fromPyTango2NumpyType
(
tango_type
))
#
self
.
set_state
(
PyTango
.
DevState
.
ON
)
self
.
myattrs
[
value
.
name
]
=
[]
else
:
self
.
myattrs
[
value
.
name
]
=
np
.
zeros
(
value
.
dimension
,
fromPyTango2NumpyType
(
tango_type
))
self
.
set_state
(
PyTango
.
DevState
.
ON
)
#------------------------------------------------------------------
...
...
@@ -406,7 +404,7 @@ class Dynamic(PyTango.Device_4Impl):
# Add your own code here
value_in
=
attr
.
get_write_value
(
PyTango
.
ExtractAs
.
Numpy
)
self
.
write_dynamic_attribute
(
attr
.
get_name
(),
value_in
)
self
.
write_dynamic_attribute
(
attr
.
get_name
(),
value_in
)
#------------------------------------------------------------------
# Read Spectrum attribute
...
...
@@ -416,8 +414,7 @@ class Dynamic(PyTango.Device_4Impl):
# Add your own code here
data
=
self
.
read_dynamic_attribute
(
attr
.
get_name
())
#
attr
.
set_value
(
data
,
len
(
data
))
attr
.
set_value
(
data
,
len
(
data
))
#------------------------------------------------------------------
...
...
@@ -427,8 +424,7 @@ class Dynamic(PyTango.Device_4Impl):
#print "In ", self.get_name(), "::write_Spectrum()"
# Add your own code here
value_in
=
attr
.
get_write_value
(
PyTango
.
ExtractAs
.
Numpy
)
#
self
.
write_dynamic_attribute
(
attr
.
get_name
(),
value_in
)
self
.
write_dynamic_attribute
(
attr
.
get_name
(),
value_in
)
#------------------------------------------------------------------
...
...
@@ -453,20 +449,18 @@ class Dynamic(PyTango.Device_4Impl):
#print "In ", self.get_name(), "::write_Image()"
# Add your own code here
value_in
=
attr
.
get_write_value
(
PyTango
.
ExtractAs
.
Numpy
)
self
.
write_dynamic_attribute
(
attr
.
get_name
(),
value_in
)
self
.
write_dynamic_attribute
(
attr
.
get_name
(),
value_in
)
def
read_proxy
(
self
,
attr
):
# Add your own code here
val
=
self
.
myattrs
[
attr
.
get_name
()].
read
()
data
=
self
.
myattrs
[
attr
.
get_name
()]
data
=
self
.
myattrs
[
attr
.
get_name
()]
attr
.
set_value
(
val
.
value
,
val
.
dim_x
,
val
.
dim_y
)
def
write_proxy
(
self
,
attr
):
val
=
attr
.
get_write_value
(
PyTango
.
ExtractAs
.
Numpy
)
self
.
myattrs
[
attr
.
get_name
()].
write
(
val
)
self
.
myattrs
[
attr
.
get_name
()].
write
(
val
)
#==================================================================
#
...
...
@@ -563,16 +557,16 @@ class Dynamic(PyTango.Device_4Impl):
#------------------------------------------------------------------
def
read_dynamic_attribute
(
self
,
attr_name
):
if
self
.
read_functions
[
attr_name
]
!=
''
:
read_method
=
getattr
(
self
.
module
,
self
.
read_functions
[
attr_name
])
num_of_args
=
read_method
.
func_code
.
co_argcount
if
num_of_args
==
1
:
# If method allows an input parameter,
# it's a reference to this class
data
=
read_method
(
self
)
else
:
data
=
read_method
()
else
:
data
=
self
.
myattrs
[
attr_name
]
read_method
=
getattr
(
self
.
module
,
self
.
read_functions
[
attr_name
])
num_of_args
=
read_method
.
func_code
.
co_argcount
if
num_of_args
==
1
:
# If method allows an input parameter,
# it's a reference to this class
data
=
read_method
(
self
)
else
:
data
=
read_method
()
else
:
data
=
self
.
myattrs
[
attr_name
]
return
data
...
...
@@ -581,22 +575,22 @@ class Dynamic(PyTango.Device_4Impl):
#------------------------------------------------------------------
def
write_dynamic_attribute
(
self
,
attr_name
,
value_in
):
if
self
.
write_functions
[
attr_name
]
!=
''
:
write_method
=
getattr
(
self
.
module
,
self
.
write_functions
[
attr_name
])
num_of_args
=
write_method
.
func_code
.
co_argcount
if
num_of_args
==
2
:
# If method allows two input parameter,
# the first is a reference to this class
value
=
write_method
(
self
,
value_in
)
else
:
value
=
write_method
(
value_in
)
else
:
value
=
value_in
self
.
myattrs
[
attr_name
]
=
value
if
type
(
value_in
)
not
in
(
int
,
float
,
str
,
bool
,
long
):
# Only scalar values can be memorized
return
dict_in
=
{
attr_name
:{
'
__value
'
:
value_in
}}
self
.
db
.
put_device_attribute_property
(
self
.
get_name
(),
dict_in
)
write_method
=
getattr
(
self
.
module
,
self
.
write_functions
[
attr_name
])
num_of_args
=
write_method
.
func_code
.
co_argcount
if
num_of_args
==
2
:
# If method allows two input parameter,
# the first is a reference to this class
value
=
write_method
(
self
,
value_in
)
else
:
value
=
write_method
(
value_in
)
else
:
value
=
value_in
self
.
myattrs
[
attr_name
]
=
value
if
type
(
value_in
)
not
in
(
int
,
float
,
str
,
bool
,
long
):
# Only scalar values can be memorized
return
dict_in
=
{
attr_name
:{
'
__value
'
:
value_in
}}
self
.
db
.
put_device_attribute_property
(
self
.
get_name
(),
dict_in
)
#==================================================================
...
...
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