Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
549ec004
Commit
549ec004
authored
Jul 05, 2015
by
Olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow to read DataValue from node. change a bit get_attribute method, fix a test for pypy
parent
25fdae58
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
22 deletions
+64
-22
opcua/node.py
opcua/node.py
+19
-10
opcua/uatypes.py
opcua/uatypes.py
+15
-10
setup.py
setup.py
+1
-1
tests.py
tests.py
+29
-1
No files found.
opcua/node.py
View file @
549ec004
...
...
@@ -129,43 +129,50 @@ class Node(object):
composed of a string(name) and a namespace index.
"""
result
=
self
.
get_attribute
(
ua
.
AttributeIds
.
BrowseName
)
return
result
.
Value
return
result
.
Value
.
Value
def
get_display_name
(
self
):
"""
get description attribute of node
"""
result
=
self
.
get_attribute
(
ua
.
AttributeIds
.
DisplayName
)
return
result
.
Value
return
result
.
Value
.
Value
def
get_data_type
(
self
):
"""
get data type of node
"""
result
=
self
.
get_attribute
(
ua
.
AttributeIds
.
DataType
)
return
result
.
Value
return
result
.
Value
.
Value
def
get_node_class
(
self
):
"""
get node class attribute of node
"""
result
=
self
.
get_attribute
(
ua
.
AttributeIds
.
NodeClass
)
return
result
.
Value
return
result
.
Value
.
Value
def
get_description
(
self
):
"""
get description attribute class of node
"""
result
=
self
.
get_attribute
(
ua
.
AttributeIds
.
Description
)
return
result
.
Value
return
result
.
Value
.
Value
def
get_value
(
self
):
"""
Get value of a node. Only variables(properties) have values.
Get value of a node
as a python type
. Only variables(properties) have values.
An exception will be generated for other node types.
"""
result
=
self
.
get_attribute
(
ua
.
AttributeIds
.
Value
)
return
result
.
Value
result
=
self
.
get_data_value
()
return
result
.
Value
.
Value
def
get_data_value
(
self
):
"""
Get value of a node as a python type. Only variables(properties) have values.
An exception will be generated for other node types.
"""
return
self
.
get_attribute
(
ua
.
AttributeIds
.
Value
)
def
set_value
(
self
,
value
,
varianttype
=
None
):
"""
...
...
@@ -186,6 +193,8 @@ class Node(object):
datavalue
=
ua
.
DataValue
(
ua
.
Variant
(
value
,
varianttype
))
self
.
set_attribute
(
ua
.
AttributeIds
.
Value
,
datavalue
)
set_data_value
=
set_value
def
set_attribute
(
self
,
attributeid
,
datavalue
):
"""
Set an attribute of a node
...
...
@@ -201,7 +210,7 @@ class Node(object):
def
get_attribute
(
self
,
attr
):
"""
Get an
attribute of a node
Read one
attribute of a node
"""
rv
=
ua
.
ReadValueId
()
rv
.
NodeId
=
self
.
nodeid
...
...
@@ -210,7 +219,7 @@ class Node(object):
params
.
NodesToRead
.
append
(
rv
)
result
=
self
.
server
.
read
(
params
)
result
[
0
].
StatusCode
.
check
()
return
result
[
0
]
.
Value
return
result
[
0
]
def
get_children
(
self
,
refs
=
ua
.
ObjectIds
.
HierarchicalReferences
,
nodeclassmask
=
ua
.
NodeClass
.
Unspecified
):
"""
...
...
opcua/uatypes.py
View file @
549ec004
...
...
@@ -50,10 +50,9 @@ def datetime_to_win_epoch(dt):
def
win_epoch_to_datetime
(
epch
):
(
s
,
ns100
)
=
divmod
(
epch
-
EPOCH_AS_FILETIME
,
HUNDREDS_OF_NANOSECONDS
)
try
:
# TDA, this generates exceptions on systems where RTC is really off
dt
=
datetime
.
utcfromtimestamp
(
s
)
except
:
logger
.
debug
(
"Exception occurred during conversion within 'win_epoch_to_datetime'.
"
)
except
Exception
as
ex
:
#FIXME: find out what kind of exceptin is raised!!!
logger
.
debug
(
"Exception occurred during conversion within 'win_epoch_to_datetime'.
%s"
,
ex
)
return
datetime
.
now
()
dt
=
dt
.
replace
(
microsecond
=
(
ns100
//
10
))
return
dt
...
...
@@ -850,12 +849,18 @@ class DataValue(FrozenClass):
return
obj
def
__str__
(
self
):
return
'DataValue('
+
'Encoding:'
+
str
(
self
.
Encoding
)
+
', '
+
\
'Value:'
+
str
(
self
.
Value
)
+
', '
+
\
'StatusCode:'
+
str
(
self
.
StatusCode
)
+
', '
+
\
'SourceTimestamp:'
+
str
(
self
.
SourceTimestamp
)
+
', '
+
\
'ServerTimestamp:'
+
str
(
self
.
ServerTimestamp
)
+
', '
+
\
'SourcePicoseconds:'
+
str
(
self
.
SourcePicoseconds
)
+
', '
+
\
'ServerPicoseconds:'
+
str
(
self
.
ServerPicoseconds
)
+
')'
s
=
'DataValue(Value:{})'
.
format
(
self
.
Value
)
if
self
.
StatusCode
is
not
None
:
s
+=
', StatusCode:{}'
.
format
(
self
.
StatusCode
)
if
self
.
SourceTimestamp
is
not
None
:
s
+=
', SourceTimestamp:{}'
.
format
(
self
.
SourceTimestamp
)
if
self
.
ServerTimestamp
is
not
None
:
s
+=
', ServerTimestamp:{}'
.
format
(
self
.
ServerTimestamp
)
if
self
.
SourcePicoseconds
is
not
None
:
s
+=
', SourcePicoseconds:{}'
.
format
(
self
.
SourcePicoseconds
)
if
self
.
ServerPicoseconds
is
not
None
:
s
+=
', ServerPicoseconds:{}'
.
format
(
self
.
ServerPicoseconds
)
s
+=
')'
return
s
__repr__
=
__str__
setup.py
View file @
549ec004
...
...
@@ -3,7 +3,7 @@ from distutils.command.install_data import install_data
setup
(
name
=
"freeopcua"
,
version
=
"0.9.
3
"
,
version
=
"0.9.
6
"
,
description
=
"Pure Python OPC-UA client and server library"
,
author
=
"Olivier Roulet-Dubonnet"
,
author_email
=
"olivier.roulet@gmail.com"
,
...
...
tests.py
View file @
549ec004
...
...
@@ -456,6 +456,34 @@ class CommonTests(object):
with
self
.
assertRaises
(
Exception
):
bad
.
get_child
(
0
,
"myobj"
)
def
test_value
(
self
):
o
=
self
.
opc
.
get_objects_node
()
var
=
ua
.
Variant
(
1.98
,
ua
.
VariantType
.
Double
)
v
=
o
.
add_variable
(
3
,
'VariableValue'
,
var
)
val
=
v
.
get_value
()
self
.
assertEqual
(
1.98
,
val
)
dvar
=
ua
.
DataValue
(
var
)
dv
=
v
.
get_data_value
()
self
.
assertEqual
(
ua
.
DataValue
,
type
(
dv
))
self
.
assertEqual
(
dvar
.
Value
,
dv
.
Value
)
self
.
assertEqual
(
dvar
.
Value
,
var
)
def
test_set_value
(
self
):
o
=
self
.
opc
.
get_objects_node
()
var
=
ua
.
Variant
(
1.98
,
ua
.
VariantType
.
Double
)
dvar
=
ua
.
DataValue
(
var
)
v
=
o
.
add_variable
(
3
,
'VariableValue'
,
var
)
v
.
set_value
(
var
.
Value
)
v1
=
v
.
get_value
()
self
.
assertEqual
(
v1
,
var
.
Value
)
v
.
set_value
(
var
)
v2
=
v
.
get_value
()
self
.
assertEqual
(
v2
,
var
.
Value
)
v
.
set_data_value
(
dvar
)
v3
=
v
.
get_data_value
()
self
.
assertEqual
(
v3
.
Value
,
dvar
.
Value
)
def
test_array_value
(
self
):
o
=
self
.
opc
.
get_objects_node
()
v
=
o
.
add_variable
(
3
,
'VariableArrayValue'
,
[
1
,
2
,
3
])
...
...
@@ -528,7 +556,7 @@ class CommonTests(object):
clthandle
,
node
,
val
,
attr
=
msclt
.
future
.
result
()
self
.
assertEqual
(
node
,
server_time_node
)
delta
=
datetime
.
now
()
-
val
self
.
assertTrue
(
delta
<
timedelta
(
seconds
=
1
))
self
.
assertTrue
(
delta
<
timedelta
(
seconds
=
2
))
sub
.
unsubscribe
(
handle
)
sub
.
delete
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment