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
49c07a7d
Commit
49c07a7d
authored
Apr 25, 2016
by
Denis Štogl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inital version of implememntation
parent
49c7ea31
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
53 deletions
+81
-53
opcua/common/event.py
opcua/common/event.py
+42
-28
opcua/common/manage_nodes.py
opcua/common/manage_nodes.py
+18
-21
opcua/common/node.py
opcua/common/node.py
+4
-0
opcua/server/server.py
opcua/server/server.py
+6
-4
tests/tests_server.py
tests/tests_server.py
+11
-0
No files found.
opcua/common/event.py
View file @
49c07a7d
...
...
@@ -76,13 +76,41 @@ class EventGenerator(object):
def
get_event_from_node
(
node
):
event
=
None
if
node
.
nodeid
.
Identifier
in
ua
.
uaevents_auto
.
IMPLEMNTED_EVENTS
.
keys
():
event
=
ua
.
uaevents_auto
.
IMPLEMNTED_EVENTS
[
node
.
nodeid
.
Identifier
]()
return
ua
.
uaevents_auto
.
IMPLEMNTED_EVENTS
[
node
.
nodeid
.
Identifier
]()
else
:
pass
#node.get
parent_identifier
,
parent_eventtype
=
_find_parent_eventtype
(
node
)
if
not
parent_eventtype
:
return
None
class
CustomEvent
(
parent_eventtype
):
def
__init__
(
self
):
super
(
CustomEvent
,
self
).
__init__
()
curr_node
=
node
while
curr_node
.
nodeid
.
Identifier
!=
parent_identifier
:
properties
=
curr_node
.
get_referenced_nodes
(
refs
=
ua
.
ObjectIds
.
HasProperty
,
direction
=
ua
.
BrowseDirection
.
Forward
)
for
prop
in
properties
:
setattr
(
self
,
prop
.
get_browse_name
().
Name
,
prop
.
get_value
())
parents
=
node
.
get_referenced_nodes
(
refs
=
ua
.
ObjectIds
.
HasSubtype
,
direction
=
ua
.
BrowseDirection
.
Inverse
,
includesubtypes
=
False
)
if
len
(
parents
)
!=
1
:
# Something went wrong
return
None
curr_node
=
parents
[
0
]
#TODO: Extend to show all fields of CustomEvent
def
__str__
(
self
):
s
=
'CustomEvent('
s
+=
'EventId:{}'
.
format
(
self
.
EventId
)
s
+=
', EventType:{}'
.
format
(
self
.
EventType
)
s
+=
', SourceNode:{}'
.
format
(
self
.
SourceNode
)
s
+=
', SourceName:{}'
.
format
(
self
.
SourceName
)
s
+=
', Time:{}'
.
format
(
self
.
Time
)
s
+=
', RecieveTime:{}'
.
format
(
self
.
RecieveTime
)
s
+=
', LocalTime:{}'
.
format
(
self
.
LocalTime
)
s
+=
', Message:{}'
.
format
(
self
.
Message
)
s
+=
', Severity:{}'
.
format
(
self
.
Severity
)
s
+=
')'
#class CustomEvent():
...
...
@@ -92,29 +120,15 @@ def get_event_from_node(node):
#child = Node(self.isession, desc.NodeId)
#setattr(self.event, desc.BrowseName.Name, child.get_value())
return
event
return
CustomEvent
()
class
CustomEvent
(
ua
.
BaseEvent
):
def
__init__
(
self
,
etype
=
ua
.
BaseEvent
,
sourcenode
=
ua
.
NodeId
(
ua
.
ObjectIds
.
Server
),
message
=
None
,
severity
=
1
):
super
(
CustomEvent
,
self
).
__init__
(
sourcenode
,
message
,
severity
,
True
)
#TODO: Add fileds
def
_find_parent_eventtype
(
node
):
parents
=
node
.
get_referenced_nodes
(
refs
=
ua
.
ObjectIds
.
HasSubtype
,
direction
=
ua
.
BrowseDirection
.
Inverse
,
includesubtypes
=
False
)
#TODO: Extend to show all fields of CustomEvent
def
__str__
(
self
):
s
=
'CustomEvent('
s
+=
'EventId:{}'
.
format
(
self
.
EventId
)
s
+=
', EventType:{}'
.
format
(
self
.
EventType
)
s
+=
', SourceNode:{}'
.
format
(
self
.
SourceNode
)
s
+=
', SourceName:{}'
.
format
(
self
.
SourceName
)
s
+=
', Time:{}'
.
format
(
self
.
Time
)
s
+=
', RecieveTime:{}'
.
format
(
self
.
RecieveTime
)
s
+=
', LocalTime:{}'
.
format
(
self
.
LocalTime
)
s
+=
', Message:{}'
.
format
(
self
.
Message
)
s
+=
', Severity:{}'
.
format
(
self
.
Severity
)
s
+=
')'
return
s
__repr__
=
__str__
if
len
(
parents
)
!=
1
:
# Something went wrong
return
None
if
parents
[
0
].
nodeid
.
Identifier
in
ua
.
uaevents_auto
.
IMPLEMNTED_EVENTS
.
keys
():
return
node
.
nodeid
.
Identifier
,
ua
.
uaevents_auto
.
IMPLEMNTED_EVENTS
[
parents
[
0
].
nodeid
.
Identifier
]
else
:
_find_parent_eventtype
(
parents
[
0
])
opcua/common/manage_nodes.py
View file @
49c07a7d
...
...
@@ -94,34 +94,31 @@ def create_method(parent, *args):
return
_create_method
(
parent
,
nodeid
,
qname
,
callback
,
inputs
,
outputs
)
def
_create_folder
(
server
,
parentnodeid
,
nodeid
,
qname
):
addnode
=
ua
.
AddNodesItem
()
addnode
.
RequestedNewNodeId
=
nodeid
addnode
.
BrowseName
=
qname
addnode
.
NodeClass
=
ua
.
NodeClass
.
Object
addnode
.
ParentNodeId
=
parentnodeid
addnode
.
ReferenceTypeId
=
ua
.
NodeId
.
from_string
(
"i=35"
)
addnode
.
TypeDefinition
=
ua
.
NodeId
.
from_string
(
"i=61"
)
attrs
=
ua
.
ObjectAttributes
()
attrs
.
Description
=
ua
.
LocalizedText
(
qname
.
Name
)
attrs
.
DisplayName
=
ua
.
LocalizedText
(
qname
.
Name
)
attrs
.
WriteMask
=
0
attrs
.
UserWriteMask
=
0
attrs
.
EventNotifier
=
0
addnode
.
NodeAttributes
=
attrs
results
=
server
.
add_nodes
([
addnode
])
results
[
0
].
StatusCode
.
check
()
return
results
[
0
].
AddedNodeId
def
create_subtype
(
parent
,
*
args
):
"""
create a child node subtype
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
))
def
_create_object
(
server
,
parentnodeid
,
nodeid
,
qname
):
def
_create_object
(
server
,
parentnodeid
,
nodeid
,
qname
,
objecttype
):
addnode
=
ua
.
AddNodesItem
()
addnode
.
RequestedNewNodeId
=
nodeid
addnode
.
BrowseName
=
qname
addnode
.
NodeClass
=
ua
.
NodeClass
.
Object
addnode
.
ParentNodeId
=
parentnodeid
addnode
.
ReferenceTypeId
=
ua
.
NodeId
.
from_string
(
"i=35"
)
addnode
.
TypeDefinition
=
ua
.
NodeId
(
ua
.
ObjectIds
.
BaseObjectType
)
#TODO: maybe move to address_space.py and implement for all node types?
if
not
objecttype
:
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasSubtype
)
else
:
addnode
.
TypeDefinition
=
ua
.
NodeId
(
objecttype
)
if
node
.
Node
(
server
,
parentnodeid
).
get_type_definition
()
==
ua
.
ObjectIds
.
FolderType
:
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
Organizes
)
else
:
addnode
.
ReferenceTypeId
=
ua
.
NodeId
(
ua
.
ObjectIds
.
HasComponent
)
attrs
=
ua
.
ObjectAttributes
()
attrs
.
Description
=
ua
.
LocalizedText
(
qname
.
Name
)
attrs
.
DisplayName
=
ua
.
LocalizedText
(
qname
.
Name
)
...
...
opcua/common/node.py
View file @
49c07a7d
...
...
@@ -369,6 +369,10 @@ class Node(object):
from
opcua.common
import
manage_nodes
return
manage_nodes
.
create_method
(
*
args
,
**
kwargs
)
def
add_subtype
(
*
args
,
**
kwargs
):
from
opcua.common
import
manage_nodes
return
manage_nodes
.
create_subtype
(
*
args
,
**
kwargs
)
def
call_method
(
*
args
,
**
kwargs
):
from
opcua.common
import
methods
return
methods
.
call_method
(
*
args
,
**
kwargs
)
opcua/server/server.py
View file @
49c07a7d
...
...
@@ -329,12 +329,14 @@ class Server(object):
"""
return
EventGenerator
(
self
.
iserver
.
isession
,
etype
,
source
)
def
create_custom_event
(
self
,
name
,
baseetype
=
ua
.
ObjectIds
.
BaseEventType
,
properties
=
[]):
def
create_custom_event
(
self
,
idx
,
name
,
baseetype
=
ua
.
ObjectIds
.
BaseEventType
,
properties
=
[]):
base_event
=
self
.
get_node
(
baseetype
)
custom_event
=
base_event
.
add_
object
(
name
)
base_event
=
self
.
get_node
(
ua
.
NodeId
(
baseetype
)
)
custom_event
=
base_event
.
add_
subtype
(
idx
,
name
)
for
property
in
properties
:
custom_event
.
add_property
(
property
[
0
],
property
[
1
])
custom_event
.
add_property
(
idx
,
property
[
0
],
ua
.
Variant
(
None
,
property
[
1
]))
return
custom_event
def
import_xml
(
self
,
path
):
"""
...
...
tests/tests_server.py
View file @
49c07a7d
...
...
@@ -142,6 +142,17 @@ class TestServer(unittest.TestCase, CommonTests):
ev
=
opcua
.
common
.
event
.
get_event_from_node
(
opcua
.
Node
(
self
.
opc
.
iserver
.
isession
,
ua
.
NodeId
(
ua
.
ObjectIds
.
BaseEventType
)))
check_base_event
(
self
,
ev
)
def
test_create_custom_event
(
self
):
event
=
self
.
opc
.
create_custom_event
(
2
,
'MyEvent'
,
ua
.
ObjectIds
.
BaseEventType
,
[(
'PropertyNum'
,
ua
.
VariantType
.
Float
),
(
'PropertyString'
,
ua
.
VariantType
.
String
)])
base
=
opcua
.
Node
(
self
.
opc
.
iserver
.
isession
,
ua
.
NodeId
(
ua
.
ObjectIds
.
BaseEventType
))
self
.
assertTrue
(
event
in
base
.
get_children
())
nodes
=
event
.
get_referenced_nodes
(
refs
=
ua
.
ObjectIds
.
HasSubtype
,
direction
=
ua
.
BrowseDirection
.
Inverse
,
includesubtypes
=
False
)
self
.
assertEqual
(
base
,
nodes
[
0
])
properties
=
event
.
get_properties
()
self
.
assertIsNot
(
properties
,
None
)
def
test_get_event_from_node_CustomEvent
(
self
):
ev
=
opcua
.
common
.
event
.
get_event_from_node
(
opcua
.
Node
(
self
.
opc
.
iserver
.
isession
,
ua
.
NodeId
(
ua
.
ObjectIds
.
AuditEventType
)))
check_base_event
(
self
,
ev
)
...
...
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