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
b1a80860
Commit
b1a80860
authored
Jul 05, 2016
by
Denis Štogl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for custom datatypes and removed some trailing spaces
parent
6d2c46e4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
16 deletions
+19
-16
opcua/common/manage_nodes.py
opcua/common/manage_nodes.py
+10
-7
opcua/common/node.py
opcua/common/node.py
+2
-2
tests/tests_common.py
tests/tests_common.py
+7
-7
No files found.
opcua/common/manage_nodes.py
View file @
b1a80860
...
...
@@ -37,7 +37,7 @@ def create_folder(parent, *args):
or namespace index, name
"""
nodeid
,
qname
=
_parse_add_args
(
*
args
)
return
node
.
Node
(
parent
.
server
,
_create_object
(
parent
.
server
,
parent
.
nodeid
,
nodeid
,
qname
,
ua
.
ObjectIds
.
FolderType
))
return
node
.
Node
(
parent
.
server
,
_create_object
(
parent
.
server
,
parent
.
nodeid
,
nodeid
,
qname
,
ua
.
ObjectIds
.
FolderType
,
ua
.
NodeClass
.
Object
))
def
create_object
(
parent
,
*
args
):
...
...
@@ -63,7 +63,7 @@ def create_object(parent, *args):
raise
except
Exception
as
ex
:
raise
TypeError
(
"This provided objecttype takes either a index, nodeid or string. Received arguments {} and got exception {}"
.
format
(
args
,
ex
))
return
node
.
Node
(
parent
.
server
,
_create_object
(
parent
.
server
,
parent
.
nodeid
,
nodeid
,
qname
,
objecttype
))
return
node
.
Node
(
parent
.
server
,
_create_object
(
parent
.
server
,
parent
.
nodeid
,
nodeid
,
qname
,
objecttype
,
ua
.
NodeClass
.
Object
))
def
create_property
(
parent
,
*
args
):
...
...
@@ -116,19 +116,23 @@ def create_subtype(parent, *args):
arguments are nodeid, browsename
or namespace index, name
"""
nodeid
,
qname
=
_parse_add_args
(
*
args
)
return
node
.
Node
(
parent
.
server
,
_create_object
(
parent
.
server
,
parent
.
nodeid
,
nodeid
,
qname
,
None
))
nodeid
,
qname
=
_parse_add_args
(
*
args
[:
2
])
if
len
(
args
)
>
3
:
node_class
=
args
[
3
]
else
:
node_class
=
ua
.
NodeClass
.
ObjectType
return
node
.
Node
(
parent
.
server
,
_create_object
(
parent
.
server
,
parent
.
nodeid
,
nodeid
,
qname
,
None
,
node_class
))
def
_create_object
(
server
,
parentnodeid
,
nodeid
,
qname
,
objecttype
):
def
_create_object
(
server
,
parentnodeid
,
nodeid
,
qname
,
objecttype
,
node_class
):
addnode
=
ua
.
AddNodesItem
()
addnode
.
RequestedNewNodeId
=
nodeid
addnode
.
BrowseName
=
qname
addnode
.
ParentNodeId
=
parentnodeid
addnode
.
NodeClass
=
node_class
#TODO: maybe move to address_space.py and implement for all node types?
if
not
objecttype
:
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasSubtype
)
addnode
.
NodeClass
=
ua
.
NodeClass
.
ObjectType
attrs
=
ua
.
ObjectTypeAttributes
()
attrs
.
IsAbstract
=
True
else
:
...
...
@@ -137,7 +141,6 @@ def _create_object(server, parentnodeid, nodeid, qname, objecttype):
else
:
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasComponent
)
addnode
.
NodeClass
=
ua
.
NodeClass
.
Object
if
isinstance
(
objecttype
,
int
):
addnode
.
TypeDefinition
=
ua
.
NodeId
(
objecttype
)
elif
isinstance
(
objecttype
,
ua
.
NodeId
):
...
...
opcua/common/node.py
View file @
b1a80860
...
...
@@ -71,7 +71,7 @@ class Node(object):
def
get_data_type_as_variant_type
(
self
):
"""
get data type of node as VariantType
This only works if node is a variable, otherwise type
This only works if node is a variable, otherwise type
may not be convertible to VariantType
"""
result
=
self
.
get_attribute
(
ua
.
AttributeIds
.
DataType
)
...
...
@@ -424,7 +424,7 @@ class Node(object):
def
read_event_history
(
self
,
starttime
=
None
,
endtime
=
None
,
numvalues
=
0
,
evtypes
=
ua
.
ObjectIds
.
BaseEventType
):
"""
Read event history of a source node
Read event history of a source node
result code from server is checked and an exception is raised in case of error
If numvalues is > 0 and number of events in period is > numvalues
then result will be truncated
...
...
tests/tests_common.py
View file @
b1a80860
...
...
@@ -479,26 +479,26 @@ class CommonTests(object):
self
.
assertTrue
(
v
in
childs
)
self
.
assertTrue
(
p
in
childs
)
def
test_add_node_withtype
(
self
):
def
test_add_node_withtype
(
self
):
objects
=
self
.
opc
.
get_objects_node
()
f
=
objects
.
add_folder
(
3
,
'MyFolder_TypeTest'
)
o
=
f
.
add_object
(
3
,
'MyObject1'
,
ua
.
ObjectIds
.
BaseObjectType
)
self
.
assertEqual
(
o
.
get_type_definition
(),
ua
.
ObjectIds
.
BaseObjectType
)
o
=
f
.
add_object
(
3
,
'MyObject2'
,
ua
.
NodeId
(
ua
.
ObjectIds
.
BaseObjectType
,
0
)
)
o
=
f
.
add_object
(
3
,
'MyObject2'
,
ua
.
NodeId
(
ua
.
ObjectIds
.
BaseObjectType
,
0
))
self
.
assertEqual
(
o
.
get_type_definition
(),
ua
.
ObjectIds
.
BaseObjectType
)
base_otype
=
self
.
opc
.
get_node
(
ua
.
ObjectIds
.
BaseObjectType
)
custom_otype
=
base_otype
.
add_subtype
(
2
,
'MyFooObjectType'
)
o
=
f
.
add_object
(
3
,
'MyObject3'
,
custom_otype
.
nodeid
)
o
=
f
.
add_object
(
3
,
'MyObject3'
,
custom_otype
.
nodeid
)
self
.
assertEqual
(
o
.
get_type_definition
(),
custom_otype
.
nodeid
.
Identifier
)
references
=
o
.
get_references
(
refs
=
ua
.
ObjectIds
.
HasTypeDefinition
,
direction
=
ua
.
BrowseDirection
.
Forward
)
self
.
assertEqual
(
len
(
references
),
1
)
self
.
assertEqual
(
len
(
references
),
1
)
self
.
assertEqual
(
references
[
0
].
NodeId
,
custom_otype
.
nodeid
)
def
test_references_for_added_nodes
(
self
):
objects
=
self
.
opc
.
get_objects_node
()
o
=
objects
.
add_object
(
3
,
'MyObject'
)
...
...
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