mirror of
https://github.com/FreeOpcUa/opcua-asyncio
synced 2025-10-29 17:07:18 +08:00
some doc update
This commit is contained in:
79
README.md
79
README.md
@@ -5,7 +5,7 @@ http://freeopcua.github.io/, https://github.com/FreeOpcUa/python-opcua
|
||||
[](https://scrutinizer-ci.com/g/FreeOpcUa/python-opcua/?branch=master)
|
||||
[](https://scrutinizer-ci.com/g/FreeOpcUa/python-opcua/?branch=master)
|
||||
|
||||
OPC-UA implementation is quasi complete and has been tested against many different applications. API offers both a low level interface to send and receive all UA defined structures and high level classes allowing to write a server or a client in a few lines. It is easy to mix high level objects and low level UA calls in one application.
|
||||
OPC-UA implementation is quasi complete and has been tested against many different OPC-UA stacks. API offers both a low level interface to send and receive all UA defined structures and high level classes allowing to write a server or a client in a few lines. It is easy to mix high level objects and low level UA calls in one application.
|
||||
|
||||
Most code is autogenerated from xml specification using same code as the one that is used for freeopcua C++ client and server, thus adding missing functionnality to client and server shoud be trivial.
|
||||
|
||||
@@ -19,6 +19,9 @@ A simple GUI client is available: https://github.com/FreeOpcUa/opcua-client-gui
|
||||
|
||||
Examples: https://github.com/FreeOpcUa/python-opcua/tree/master/examples
|
||||
|
||||
Minimal client example: https://github.com/FreeOpcUa/python-opcua/tree/master/examples/minimal-client.py
|
||||
Minimal server example: https://github.com/FreeOpcUa/python-opcua/tree/master/examples/minimal-server.py
|
||||
|
||||
A set of command line tools also available: https://github.com/FreeOpcUa/python-opcua/tree/master/tools
|
||||
* uadiscover (find_servers, get_endpoints and find_servers_on_network calls)
|
||||
* uals (list children of a node)
|
||||
@@ -27,6 +30,10 @@ A set of command line tools also available: https://github.com/FreeOpcUa/python-
|
||||
* uawrite (write attribute of a node)
|
||||
* uasubscribe (subscribe to a node and print datachange events)
|
||||
* uaclient (connect to server and start python shell)
|
||||
* uaserver (starts a demo OPC-UA server)
|
||||
|
||||
tools/uaserver --populate --certificate cert.pem --private_key pk.pem
|
||||
|
||||
|
||||
Client: what works:
|
||||
* connection to server, opening channel, session
|
||||
@@ -44,7 +51,6 @@ Client: what works:
|
||||
|
||||
Tested servers: freeopcua C++, freeopcua Python, prosys, kepware, beckoff
|
||||
|
||||
|
||||
Client: what is not implemented yet
|
||||
* localized text feature
|
||||
* removing nodes
|
||||
@@ -72,71 +78,20 @@ Server: what is not implemented
|
||||
* removing nodes
|
||||
* adding some missing modify methods
|
||||
|
||||
Example minimal client code:
|
||||
|
||||
```
|
||||
from opcua import ua, Client
|
||||
|
||||
class SubHandler(object):
|
||||
def data_change(self, handle, node, val, attr):
|
||||
print("Python: New data change event", handle, node, val, attr)
|
||||
|
||||
def event(self, handle, event):
|
||||
print("Python: New event", handle, event)
|
||||
|
||||
if __name__ == "__main__":
|
||||
client = Client("opc.tcp://localhost:4841/freeopcua/server/")
|
||||
client.connect()
|
||||
|
||||
root = client.get_root_node()
|
||||
|
||||
#getting a variable by path and setting its value attribute
|
||||
myvar = root.get_child(["0:Objects", "2:NewObject", "2:MyVariable"])
|
||||
var.set_value(ua.Variant([23], ua.VariantType.Int64))
|
||||
|
||||
#subscribing to data change event to our variable
|
||||
handler = SubHandler()
|
||||
sub = client.create_subscription(500, handler)
|
||||
sub.subscribe_data_change(myvar)
|
||||
|
||||
time.sleep(100)
|
||||
|
||||
client.disconnect()
|
||||
```
|
||||
|
||||
Example minimal server code:
|
||||
|
||||
```
|
||||
from opcua import ua, Server, ObjectIds
|
||||
|
||||
server = Server()
|
||||
|
||||
server.set_endpoint("opc.tcp://localhost:4841/freeopcua/server/")
|
||||
server.set_server_name("FreeOpcUa Example Server")
|
||||
uri = "http://examples.freeopcua.github.io"
|
||||
idx = server.register_namespace(uri)
|
||||
objects = server.get_objects_node()
|
||||
myfolder = objects.add_folder(idx, "myfolder")
|
||||
myvar = myfolder.add_variable(idx, "myvar", 6.7)
|
||||
|
||||
# creating an event object
|
||||
myevent = server.get_event_object(ObjectIds.BaseEventType)
|
||||
myevent.Message.Text = "This is my event"
|
||||
myevent.Severity = 300
|
||||
|
||||
server.start()
|
||||
myevent.trigger()
|
||||
...
|
||||
```
|
||||
|
||||
or starting a server using command line and supporting encryption:
|
||||
|
||||
tools/uaserver --populate --certificate cert.pem --private_key pk.pem
|
||||
|
||||
# Development
|
||||
|
||||
Code follows PEP8 apart for line lengths and autogenerate class and enums that keep camel case from XML definition.
|
||||
|
||||
All code is under opcua directory
|
||||
|
||||
- ua contains all UA structures from specification
|
||||
- common contains high level objects and methods used both in server and client
|
||||
- client contains client specific code
|
||||
- server contains server specific code
|
||||
- utils contains some utilities not really related to OPC-UA
|
||||
- tools contains command lines tools
|
||||
|
||||
## Running tests:
|
||||
|
||||
python tests.py
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
OPC-UA Client Class
|
||||
=========================================
|
||||
|
||||
.. autoclass:: opcua.Client
|
||||
.. autoclass:: opcua.client.client.Client
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
.. autoclass:: opcua.BinaryClient
|
||||
.. autoclass:: opcua.client.binary_client.BinaryClient
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
Python OPC-UA Documentation
|
||||
=========================================
|
||||
|
||||
Directory structure:
|
||||
|
||||
Contents:
|
||||
|
||||
.. toctree::
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
High level Functions and Node Class
|
||||
=========================================
|
||||
|
||||
.. automodule:: opcua.node
|
||||
.. automodule:: opcua.common.node
|
||||
:member-order: bysource
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
@@ -2,21 +2,25 @@
|
||||
OPC-UA Server Class
|
||||
=========================================
|
||||
|
||||
.. autoclass:: opcua.Server
|
||||
.. autoclass:: opcua.server.server.Server
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
.. autoattribute:
|
||||
|
||||
.. autoclass:: opcua.internal_server.InternalServer
|
||||
.. autoclass:: opcua.server.internal_server.InternalServer
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
.. autoclass:: opcua.binary_server_asyncio.BinaryServer
|
||||
.. autoclass:: opcua.server.internal_server.InternalSession
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
.. autoclass:: opcua.binary_server.BinaryServer
|
||||
.. autoclass:: opcua.server.binary_server_asyncio.BinaryServer
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
.. autoclass:: opcua.server.binary_server.BinaryServer
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Subscription Class
|
||||
=========================================
|
||||
|
||||
.. autoclass:: opcua.Subscription
|
||||
.. autoclass:: opcua.common.subscription.Subscription
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
@@ -4,14 +4,13 @@ UA Structures and Enums
|
||||
|
||||
All the structures and enums are to be found under opcua.ua
|
||||
|
||||
.. automodule:: opcua.uatypes
|
||||
.. automodule:: opcua.ua.uatypes
|
||||
:members:
|
||||
|
||||
|
||||
.. automodule:: opcua.uaprotocol_hand
|
||||
.. automodule:: opcua.ua.uaprotocol_hand
|
||||
:members:
|
||||
|
||||
.. automodule:: opcua.uaprotocol_auto
|
||||
.. automodule:: opcua.ua.uaprotocol_auto
|
||||
:members:
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user