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
13198d46
Commit
13198d46
authored
May 02, 2019
by
Christian Bergmiller
Committed by
oroulet
May 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs, typings, cleanup
parent
a3f0d308
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
31 deletions
+34
-31
asyncua/server/address_space.py
asyncua/server/address_space.py
+29
-25
asyncua/server/internal_subscription.py
asyncua/server/internal_subscription.py
+2
-1
asyncua/server/monitored_item_service.py
asyncua/server/monitored_item_service.py
+3
-5
No files found.
asyncua/server/address_space.py
View file @
13198d46
...
...
@@ -18,12 +18,12 @@ class AttributeValue(object):
self
.
datachange_callbacks
=
{}
def
__str__
(
self
):
return
"AttributeValue({0})"
.
format
(
self
.
value
)
return
f"AttributeValue(
{
self
.
value
}
)"
__repr__
=
__str__
class
NodeData
(
object
)
:
class
NodeData
:
def
__init__
(
self
,
nodeid
):
self
.
nodeid
=
nodeid
...
...
@@ -32,16 +32,16 @@ class NodeData(object):
self
.
call
=
None
def
__str__
(
self
):
return
"NodeData(id:{0}, attrs:{1}, refs:{2})"
.
format
(
self
.
nodeid
,
self
.
attributes
,
self
.
references
)
return
f"NodeData(id:
{
self
.
nodeid
}
, attrs:
{
self
.
attributes
}
, refs:
{
self
.
references
}
)"
__repr__
=
__str__
class
AttributeService
(
object
)
:
class
AttributeService
:
def
__init__
(
self
,
aspace
):
def
__init__
(
self
,
aspace
:
"AddressSpace"
):
self
.
logger
=
logging
.
getLogger
(
__name__
)
self
.
_aspace
=
aspace
self
.
_aspace
:
"AddressSpace"
=
aspace
def
read
(
self
,
params
):
self
.
logger
.
debug
(
"read %s"
,
params
)
...
...
@@ -60,8 +60,9 @@ class AttributeService(object):
continue
al
=
self
.
_aspace
.
get_attribute_value
(
writevalue
.
NodeId
,
ua
.
AttributeIds
.
AccessLevel
)
ual
=
self
.
_aspace
.
get_attribute_value
(
writevalue
.
NodeId
,
ua
.
AttributeIds
.
UserAccessLevel
)
if
not
al
.
StatusCode
.
is_good
()
or
not
ua
.
ua_binary
.
test_bit
(
al
.
Value
.
Value
,
ua
.
AccessLevel
.
CurrentWrite
)
or
not
ua
.
ua_binary
.
test_bit
(
ual
.
Value
.
Value
,
ua
.
AccessLevel
.
CurrentWrite
):
if
not
al
.
StatusCode
.
is_good
()
or
not
ua
.
ua_binary
.
test_bit
(
al
.
Value
.
Value
,
ua
.
AccessLevel
.
CurrentWrite
)
or
not
ua
.
ua_binary
.
test_bit
(
ual
.
Value
.
Value
,
ua
.
AccessLevel
.
CurrentWrite
):
res
.
append
(
ua
.
StatusCode
(
ua
.
StatusCodes
.
BadUserAccessDenied
))
continue
res
.
append
(
self
.
_aspace
.
set_attribute_value
(
writevalue
.
NodeId
,
writevalue
.
AttributeId
,
writevalue
.
Value
))
...
...
@@ -70,9 +71,9 @@ class AttributeService(object):
class
ViewService
(
object
):
def
__init__
(
self
,
aspace
):
def
__init__
(
self
,
aspace
:
"AddressSpace"
):
self
.
logger
=
logging
.
getLogger
(
__name__
)
self
.
_aspace
=
aspace
self
.
_aspace
:
"AddressSpace"
=
aspace
def
browse
(
self
,
params
):
self
.
logger
.
debug
(
"browse %s"
,
params
)
...
...
@@ -177,11 +178,11 @@ class ViewService(object):
return
None
class
NodeManagementService
(
object
)
:
class
NodeManagementService
:
def
__init__
(
self
,
aspace
):
def
__init__
(
self
,
aspace
:
"AddressSpace"
):
self
.
logger
=
logging
.
getLogger
(
__name__
)
self
.
_aspace
=
aspace
self
.
_aspace
:
"AddressSpace"
=
aspace
def
add_nodes
(
self
,
addnodeitems
,
user
=
User
.
Admin
):
results
=
[]
...
...
@@ -216,8 +217,8 @@ class NodeManagementService(object):
return
result
if
item
.
ParentNodeId
.
is_null
():
#self.logger.info("add_node: while adding node %s, requested parent node is null %s %s",
#
item.RequestedNewNodeId, item.ParentNodeId, item.ParentNodeId.is_null())
#
self.logger.info("add_node: while adding node %s, requested parent node is null %s %s",
#
item.RequestedNewNodeId, item.ParentNodeId, item.ParentNodeId.is_null())
if
check
:
result
.
StatusCode
=
ua
.
StatusCode
(
ua
.
StatusCodes
.
BadParentNodeIdInvalid
)
return
result
...
...
@@ -366,7 +367,8 @@ class NodeManagementService(object):
rdesc
.
IsForward
=
addref
.
IsForward
rdesc
.
NodeId
=
addref
.
TargetNodeId
if
addref
.
TargetNodeClass
==
ua
.
NodeClass
.
Unspecified
:
rdesc
.
NodeClass
=
self
.
_aspace
.
get_attribute_value
(
addref
.
TargetNodeId
,
ua
.
AttributeIds
.
NodeClass
).
Value
.
Value
rdesc
.
NodeClass
=
self
.
_aspace
.
get_attribute_value
(
addref
.
TargetNodeId
,
ua
.
AttributeIds
.
NodeClass
).
Value
.
Value
else
:
rdesc
.
NodeClass
=
addref
.
TargetNodeClass
bname
=
self
.
_aspace
.
get_attribute_value
(
addref
.
TargetNodeId
,
ua
.
AttributeIds
.
BrowseName
).
Value
.
Value
...
...
@@ -443,11 +445,11 @@ class NodeManagementService(object):
self
.
_add_node_attr
(
item
,
nodedata
,
"Value"
,
add_timestamps
=
add_timestamps
)
class
MethodService
(
object
)
:
class
MethodService
:
def
__init__
(
self
,
aspace
):
def
__init__
(
self
,
aspace
:
"AddressSpace"
):
self
.
logger
=
logging
.
getLogger
(
__name__
)
self
.
_aspace
=
aspace
self
.
_aspace
:
"AddressSpace"
=
aspace
async
def
call
(
self
,
methods
):
results
=
[]
...
...
@@ -480,10 +482,9 @@ class MethodService(object):
return
res
class
AddressSpace
(
object
)
:
class
AddressSpace
:
"""
The address space object stores all the nodes of the OPC-UA server
and helper methods.
The address space object stores all the nodes of the OPC-UA server and helper methods.
The methods are thread safe
"""
...
...
@@ -517,9 +518,12 @@ class AddressSpace(object):
self
.
_nodeid_counter
[
idx
]
+=
1
else
:
# get the biggest identifier number from the existed nodes in address space
identifier_list
=
sorted
([
nodeid
.
Identifier
for
nodeid
in
self
.
_nodes
.
keys
()
if
nodeid
.
NamespaceIndex
==
idx
and
nodeid
.
NodeIdType
in
(
ua
.
NodeIdType
.
Numeric
,
ua
.
NodeIdType
.
TwoByte
,
ua
.
NodeIdType
.
FourByte
)])
identifier_list
=
sorted
([
nodeid
.
Identifier
for
nodeid
in
self
.
_nodes
.
keys
()
if
nodeid
.
NamespaceIndex
==
idx
and
nodeid
.
NodeIdType
in
(
ua
.
NodeIdType
.
Numeric
,
ua
.
NodeIdType
.
TwoByte
,
ua
.
NodeIdType
.
FourByte
)
])
if
identifier_list
:
self
.
_nodeid_counter
[
idx
]
=
identifier_list
[
-
1
]
else
:
...
...
asyncua/server/internal_subscription.py
View file @
13198d46
...
...
@@ -52,6 +52,7 @@ class InternalSubscription:
self
.
publish_results
()
async
def
_subscription_loop
(
self
):
"""Publication cycle."""
try
:
while
True
:
await
asyncio
.
sleep
(
self
.
data
.
RevisedPublishingInterval
/
1000.0
)
...
...
@@ -60,7 +61,7 @@ class InternalSubscription:
self
.
logger
.
info
(
'exiting _subscription_loop for %s'
,
self
.
data
.
SubscriptionId
)
pass
except
Exception
:
# seems this except is necessary to
print
errors
# seems this except is necessary to
log
errors
self
.
logger
.
exception
(
"Exception in subscription loop"
)
def
has_published_results
(
self
):
...
...
asyncua/server/monitored_item_service.py
View file @
13198d46
...
...
@@ -4,6 +4,7 @@ server side implementation of a subscription object
import
logging
from
asyncua
import
ua
from
.address_space
import
AddressSpace
class
MonitoredItemData
:
...
...
@@ -39,10 +40,10 @@ class MonitoredItemService:
Implements monitored item service for one subscription
"""
def
__init__
(
self
,
isub
,
aspace
):
def
__init__
(
self
,
isub
,
aspace
:
AddressSpace
):
self
.
logger
=
logging
.
getLogger
(
f"
{
__name__
}
.
{
isub
.
data
.
SubscriptionId
}
"
)
self
.
isub
=
isub
self
.
aspace
=
aspace
self
.
aspace
:
AddressSpace
=
aspace
self
.
_monitored_items
=
{}
self
.
_monitored_events
=
{}
self
.
_monitored_datachange
=
{}
...
...
@@ -57,7 +58,6 @@ class MonitoredItemService:
async
def
create_monitored_items
(
self
,
params
):
results
=
[]
for
item
in
params
.
ItemsToCreate
:
# with self._lock:
if
item
.
ItemToMonitor
.
AttributeId
==
ua
.
AttributeIds
.
EventNotifier
:
result
=
self
.
_create_events_monitored_item
(
item
)
else
:
...
...
@@ -102,14 +102,12 @@ class MonitoredItemService:
self
.
_monitored_item_counter
+=
1
result
.
MonitoredItemId
=
self
.
_monitored_item_counter
self
.
logger
.
debug
(
"Creating MonitoredItem with id %s"
,
result
.
MonitoredItemId
)
mdata
=
MonitoredItemData
()
mdata
.
mode
=
params
.
MonitoringMode
mdata
.
client_handle
=
params
.
RequestedParameters
.
ClientHandle
mdata
.
monitored_item_id
=
result
.
MonitoredItemId
mdata
.
queue_size
=
params
.
RequestedParameters
.
QueueSize
mdata
.
filter
=
params
.
RequestedParameters
.
Filter
return
result
,
mdata
def
_create_events_monitored_item
(
self
,
params
):
...
...
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