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
9e8dd5a5
Commit
9e8dd5a5
authored
Jun 20, 2023
by
lennart
Committed by
oroulet
Jun 23, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sample on instantiating objects from imported nodesets into a server
parent
514bed45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
examples/server-woodworking.py
examples/server-woodworking.py
+72
-0
No files found.
examples/server-woodworking.py
0 → 100644
View file @
9e8dd5a5
# Sample on instantiating objects from imported nodesets into a server
import
os.path
import
asyncio
import
logging
import
random
from
asyncua
import
ua
,
Server
from
asyncua.common.instantiate_util
import
instantiate
class
HelloServer
:
def
__init__
(
self
,
endpoint
,
name
,
model_filepath
):
self
.
server
=
Server
()
self
.
model_filepath
=
model_filepath
self
.
server
.
set_server_name
(
name
)
self
.
server
.
set_endpoint
(
endpoint
)
async
def
init
(
self
):
await
self
.
server
.
init
()
# This need to be imported at the start or else it will overwrite the data
await
self
.
server
.
import_xml
(
os
.
path
.
join
(
self
.
model_filepath
,
"../nodeset/DI/Opc.Ua.Di.NodeSet2.xml"
))
await
self
.
server
.
import_xml
(
os
.
path
.
join
(
self
.
model_filepath
,
"../nodeset/Machinery/Opc.Ua.Machinery.NodeSet2.xml"
))
await
self
.
server
.
import_xml
(
os
.
path
.
join
(
self
.
model_filepath
,
"../nodeset/Woodworking/Opc.Ua.Woodworking.NodeSet2.xml"
))
# instantiate mandatory objects in server
self
.
device
=
await
instantiate
(
await
self
.
server
.
nodes
.
objects
.
get_child
(
'3:Machines'
),
await
self
.
server
.
nodes
.
base_object_type
.
get_child
(
'4:WwMachineType'
),
bname
=
'test_Server_OPC_UA'
,
dname
=
ua
.
LocalizedText
(
'Planing Machine'
),
idx
=
4
,
instantiate_optional
=
False
)
# write values to mandatory nodes
await
self
.
server
.
get_node
(
'ns=4;i=7821'
).
write_value
(
'ProfilingMachine'
)
#DeviceClass
await
self
.
server
.
get_node
(
'ns=4;i=7822'
).
write_value
(
ua
.
LocalizedText
(
"Manufacturer Name"
,
"de_CH"
))
#Manufacturer
await
self
.
server
.
get_node
(
'ns=4;i=7823'
).
write_value
(
ua
.
LocalizedText
(
"Machine Model"
,
"de_CH"
))
#Model
await
self
.
server
.
get_node
(
'ns=4;i=7824'
).
write_value
(
'Product_Instance_Uri'
)
#ProductInstanceUri
await
self
.
server
.
get_node
(
'ns=4;i=7825'
).
write_value
(
'422111516848641789'
)
#SerialNumber
await
self
.
server
.
get_node
(
'ns=4;i=7826'
).
write_value
(
ua
.
Variant
(
1972
,
ua
.
VariantType
.
UInt16
))
#YearOfConstruction
async
def
__aenter__
(
self
):
await
self
.
init
()
await
self
.
server
.
start
()
return
self
.
server
async
def
__aexit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
await
self
.
server
.
stop
()
async
def
main
():
script_dir
=
os
.
path
.
dirname
(
__file__
)
async
with
HelloServer
(
"opc.tcp://0.0.0.0:4840"
,
"FreeOpcUa Example Server"
,
script_dir
,
)
as
server
:
while
True
:
await
asyncio
.
sleep
(
1
)
a
,
b
=
random
.
randint
(
0
,
5
),
random
.
randint
(
0
,
4
)
# Update variables
await
server
.
get_node
(
'ns=4;i=7830'
).
write_value
(
a
)
#CurrentMode
await
server
.
get_node
(
'ns=4;i=7831'
).
write_value
(
b
)
#CurrentState
await
asyncio
.
sleep
(
5
)
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
asyncio
.
run
(
main
())
\ No newline at end of file
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