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
a083a9b6
Commit
a083a9b6
authored
Jun 15, 2016
by
bitkeeper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support providing objecttype for the method add_object of Node
parent
5b146814
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
2 deletions
+109
-2
examples/customobject.xml
examples/customobject.xml
+35
-0
examples/server-customobject.py
examples/server-customobject.py
+52
-0
opcua/common/manage_nodes.py
opcua/common/manage_nodes.py
+22
-2
No files found.
examples/customobject.xml
0 → 100644
View file @
a083a9b6
<UANodeSet
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:uax=
"http://opcfoundation.org/UA/2008/02/Types.xsd"
xmlns=
"http://opcfoundation.org/UA/2011/03/UANodeSet.xsd"
xmlns:s1=
"https://github.com/FreeOpcUa/python-opcua/customobject/Types.xsd"
xmlns:xsd=
"http://www.w3.org/2001/XMLSchema"
>
<NamespaceUris>
<Uri>
https://github.com/FreeOpcUa/python-opcua/customobject
</Uri>
</NamespaceUris>
<Aliases>
<Alias
Alias=
"Double"
>
i=11
</Alias>
<Alias
Alias=
"HasModellingRule"
>
i=37
</Alias>
<Alias
Alias=
"HasTypeDefinition"
>
i=40
</Alias>
<Alias
Alias=
"HasSubtype"
>
i=45
</Alias>
<Alias
Alias=
"HasComponent"
>
i=47
</Alias>
</Aliases>
<Extensions>
<Extension>
<ModelInfo
Tool=
"UaModeler"
Hash=
"qnoF+0+hDsL4GCM37vuINw=="
Version=
"1.4.3"
/>
</Extension>
</Extensions>
<UAObjectType
NodeId=
"ns=1;i=1002"
BrowseName=
"1:MyObjectType"
>
<DisplayName>
MyObjectType
</DisplayName>
<References>
<Reference
ReferenceType=
"HasComponent"
>
ns=1;i=6001
</Reference>
<Reference
ReferenceType=
"HasSubtype"
IsForward=
"false"
>
i=58
</Reference>
</References>
</UAObjectType>
<UAVariable
DataType=
"Double"
ParentNodeId=
"ns=1;i=1002"
NodeId=
"ns=1;i=6001"
BrowseName=
"1:MyVariable"
UserAccessLevel=
"3"
AccessLevel=
"3"
>
<DisplayName>
MyVariable
</DisplayName>
<References>
<Reference
ReferenceType=
"HasTypeDefinition"
>
i=63
</Reference>
<Reference
ReferenceType=
"HasModellingRule"
>
i=78
</Reference>
<Reference
ReferenceType=
"HasComponent"
IsForward=
"false"
>
ns=1;i=1002
</Reference>
</References>
<Value>
<uax:Double>
0
</uax:Double>
</Value>
</UAVariable>
</UANodeSet>
examples/server-customobject.py
0 → 100644
View file @
a083a9b6
import
sys
sys
.
path
.
insert
(
0
,
".."
)
import
time
from
opcua
import
ua
,
Server
if
__name__
==
"__main__"
:
# setup our server
server
=
Server
()
server
.
set_endpoint
(
"opc.tcp://0.0.0.0:4840/freeopcua/server/"
)
# setup our own namespace, not really necessary but should as spec
uri
=
"http://examples.freeopcua.github.io"
idx
=
server
.
register_namespace
(
uri
)
# Import customobject type
server
.
import_xml
(
'customobject.xml'
)
# get Objects node, this is where we should put our custom stuff
objects
=
server
.
get_objects_node
()
# get nodeid of custom object type by :
# 1) Use node ID
# 2) Or Full path
# 3) Or As child from parent
nodeid_a
=
ua
.
NodeId
.
from_string
(
'ns=1;i=1002'
)
nodeid_b
=
server
.
get_root_node
().
get_child
([
"0:Types"
,
"0:ObjectTypes"
,
"0:BaseObjectType"
,
"1:MyObjectType"
]).
nodeid
nodeid_c
=
server
.
get_node
(
ua
.
ObjectIds
.
BaseObjectType
).
get_child
([
"1:MyObjectType"
]).
nodeid
myobject_type_nodeid
=
nodeid_a
# populating our address space
myobj
=
objects
.
add_object
(
idx
,
"MyObject"
,)
myobj
=
objects
.
add_object
(
idx
,
"MyCustomObject"
,
myobject_type_nodeid
)
# starting!
server
.
start
()
try
:
count
=
0
while
True
:
time
.
sleep
(
1
)
count
+=
0.1
myvar
.
set_value
(
count
)
finally
:
# close connection, remove subcsriptions, etc
server
.
stop
()
opcua/common/manage_nodes.py
View file @
a083a9b6
...
...
@@ -47,7 +47,24 @@ def create_object(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
.
BaseObjectType
))
objecttype
=
ua
.
ObjectIds
.
BaseObjectType
if
(
len
(
args
)
==
3
):
objecttype
=
args
[
2
]
try
:
if
isinstance
(
objecttype
,
int
):
objecttype
=
ua
.
NodeId
(
objecttype
)
elif
isinstance
(
objecttype
,
ua
.
NodeId
):
objecttype
=
objecttype
elif
isinstance
(
objecttype
,
str
):
objecttype
=
ua
.
NodeId
.
from_string
(
objecttype
)
else
:
raise
RuntimeError
()
return
nodeid
,
qname
except
ua
.
UaError
:
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
))
def
create_property
(
parent
,
*
args
):
...
...
@@ -122,7 +139,10 @@ def _create_object(server, parentnodeid, nodeid, qname, objecttype):
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
):
addnode
.
TypeDefinition
=
objecttype
attrs
=
ua
.
ObjectAttributes
()
attrs
.
EventNotifier
=
0
...
...
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