Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
osie
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
0
Merge Requests
0
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
Martin Manchev
osie
Commits
2d48c8aa
Commit
2d48c8aa
authored
Aug 03, 2023
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify.
parent
86a59abf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
25 deletions
+21
-25
opcua-to-http-gw/opcua-to-http-gw.py
opcua-to-http-gw/opcua-to-http-gw.py
+21
-25
No files found.
opcua-to-http-gw/opcua-to-http-gw.py
View file @
2d48c8aa
...
@@ -14,9 +14,7 @@ import argparse
...
@@ -14,9 +14,7 @@ import argparse
import
logging
import
logging
import
__main__
import
__main__
# #################################
# command line handling
# Configure
# XXX: addn erp5_username and erp5_password!
parser
=
argparse
.
ArgumentParser
(
description
=
'Run OPCUA Server.'
)
parser
=
argparse
.
ArgumentParser
(
description
=
'Run OPCUA Server.'
)
a
=
parser
.
add_argument
a
=
parser
.
add_argument
a
(
'--ip'
,
help
=
'The IP address on which the OPCUA Server runs'
,
default
=
"127.0.0.1"
)
a
(
'--ip'
,
help
=
'The IP address on which the OPCUA Server runs'
,
default
=
"127.0.0.1"
)
...
@@ -34,6 +32,7 @@ erp5_username = args.erp5_username
...
@@ -34,6 +32,7 @@ erp5_username = args.erp5_username
erp5_password
=
args
.
erp5_password
erp5_password
=
args
.
erp5_password
ERP5_REQUEST_API
=
"ERP5Site_handleOPCUARequest"
ERP5_REQUEST_API
=
"ERP5Site_handleOPCUARequest"
# ERP5 backend storage for OPCUA Document
@
dataclass
(
frozen
=
True
)
@
dataclass
(
frozen
=
True
)
class
ERP5Handler
(
asyncua
.
common
.
subscription
.
SubHandler
):
class
ERP5Handler
(
asyncua
.
common
.
subscription
.
SubHandler
):
url
:
str
url
:
str
...
@@ -58,16 +57,15 @@ class ERP5Handler(asyncua.common.subscription.SubHandler):
...
@@ -58,16 +57,15 @@ class ERP5Handler(asyncua.common.subscription.SubHandler):
def
event_notification
(
self
,
event
):
def
event_notification
(
self
,
event
):
self
.
call
(
event
=
event
)
self
.
call
(
event
=
event
)
erp5_handler
=
None
# init main ERP5 storage
if
erp5_url
is
not
None
:
erp5_handler
=
ERP5Handler
(
erp5_url
)
erp5_handler
=
ERP5Handler
(
erp5_url
)
class
InternalSession
(
asyncua
.
server
.
internal_session
.
InternalSession
):
class
InternalSession
(
asyncua
.
server
.
internal_session
.
InternalSession
):
async
def
read
(
self
,
params
):
erp5_handler
.
call
(
params
=
params
)
async
def
read
(
self
,
params
):
return
await
super
().
read
(
params
)
erp5_handler
.
call
(
params
=
params
)
return
await
super
().
read
(
params
)
# #################################
# Start OPCUA Server
# Start OPCUA Server
async
def
main
():
async
def
main
():
_logger
=
logging
.
getLogger
(
__name__
)
_logger
=
logging
.
getLogger
(
__name__
)
...
@@ -80,7 +78,6 @@ async def main():
...
@@ -80,7 +78,6 @@ async def main():
if
xml
is
not
None
:
if
xml
is
not
None
:
await
server
.
import_xml
(
xml
)
await
server
.
import_xml
(
xml
)
# read previous state as saved in ERP5 backend
# read previous state as saved in ERP5 backend
erp5_json
=
erp5_handler
.
call
(
http_method
=
"GET"
).
json
()
erp5_json
=
erp5_handler
.
call
(
http_method
=
"GET"
).
json
()
_logger
.
error
(
erp5_json
)
_logger
.
error
(
erp5_json
)
...
@@ -91,22 +88,21 @@ async def main():
...
@@ -91,22 +88,21 @@ async def main():
# XXX: this leads to a change notification which calls ERP5 and endless loop!
# XXX: this leads to a change notification which calls ERP5 and endless loop!
#await node.write_value(v)
#await node.write_value(v)
if
erp5_handler
:
subscription
=
await
server
.
create_subscription
(
1000
,
erp5_handler
)
subscription
=
await
server
.
create_subscription
(
1000
,
erp5_handler
)
await
subscription
.
subscribe_events
()
await
subscription
.
subscribe_events
()
nodes
=
await
asyncua
.
common
.
ua_utils
.
get_nodes_of_namespace
(
server
)
nodes
=
await
asyncua
.
common
.
ua_utils
.
get_nodes_of_namespace
(
server
)
await
subscription
.
subscribe_data_change
(
nodes
)
await
subscription
.
subscribe_data_change
(
nodes
)
def
create_session
(
name
,
def
create_session
(
name
,
user
=
asyncua
.
server
.
users
.
User
(
role
=
asyncua
.
server
.
users
.
UserRole
.
Anonymous
),
user
=
asyncua
.
server
.
users
.
User
(
role
=
asyncua
.
server
.
users
.
UserRole
.
Anonymous
),
external
=
False
):
external
=
False
):
self
=
server
.
iserver
self
=
server
.
iserver
return
InternalSession
(
self
,
self
.
aspace
,
self
.
subscription_service
,
name
,
user
=
user
,
external
=
external
)
return
InternalSession
(
self
,
self
.
aspace
,
self
.
subscription_service
,
name
,
user
=
user
,
external
=
external
)
server
.
iserver
.
create_session
=
create_session
server
.
iserver
.
create_session
=
create_session
_logger
.
info
(
"Added subscription for erp5 handler."
)
_logger
.
info
(
"Starting server!"
)
# start OPCUA server
_logger
.
info
(
"Starting server!"
)
async
with
server
:
async
with
server
:
while
True
:
while
True
:
await
asyncio
.
sleep
(
1
)
await
asyncio
.
sleep
(
1
)
...
...
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