Pure Python OPC-UA client library
Project description
Pure Python OPC-UA Client (and maybe server later)
API is or will be the same as the python bindings of freeopcua c++ client
Most code is autogenerated from xml specification using same code as the one that is goind to be used for freeopcua C++ client and server
what works:
* connection to server, opening channel, session
* browsing and reading attributes value
* gettings nodes by path and nodeids
* creating subscriptions
* subscribing to items for data change
what is not implemented yet (but is trivial to implement):
* subscribing to events
* subscribing to status change
* adding all modify methods
what is not implemented or though about but should also be trivial
* certificate handling
* user and password
in addition testing against more servers should be done
adding more functionnality shoud be trivial since most code is autogenerated
Example code:
```
import logging
from opcua import Client
from opcua import uaprotocol as ua
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__":
logging.basicConfig(level=logging.WARN)
client = Client("opc.tcp://localhost:4841/freeopcua/server/")
client.connect()
#getting root folder and browsing
root = client.get_root_node()
print(root.get_children())
#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()
```
API is or will be the same as the python bindings of freeopcua c++ client
Most code is autogenerated from xml specification using same code as the one that is goind to be used for freeopcua C++ client and server
what works:
* connection to server, opening channel, session
* browsing and reading attributes value
* gettings nodes by path and nodeids
* creating subscriptions
* subscribing to items for data change
what is not implemented yet (but is trivial to implement):
* subscribing to events
* subscribing to status change
* adding all modify methods
what is not implemented or though about but should also be trivial
* certificate handling
* user and password
in addition testing against more servers should be done
adding more functionnality shoud be trivial since most code is autogenerated
Example code:
```
import logging
from opcua import Client
from opcua import uaprotocol as ua
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__":
logging.basicConfig(level=logging.WARN)
client = Client("opc.tcp://localhost:4841/freeopcua/server/")
client.connect()
#getting root folder and browsing
root = client.get_root_node()
print(root.get_children())
#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()
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
freeopcua-0.5.1.tar.gz
(80.4 kB
view hashes)