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
4fb4eaa0
Commit
4fb4eaa0
authored
Sep 03, 2016
by
olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more generic solution to parse and generate code for extension objects value
parent
3976fb13
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
494 additions
and
239 deletions
+494
-239
opcua/common/xmlparser.py
opcua/common/xmlparser.py
+37
-19
opcua/server/standard_address_space/standard_address_space_part3.py
...er/standard_address_space/standard_address_space_part3.py
+24
-0
opcua/server/standard_address_space/standard_address_space_part4.py
...er/standard_address_space/standard_address_space_part4.py
+118
-0
opcua/server/standard_address_space/standard_address_space_part5.py
...er/standard_address_space/standard_address_space_part5.py
+192
-192
opcua/server/standard_address_space/standard_address_space_part9.py
...er/standard_address_space/standard_address_space_part9.py
+36
-24
schemas/generate_address_space.py
schemas/generate_address_space.py
+11
-3
tests/custom_nodes.xml
tests/custom_nodes.xml
+76
-1
No files found.
opcua/common/xmlparser.py
View file @
4fb4eaa0
...
...
@@ -212,6 +212,7 @@ class XMLParser(object):
def
_set_attr
(
self
,
key
,
val
,
obj
):
if
key
==
"NodeId"
:
obj
.
nodeid
=
self
.
_get_node_id
(
val
)
print
(
"PARSING"
,
obj
.
nodeid
)
elif
key
==
"BrowseName"
:
obj
.
browsename
=
val
elif
key
==
"SymbolicName"
:
...
...
@@ -302,6 +303,7 @@ class XMLParser(object):
txt
=
""
for
text
in
el
.
itertext
():
txt
+=
text
txt
=
txt
.
strip
()
return
txt
def
_parse_list_of_localized_text
(
self
,
el
):
...
...
@@ -325,26 +327,42 @@ class XMLParser(object):
value
=
[]
for
extension_object_list
in
el
:
for
extension_object
in
extension_object_list
:
extension_object
.
find
(
'Body'
)
for
extension_object_part
in
extension_object
:
ext_obj
=
self
.
_parse_ext_obj
(
extension_object
)
value
.
append
(
ext_obj
)
return
value
def
_parse_ext_obj
(
self
,
el
):
ext
=
ExtObj
()
for
extension_object_part
in
el
:
ntag
=
self
.
_retag
.
match
(
extension_object_part
.
tag
).
groups
()[
1
]
if
ntag
==
'TypeId'
:
ntag
=
self
.
_retag
.
match
(
extension_object_part
.
find
(
'*'
).
tag
).
groups
()[
1
]
ext
.
typeid
=
self
.
_get_text
(
extension_object_part
)
elif
ntag
==
'Body'
:
ntag
=
self
.
_retag
.
match
(
extension_object_part
.
find
(
'*'
).
tag
).
groups
()[
1
]
ext
.
objname
=
ntag
for
body_item
in
extension_object_part
.
findall
(
'*/*'
):
ntag
=
self
.
_retag
.
match
(
body_item
.
tag
).
groups
()[
1
]
child
=
body_item
.
find
(
'*'
)
if
child
is
not
None
:
ext
.
body
[
ntag
]
=
self
.
_get_text
(
child
)
ext
.
objname
=
self
.
_retag
.
match
(
extension_object_part
.
find
(
'*'
).
tag
).
groups
()[
1
]
ext
.
body
=
self
.
_parse_body
(
extension_object_part
)
print
(
"body"
,
ext
.
body
)
else
:
ext
.
body
[
ntag
]
=
self
.
_get_text
(
body_item
)
value
.
append
(
ext
)
return
value
print
(
"Uknoen ndtag"
,
ntag
)
print
(
"ext_obj"
,
ext
.
objname
,
ext
.
typeid
,
ext
.
body
)
return
ext
def
_parse_body
(
self
,
el
):
body
=
{}
#ntag = self._retag.match(el.find('*').tag).groups()[1]
#body[ntag] = {}
for
body_item
in
el
:
otag
=
self
.
_retag
.
match
(
body_item
.
tag
).
groups
()[
1
]
childs
=
[
i
for
i
in
body_item
]
if
not
childs
:
val
=
self
.
_get_text
(
body_item
)
elif
len
(
childs
)
==
1
:
val
=
self
.
_get_text
(
childs
[
0
])
else
:
val
=
self
.
_parse_body
(
body_item
)
if
val
:
body
[
otag
]
=
val
return
body
def
_parse_refs
(
self
,
el
,
obj
):
for
ref
in
el
:
...
...
opcua/server/standard_address_space/standard_address_space_part3.py
View file @
4fb4eaa0
...
...
@@ -632,12 +632,18 @@ def create_standard_address_space_Part3(server):
value
=
[]
extobj
=
ua
.
EnumValueType
()
extobj
.
Value
=
"1"
extobj
.
DisplayName
.
Text
=
"Mandatory"
extobj
.
Description
.
Text
=
"The BrowseName must appear in all instances of the type."
value
.
append
(
extobj
)
extobj
=
ua
.
EnumValueType
()
extobj
.
Value
=
"2"
extobj
.
DisplayName
.
Text
=
"Optional"
extobj
.
Description
.
Text
=
"The BrowseName may appear in an instance of the type."
value
.
append
(
extobj
)
extobj
=
ua
.
EnumValueType
()
extobj
.
Value
=
"3"
extobj
.
DisplayName
.
Text
=
"Constraint"
extobj
.
Description
.
Text
=
"The modelling rule defines a constraint and the BrowseName is not used in an instance of the type."
value
.
append
(
extobj
)
attrs
.
Value
=
ua
.
Variant
(
value
,
ua
.
VariantType
.
ExtensionObject
)
attrs
.
ValueRank
=
1
...
...
@@ -975,30 +981,48 @@ def create_standard_address_space_Part3(server):
value
=
[]
extobj
=
ua
.
EnumValueType
()
extobj
.
Value
=
"0"
extobj
.
DisplayName
.
Text
=
"Unspecified"
extobj
.
Description
.
Text
=
"No classes are selected."
value
.
append
(
extobj
)
extobj
=
ua
.
EnumValueType
()
extobj
.
Value
=
"1"
extobj
.
DisplayName
.
Text
=
"Object"
extobj
.
Description
.
Text
=
"The node is an object."
value
.
append
(
extobj
)
extobj
=
ua
.
EnumValueType
()
extobj
.
Value
=
"2"
extobj
.
DisplayName
.
Text
=
"Variable"
extobj
.
Description
.
Text
=
"The node is a variable."
value
.
append
(
extobj
)
extobj
=
ua
.
EnumValueType
()
extobj
.
Value
=
"4"
extobj
.
DisplayName
.
Text
=
"Method"
extobj
.
Description
.
Text
=
"The node is a method."
value
.
append
(
extobj
)
extobj
=
ua
.
EnumValueType
()
extobj
.
Value
=
"8"
extobj
.
DisplayName
.
Text
=
"ObjectType"
extobj
.
Description
.
Text
=
"The node is an object type."
value
.
append
(
extobj
)
extobj
=
ua
.
EnumValueType
()
extobj
.
Value
=
"16"
extobj
.
DisplayName
.
Text
=
"VariableType"
extobj
.
Description
.
Text
=
"The node is an variable type."
value
.
append
(
extobj
)
extobj
=
ua
.
EnumValueType
()
extobj
.
Value
=
"32"
extobj
.
DisplayName
.
Text
=
"ReferenceType"
extobj
.
Description
.
Text
=
"The node is a reference type."
value
.
append
(
extobj
)
extobj
=
ua
.
EnumValueType
()
extobj
.
Value
=
"64"
extobj
.
DisplayName
.
Text
=
"DataType"
extobj
.
Description
.
Text
=
"The node is a data type."
value
.
append
(
extobj
)
extobj
=
ua
.
EnumValueType
()
extobj
.
Value
=
"128"
extobj
.
DisplayName
.
Text
=
"View"
extobj
.
Description
.
Text
=
"The node is a view."
value
.
append
(
extobj
)
attrs
.
Value
=
ua
.
Variant
(
value
,
ua
.
VariantType
.
ExtensionObject
)
attrs
.
ValueRank
=
1
...
...
opcua/server/standard_address_space/standard_address_space_part4.py
View file @
4fb4eaa0
This diff is collapsed.
Click to expand it.
opcua/server/standard_address_space/standard_address_space_part5.py
View file @
4fb4eaa0
This diff is collapsed.
Click to expand it.
opcua/server/standard_address_space/standard_address_space_part9.py
View file @
4fb4eaa0
...
...
@@ -905,14 +905,16 @@ def create_standard_address_space_Part9(server):
attrs
.
DataType
=
ua
.
NodeId
.
from_string
(
"i=296"
)
value
=
[]
extobj
=
ua
.
Argument
()
extobj
.
ValueRank
=
"-1"
extobj
.
Name
=
"EventId"
extobj
.
DataType
=
"i=15"
extobj
.
Name
=
"EventId"
extobj
.
ValueRank
=
"-1"
extobj
.
Description
.
Text
=
"The identifier for the event to comment."
value
.
append
(
extobj
)
extobj
=
ua
.
Argument
()
extobj
.
ValueRank
=
"-1"
extobj
.
Name
=
"Comment"
extobj
.
DataType
=
"i=21"
extobj
.
Name
=
"Comment"
extobj
.
ValueRank
=
"-1"
extobj
.
Description
.
Text
=
"The comment to add to the condition."
value
.
append
(
extobj
)
attrs
.
Value
=
ua
.
Variant
(
value
,
ua
.
VariantType
.
ExtensionObject
)
attrs
.
ValueRank
=
1
...
...
@@ -974,9 +976,10 @@ def create_standard_address_space_Part9(server):
attrs
.
DataType
=
ua
.
NodeId
.
from_string
(
"i=296"
)
value
=
[]
extobj
=
ua
.
Argument
()
extobj
.
ValueRank
=
"-1"
extobj
.
Name
=
"SubscriptionId"
extobj
.
DataType
=
"i=288"
extobj
.
Name
=
"SubscriptionId"
extobj
.
ValueRank
=
"-1"
extobj
.
Description
.
Text
=
"The identifier for the suscription to refresh."
value
.
append
(
extobj
)
attrs
.
Value
=
ua
.
Variant
(
value
,
ua
.
VariantType
.
ExtensionObject
)
attrs
.
ValueRank
=
1
...
...
@@ -1038,14 +1041,16 @@ def create_standard_address_space_Part9(server):
attrs
.
DataType
=
ua
.
NodeId
.
from_string
(
"i=296"
)
value
=
[]
extobj
=
ua
.
Argument
()
extobj
.
ValueRank
=
"-1"
extobj
.
Name
=
"SubscriptionId"
extobj
.
DataType
=
"i=288"
extobj
.
Name
=
"SubscriptionId"
extobj
.
ValueRank
=
"-1"
extobj
.
Description
.
Text
=
"The identifier for the suscription to refresh."
value
.
append
(
extobj
)
extobj
=
ua
.
Argument
()
extobj
.
ValueRank
=
"-1"
extobj
.
Name
=
"MonitoredItemId"
extobj
.
DataType
=
"i=288"
extobj
.
Name
=
"MonitoredItemId"
extobj
.
ValueRank
=
"-1"
extobj
.
Description
.
Text
=
"The identifier for the monitored item to refresh."
value
.
append
(
extobj
)
attrs
.
Value
=
ua
.
Variant
(
value
,
ua
.
VariantType
.
ExtensionObject
)
attrs
.
ValueRank
=
1
...
...
@@ -1465,9 +1470,10 @@ def create_standard_address_space_Part9(server):
attrs
.
DataType
=
ua
.
NodeId
.
from_string
(
"i=296"
)
value
=
[]
extobj
=
ua
.
Argument
()
extobj
.
ValueRank
=
"-1"
extobj
.
Name
=
"SelectedResponse"
extobj
.
DataType
=
"i=6"
extobj
.
Name
=
"SelectedResponse"
extobj
.
ValueRank
=
"-1"
extobj
.
Description
.
Text
=
"The response to the dialog condition."
value
.
append
(
extobj
)
attrs
.
Value
=
ua
.
Variant
(
value
,
ua
.
VariantType
.
ExtensionObject
)
attrs
.
ValueRank
=
1
...
...
@@ -1811,14 +1817,16 @@ def create_standard_address_space_Part9(server):
attrs
.
DataType
=
ua
.
NodeId
.
from_string
(
"i=296"
)
value
=
[]
extobj
=
ua
.
Argument
()
extobj
.
ValueRank
=
"-1"
extobj
.
Name
=
"EventId"
extobj
.
DataType
=
"i=15"
extobj
.
Name
=
"EventId"
extobj
.
ValueRank
=
"-1"
extobj
.
Description
.
Text
=
"The identifier for the event to comment."
value
.
append
(
extobj
)
extobj
=
ua
.
Argument
()
extobj
.
ValueRank
=
"-1"
extobj
.
Name
=
"Comment"
extobj
.
DataType
=
"i=21"
extobj
.
Name
=
"Comment"
extobj
.
ValueRank
=
"-1"
extobj
.
Description
.
Text
=
"The comment to add to the condition."
value
.
append
(
extobj
)
attrs
.
Value
=
ua
.
Variant
(
value
,
ua
.
VariantType
.
ExtensionObject
)
attrs
.
ValueRank
=
1
...
...
@@ -1880,14 +1888,16 @@ def create_standard_address_space_Part9(server):
attrs
.
DataType
=
ua
.
NodeId
.
from_string
(
"i=296"
)
value
=
[]
extobj
=
ua
.
Argument
()
extobj
.
ValueRank
=
"-1"
extobj
.
Name
=
"EventId"
extobj
.
DataType
=
"i=15"
extobj
.
Name
=
"EventId"
extobj
.
ValueRank
=
"-1"
extobj
.
Description
.
Text
=
"The identifier for the event to comment."
value
.
append
(
extobj
)
extobj
=
ua
.
Argument
()
extobj
.
ValueRank
=
"-1"
extobj
.
Name
=
"Comment"
extobj
.
DataType
=
"i=21"
extobj
.
Name
=
"Comment"
extobj
.
ValueRank
=
"-1"
extobj
.
Description
.
Text
=
"The comment to add to the condition."
value
.
append
(
extobj
)
attrs
.
Value
=
ua
.
Variant
(
value
,
ua
.
VariantType
.
ExtensionObject
)
attrs
.
ValueRank
=
1
...
...
@@ -2612,9 +2622,10 @@ def create_standard_address_space_Part9(server):
attrs
.
DataType
=
ua
.
NodeId
.
from_string
(
"i=296"
)
value
=
[]
extobj
=
ua
.
Argument
()
extobj
.
ValueRank
=
"-1"
extobj
.
Name
=
"ShelvingTime"
extobj
.
DataType
=
"i=290"
extobj
.
Name
=
"ShelvingTime"
extobj
.
ValueRank
=
"-1"
extobj
.
Description
.
Text
=
"If not 0, this parameter specifies a fixed time for which the Alarm is to be shelved."
value
.
append
(
extobj
)
attrs
.
Value
=
ua
.
Variant
(
value
,
ua
.
VariantType
.
ExtensionObject
)
attrs
.
ValueRank
=
1
...
...
@@ -3477,9 +3488,10 @@ def create_standard_address_space_Part9(server):
attrs
.
DataType
=
ua
.
NodeId
.
from_string
(
"i=296"
)
value
=
[]
extobj
=
ua
.
Argument
()
extobj
.
ValueRank
=
"-1"
extobj
.
Name
=
"ShelvingTime"
extobj
.
DataType
=
"i=290"
extobj
.
Name
=
"ShelvingTime"
extobj
.
ValueRank
=
"-1"
extobj
.
Description
.
Text
=
"If not 0, this parameter specifies a fixed time for which the Alarm is to be shelved."
value
.
append
(
extobj
)
attrs
.
Value
=
ua
.
Variant
(
value
,
ua
.
VariantType
.
ExtensionObject
)
attrs
.
ValueRank
=
1
...
...
schemas/generate_address_space.py
View file @
4fb4eaa0
...
...
@@ -137,11 +137,19 @@ def create_standard_address_space_%s(server):
self
.
writecode
(
indent
,
'attrs.ArrayDimensions = {}'
.
format
(
obj
.
dimensions
))
def
make_ext_obj_code
(
self
,
indent
,
extobj
):
print
(
"makeing code for "
,
extobj
.
objname
)
self
.
writecode
(
indent
,
'extobj = ua.{}()'
.
format
(
extobj
.
objname
))
for
name
,
val
in
extobj
.
body
.
items
():
val
=
val
.
strip
()
if
val
not
in
(
None
,
""
):
self
.
writecode
(
indent
,
'extobj.{} = "{}"'
.
format
(
name
,
val
))
if
type
(
val
)
is
str
:
raise
Exception
(
"Error val should a dict"
,
name
,
val
)
#self.writecode(indent, 'extobj.{} = "{}"'.format(name, val))
else
:
for
k
,
v
in
val
.
items
():
if
type
(
v
)
is
str
:
self
.
writecode
(
indent
,
'extobj.{} = "{}"'
.
format
(
k
,
v
))
else
:
for
k2
,
v2
in
v
.
items
():
self
.
writecode
(
indent
,
'extobj.{}.{} = "{}"'
.
format
(
k
,
k2
,
v2
))
def
make_variable_code
(
self
,
obj
):
indent
=
" "
...
...
tests/custom_nodes.xml
View file @
4fb4eaa0
...
...
@@ -122,7 +122,7 @@
</Definition>
</UADataType>
<UAVariable
DataType=
"EnumValueType"
ParentNodeId=
"
ns=1;i=3011"
ValueRank=
"1"
NodeId=
"ns=1;i=6
002"
ArrayDimensions=
"3"
BrowseName=
"EnumValues"
>
<UAVariable
DataType=
"EnumValueType"
ParentNodeId=
"
i=120"
ValueRank=
"1"
NodeId=
"ns=1;i=99
002"
ArrayDimensions=
"3"
BrowseName=
"EnumValues"
>
<DisplayName>
EnumValues
</DisplayName>
<References>
<Reference
ReferenceType=
"HasModellingRule"
>
i=78
</Reference>
...
...
@@ -177,6 +177,81 @@
</Value>
</UAVariable>
<!-- Test the other xml format-->
<UAVariable
NodeId=
"i=99003"
BrowseName=
"EnumValues"
ParentNodeId=
"i=120"
DataType=
"i=7594"
ValueRank=
"1"
>
<DisplayName>
EnumValues
</DisplayName>
<References>
<Reference
ReferenceType=
"HasTypeDefinition"
>
i=68
</Reference>
<Reference
ReferenceType=
"HasModellingRule"
>
i=78
</Reference>
<Reference
ReferenceType=
"HasProperty"
IsForward=
"false"
>
i=120
</Reference>
</References>
<Value>
<ListOfExtensionObject
xmlns=
"http://opcfoundation.org/UA/2008/02/Types.xsd"
>
<ExtensionObject>
<TypeId>
<Identifier>
i=7616
</Identifier>
</TypeId>
<Body>
<EnumValueType>
<Value>
1
</Value>
<DisplayName>
<Locale>
</Locale>
<Text>
Mandatory
</Text>
</DisplayName>
<Description>
<Locale>
</Locale>
<Text>
The BrowseName must appear in all instances of the type.
</Text>
</Description>
</EnumValueType>
</Body>
</ExtensionObject>
<ExtensionObject>
<TypeId>
<Identifier>
i=7616
</Identifier>
</TypeId>
<Body>
<EnumValueType>
<Value>
2
</Value>
<DisplayName>
<Locale>
</Locale>
<Text>
Optional
</Text>
</DisplayName>
<Description>
<Locale>
</Locale>
<Text>
The BrowseName may appear in an instance of the type.
</Text>
</Description>
</EnumValueType>
</Body>
</ExtensionObject>
<ExtensionObject>
<TypeId>
<Identifier>
i=7616
</Identifier>
</TypeId>
<Body>
<EnumValueType>
<Value>
3
</Value>
<DisplayName>
<Locale>
</Locale>
<Text>
Constraint
</Text>
</DisplayName>
<Description>
<Locale>
</Locale>
<Text>
The modelling rule defines a constraint and the BrowseName is not used in an instance of the type.
</Text>
</Description>
</EnumValueType>
</Body>
</ExtensionObject>
</ListOfExtensionObject>
</Value>
</UAVariable>
<!-- test data Object with Method and MethodArguments -->
<UAObjectType
NodeId=
"ns=1;i=1050"
BrowseName=
"1:MyObjectType"
>
<DisplayName>
MyObjectType
</DisplayName>
...
...
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