Commit d4c1320d authored by Olivier R-D's avatar Olivier R-D

update readme and server example

parent f9cadc64
Pure Python OPC-UA Client and Server Pure Python OPC-UA Client and Server, http://freeopcua.github.io/, https://github.com/FreeOpcUa/python-opcua
API is similar to the python bindings of freeopcua c++ client and servers. However there are differences due to a different implementation and to make it more pythonic. API is similar to the python bindings of freeopcua c++ client and servers. However there are differences due to a different implementation and to make it more pythonic.
Most code is autogenerated from xml specification using same code as the one that is going to be used for freeopcua C++ client and server. Adding more functionnality shoud be trivial. Most code is autogenerated from xml specification using same code as the one that is going to be used for freeopcua C++ client and server. Adding more functionnality shoud be trivial.
with Python3 the server and client do not require any third party libraries. If using python2.7 or pypy you need to install enum34, with pip for example. Server and client can be run with pypy. with Python3 the server and client do not require any third party libraries. If using python2.7 or pypy you need to install enum34, trollius(asyncio), and futures(concurrent.futures), with pip for example. Server and client can be run with pypy.
Client: what works: Client: what works:
...@@ -15,13 +15,13 @@ Client: what works: ...@@ -15,13 +15,13 @@ Client: what works:
* subscribing to items for data change * subscribing to items for data change
* adding nodes * adding nodes
* tested servers: freeopcua C++, freeopcua Python, prosys * tested servers: freeopcua C++, freeopcua Python, prosys
* method call
Client: what is not implemented yet Client: what is not implemented yet
* method call
* removing nodes * removing nodes
* subscribing to events * subscribing to events
* subscribing to status change * subscribing to status change
* adding all modify methods * adding missing modify methods
* certificate handling * certificate handling
* user and password * user and password
......
...@@ -22,29 +22,37 @@ if __name__ == "__main__": ...@@ -22,29 +22,37 @@ if __name__ == "__main__":
#optional setup logging #optional setup logging
logging.basicConfig(level=logging.WARN) logging.basicConfig(level=logging.WARN)
#logger = logging.getLogger("opcua.address_space") #logger = logging.getLogger("opcua.address_space")
logger = logging.getLogger("asyncio") #logger = logging.getLogger("opcua.internal_server")
logger.setLevel(logging.DEBUG) #logger.setLevel(logging.DEBUG)
logger = logging.getLogger("opcua.internal_server") #logger = logging.getLogger("opcua.subscription_server")
logger.setLevel(logging.DEBUG) #logger.setLevel(logging.DEBUG)
logger = logging.getLogger("opcua.subscription_server")
logger.setLevel(logging.DEBUG)
# now setup our server
# now setup our server and start it
server = Server() server = Server()
server.set_endpoint("opc.tcp://localhost:4841/freeopcua/server/") server.set_endpoint("opc.tcp://localhost:4841/freeopcua/server/")
server.set_server_name("FreeOpcUa Example Server") server.set_server_name("FreeOpcUa Example Server")
root = server.get_root_node()
# setup our own namespace
uri = "http://examples.freeopcua.github.io"
idx = server.register_namespace(uri)
# get Objects node, this is where we should put our custom stuff
objects = server.get_objects_node() objects = server.get_objects_node()
myfolder = objects.add_folder(2, "myfolder")
myobj = objects.add_object(2, "NewObject")
myvar = myobj.add_variable(2, "MyVariable", 6.7)
myarrayvar = myobj.add_variable(2, "myarrayvar", [6.7, 7.9])
myprop = myobj.add_property(2, "myproperty", "I am a property")
# populating our address space
myfolder = objects.add_folder(idx, "myfolder")
myobj = objects.add_object(idx, "NewObject")
myvar = myobj.add_variable(idx, "MyVariable", 6.7)
myarrayvar = myobj.add_variable(idx, "myarrayvar", [6.7, 7.9])
myprop = myobj.add_property(idx, "myproperty", "I am a property")
# starting!
server.start() server.start()
print("Available loggers are: ", logging.Logger.manager.loggerDict.keys()) print("Available loggers are: ", logging.Logger.manager.loggerDict.keys())
try: try:
handler = SubHandler() handler = SubHandler()
#enable following if you want to subscribe to nodes on server side
#sub = server.create_subscription(500, handler) #sub = server.create_subscription(500, handler)
#handle = sub.subscribe_data_change(myvar) #handle = sub.subscribe_data_change(myvar)
#time.sleep(0.1) #time.sleep(0.1)
......
...@@ -443,48 +443,6 @@ class QualifiedName(object): ...@@ -443,48 +443,6 @@ class QualifiedName(object):
__repr__ = __str__ __repr__ = __str__
'''
class DateTime(object):
def __init__(self, data=None):
if data is None:
self.data = datetime_to_win_epoch(datetime.now())
else:
self.data = data
@staticmethod
def now():
return DateTime.from_datetime(datetime.now())
@staticmethod
def from_datetime(pydt):
dt = DateTime()
dt.data = datetime_to_win_epoch(pydt)
return dt
def to_binary(self):
return struct.pack("<d", self.data)
@staticmethod
def from_binary(data):
#print("Generating DateTime from {}", data)
d = DateTime()
d.data = struct.unpack("<d", data.read(8))[0]
return d
@staticmethod
def from_time_t(data):
return DateTime.from_datetime(datetime.fromtimestamp(data))
def to_time_t(self):
epoch = datetime.utcfromtimestamp(0)
delta = self.win_epoch_to_datetime(self.data)() - epoch
return delta.total_seconds()
def __str__(self):
return "Datetime({})".format(win_epoch_to_datetime(self.data).isoformat())
__repr__ = __str__
'''
class VariantType(Enum): class VariantType(Enum):
''' '''
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment