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
e5fff184
Commit
e5fff184
authored
Nov 10, 2016
by
Kevin Levesque
Committed by
ORD
Nov 11, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a simple server that import an xml file and a client that calls the methods defines
parent
473476c3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
211 additions
and
0 deletions
+211
-0
examples/simple-client-server-xml/client_minimal.py
examples/simple-client-server-xml/client_minimal.py
+35
-0
examples/simple-client-server-xml/server.py
examples/simple-client-server-xml/server.py
+85
-0
examples/simple-client-server-xml/test_saying.xml
examples/simple-client-server-xml/test_saying.xml
+91
-0
No files found.
examples/simple-client-server-xml/client_minimal.py
0 → 100644
View file @
e5fff184
from
opcua
import
Client
,
ua
from
opcua.ua
import
ua_binary
as
uabin
from
opcua.common.methods
import
call_method
class
HelloClient
:
def
__init__
(
self
,
endpoint
):
self
.
client
=
Client
(
endpoint
)
def
__enter__
(
self
):
self
.
client
.
connect
()
return
self
.
client
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
self
.
client
.
disconnect
()
if
__name__
==
'__main__'
:
with
HelloClient
(
"opc.tcp://localhost:40840/freeopcua/server/"
)
as
client
:
root
=
client
.
get_root_node
()
print
(
"Root node is: "
,
root
)
objects
=
client
.
get_objects_node
()
print
(
"Objects node is: "
,
objects
)
hellower
=
objects
.
get_child
(
"0:Hellower"
)
print
(
"Hellower is: "
,
hellower
)
resulting_text
=
hellower
.
call_method
(
"0:SayHello"
,
False
)
print
(
resulting_text
)
resulting_text
=
hellower
.
call_method
(
"1:SayHello2"
,
True
)
print
(
resulting_text
)
resulting_array
=
hellower
.
call_method
(
"1:SayHelloArray"
,
False
)
print
(
resulting_array
)
examples/simple-client-server-xml/server.py
0 → 100644
View file @
e5fff184
import
os.path
try
:
from
IPython
import
embed
except
ImportError
:
import
code
def
embed
():
vars
=
globals
()
vars
.
update
(
locals
())
shell
=
code
.
InteractiveConsole
(
vars
)
shell
.
interact
()
from
opcua
import
ua
,
uamethod
,
Server
@
uamethod
def
say_hello_xml
(
parent
,
happy
):
print
(
"Calling say_hello_xml"
)
if
happy
:
result
=
"I'm happy"
else
:
result
=
"I'm not happy"
print
(
result
)
return
result
@
uamethod
def
say_hello
(
parent
,
happy
):
if
happy
:
result
=
"I'm happy"
else
:
result
=
"I'm not happy"
print
(
result
)
return
result
@
uamethod
def
say_hello_array
(
parent
,
happy
):
if
happy
:
result
=
"I'm happy"
else
:
result
=
"I'm not happy"
print
(
result
)
return
[
result
,
"Actually I am"
]
class
HelloServer
:
def
__init__
(
self
,
endpoint
,
name
,
model_filepath
):
self
.
server
=
Server
()
# This need to be imported at the start or else it will overwrite the data
self
.
server
.
import_xml
(
model_filepath
)
self
.
server
.
set_endpoint
(
endpoint
)
self
.
server
.
set_server_name
(
name
)
objects
=
self
.
server
.
get_objects_node
()
freeopcua_namespace
=
self
.
server
.
get_namespace_index
(
"urn:freeopcua:python:server"
)
hellower
=
objects
.
get_child
(
"0:Hellower"
)
hellower_say_hello
=
hellower
.
get_child
(
"0:SayHello"
)
self
.
server
.
link_method
(
hellower_say_hello
,
say_hello_xml
)
hellower
.
add_method
(
freeopcua_namespace
,
"SayHello2"
,
say_hello
,
[
ua
.
VariantType
.
Boolean
],
[
ua
.
VariantType
.
String
])
hellower
.
add_method
(
freeopcua_namespace
,
"SayHelloArray"
,
say_hello_array
,
[
ua
.
VariantType
.
Boolean
],
[
ua
.
VariantType
.
String
])
def
__enter__
(
self
):
self
.
server
.
start
()
return
self
.
server
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
self
.
server
.
stop
()
if
__name__
==
'__main__'
:
script_dir
=
os
.
path
.
dirname
(
__file__
)
with
HelloServer
(
"opc.tcp://0.0.0.0:40840/freeopcua/server/"
,
"FreeOpcUa Example Server"
,
os
.
path
.
join
(
script_dir
,
"test_saying.xml"
))
as
server
:
embed
()
examples/simple-client-server-xml/test_saying.xml
0 → 100644
View file @
e5fff184
<?xml version='1.0' encoding='utf-8'?>
<UANodeSet
xmlns=
"http://opcfoundation.org/UA/2011/03/UANodeSet.xsd"
xmlns:uax=
"http://opcfoundation.org/UA/2008/02/Types.xsd"
xmlns:xsd=
"http://www.w3.org/2001/XMLSchema"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
>
<Aliases>
<Alias
Alias=
"Organizes"
>
i=35
</Alias>
<Alias
Alias=
"HasTypeDefinition"
>
i=40
</Alias>
<Alias
Alias=
"HasProperty"
>
i=46
</Alias>
<Alias
Alias=
"HasComponent"
>
i=47
</Alias>
<Alias
Alias=
"Argument"
>
i=296
</Alias>
</Aliases>
<NamespaceUris
/>
<UAObject
BrowseName=
"0:Hellower"
NodeId=
"i=20001"
ParentNodeId=
"i=85"
>
<DisplayName>
BaseObjectType
</DisplayName>
<Description>
The base type for all object nodes.
</Description>
<References>
<Reference
IsForward=
"false"
ReferenceType=
"Organizes"
>
i=85
</Reference>
<Reference
ReferenceType=
"HasTypeDefinition"
>
i=58
</Reference>
<Reference
ReferenceType=
"HasComponent"
>
i=20002
</Reference>
</References>
</UAObject>
<UAMethod
BrowseName=
"0:SayHello"
NodeId=
"i=20002"
ParentNodeId=
"i=20001"
>
<DisplayName>
SayHello
</DisplayName>
<Description>
SayHello
</Description>
<References>
<Reference
IsForward=
"false"
ReferenceType=
"HasComponent"
>
i=20001
</Reference>
<Reference
ReferenceType=
"HasProperty"
>
i=20003
</Reference>
<Reference
ReferenceType=
"HasProperty"
>
i=20004
</Reference>
</References>
</UAMethod>
<UAVariable
BrowseName=
"0:InputArguments"
DataType=
"Argument"
NodeId=
"i=20003"
ParentNodeId=
"i=20002"
ValueRank=
"0"
>
<DisplayName>
InputArguments
</DisplayName>
<Description>
InputArguments
</Description>
<Value>
<uax:ListOfExtensionObject>
<uax:ExtensionObject>
<uax:TypeId>
<uax:Identifier>
i=296
</uax:Identifier>
</uax:TypeId>
<uax:Body>
<uax:Argument>
<uax:ValueRank>
-1
</uax:ValueRank>
<uax:Description>
<uax:Text
/>
<uax:Locale
/>
</uax:Description>
<uax:DataType>
<uax:Identifier>
i=1
</uax:Identifier>
</uax:DataType>
<uax:Name>
happy
</uax:Name>
<uax:ArrayDimensions
/>
</uax:Argument>
</uax:Body>
</uax:ExtensionObject>
</uax:ListOfExtensionObject>
</Value>
<References>
<Reference
IsForward=
"false"
ReferenceType=
"HasProperty"
>
i=20002
</Reference>
<Reference
ReferenceType=
"HasTypeDefinition"
>
i=68
</Reference>
</References>
</UAVariable>
<UAVariable
BrowseName=
"0:OutputArguments"
DataType=
"Argument"
NodeId=
"i=20004"
ParentNodeId=
"i=20002"
ValueRank=
"0"
>
<DisplayName>
OutputArguments
</DisplayName>
<Description>
OutputArguments
</Description>
<Value>
<uax:ListOfExtensionObject>
<uax:ExtensionObject>
<uax:TypeId>
<uax:Identifier>
i=296
</uax:Identifier>
</uax:TypeId>
<uax:Body>
<uax:Argument>
<uax:ValueRank>
-1
</uax:ValueRank>
<uax:Description>
<uax:Text
/>
<uax:Locale
/>
</uax:Description>
<uax:DataType>
<uax:Identifier>
i=12
</uax:Identifier>
</uax:DataType>
<uax:Name>
saying
</uax:Name>
<uax:ArrayDimensions
/>
</uax:Argument>
</uax:Body>
</uax:ExtensionObject>
</uax:ListOfExtensionObject>
</Value>
<References>
<Reference
IsForward=
"false"
ReferenceType=
"HasProperty"
>
i=20002
</Reference>
<Reference
ReferenceType=
"HasTypeDefinition"
>
i=68
</Reference>
</References>
</UAVariable>
</UANodeSet>
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