Skip to content
Snippets Groups Projects
Commit ee5c4655 authored by Susanna Weber's avatar Susanna Weber
Browse files

last changes to functions

parent 7c6e1cc8
Branches
No related tags found
No related merge requests found
...@@ -23,16 +23,13 @@ def writebeginning(): ...@@ -23,16 +23,13 @@ def writebeginning():
import asyncio import asyncio
from asyncua import ua, Server from asyncua import ua, Server
from asyncua.common.methods import uamethod from asyncua.common.structures104 import new_enum
from asyncua.common.structures104 import new_struct, new_enum, new_struct_field
from asyncua.common import node
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
_logger = logging.getLogger('asyncua') _logger = logging.getLogger('asyncua')
""") """)
server.write("\nasync def main():") server.write("\nasync def main():")
# äinten = "\tab"
server.write(f""" server.write(f"""
# setup our server # setup our server
server = Server() server = Server()
...@@ -66,7 +63,7 @@ def getVariantType(datatype): ...@@ -66,7 +63,7 @@ def getVariantType(datatype):
varianttype = "ua.VariantType.Int64" varianttype = "ua.VariantType.Int64"
if datatype == "float" or datatype == "double": if datatype == "float" or datatype == "double":
varianttype = "ua.VariantType.Double" varianttype = "ua.VariantType.Double"
elif datatype == "Boolean": elif datatype == "boolean":
varianttype = "ua.VariantType.Boolean" varianttype = "ua.VariantType.Boolean"
elif datatype == "time": elif datatype == "time":
varianttype = "ua.VariantType.DateTime" varianttype = "ua.VariantType.DateTime"
...@@ -221,7 +218,6 @@ def writeparameter(parameterobj, headnode, enumnodedict, enumvaldict, parameterl ...@@ -221,7 +218,6 @@ def writeparameter(parameterobj, headnode, enumnodedict, enumvaldict, parameterl
else: else:
varianttype = getVariantType(i.datatype) varianttype = getVariantType(i.datatype)
datatype = "parametertype.nodeid" datatype = "parametertype.nodeid"
#varname = ((i.name).lower()).replace(" ", "") + "var"
parameterdict[i.name] = varname parameterdict[i.name] = varname
server.write(writeindent + varname + " = " + "await " + headnode + ".add_variable(idx, \"" + str( server.write(writeindent + varname + " = " + "await " + headnode + ".add_variable(idx, \"" + str(
parname) + "\", " + str(i.value) + ", " + varianttype + ", " + datatype + ")\n") parname) + "\", " + str(i.value) + ", " + varianttype + ", " + datatype + ")\n")
...@@ -242,16 +238,16 @@ def writeparameter(parameterobj, headnode, enumnodedict, enumvaldict, parameterl ...@@ -242,16 +238,16 @@ def writeparameter(parameterobj, headnode, enumnodedict, enumvaldict, parameterl
server.write(writeindent + "await " + varname + "description.set_modelling_rule(True)\n\n") server.write(writeindent + "await " + varname + "description.set_modelling_rule(True)\n\n")
def defFunction(functionname, file, indent, inargs, function): def defFunction(functionname, file, indent, inargs, function, returnargs):
#return values are not written in the function at the moment #return values are not written in the function at the moment
""" """
writes the body for each function, it leaves the body empty and gives a description for the method which should be implemented writes the body for each function, it leaves the body empty and gives a description for the method which should be implemented
arguments: :param functionname: name of the function changed to a lowercase String without blanks
- functionname(name of the function changed to a lowercase String without blanks), :param file: file it writes in
- file(file it writes in) :param indent: indent it writes with
- indent(indent it writes with) :param inargs: arguments of the function
- inargs(arguments of the function :param function: the object
- function(the object) :param returnargs: arguments that should be returned to be listed in the comments
""" """
writeindent = "" writeindent = ""
for i in range(indent): for i in range(indent):
...@@ -269,6 +265,8 @@ def defFunction(functionname, file, indent, inargs, function): ...@@ -269,6 +265,8 @@ def defFunction(functionname, file, indent, inargs, function):
file.write(writeindent + "#ToDo: Write a Function that fits the decription: \"" + str(function.description) + "\"\n") file.write(writeindent + "#ToDo: Write a Function that fits the decription: \"" + str(function.description) + "\"\n")
file.write(writeindent + " # Use \"await\" before changing values and cast to Ua Varianttype\n") file.write(writeindent + " # Use \"await\" before changing values and cast to Ua Varianttype\n")
file.write(writeindent + " # Use get and set_value to change the value at a given nodeid e.g: await testvar.set_value(ua.Variant(position))\n") file.write(writeindent + " # Use get and set_value to change the value at a given nodeid e.g: await testvar.set_value(ua.Variant(position))\n")
if returnargs is not None:
file.write(writeindent + " # Function should return these values: " + str(returnargs) + "\n")
file.write(writeindent + "pass\n") file.write(writeindent + "pass\n")
...@@ -291,7 +289,7 @@ def writefunction(functionobj, headnode, functionlist): ...@@ -291,7 +289,7 @@ def writefunction(functionobj, headnode, functionlist):
functionname = (fobj["name"].lower()).replace(" ", "") functionname = (fobj["name"].lower()).replace(" ", "")
functionlist.remove(fobj) functionlist.remove(fobj)
break break
defFunction(functionname, server, 1, i.inargsnames, i) defFunction(functionname, server, 1, i.inargsnames, i, i.outargsnames)
server.write("\n") server.write("\n")
inargslist = [] inargslist = []
if i.inargsdatatypes != None: if i.inargsdatatypes != None:
...@@ -302,8 +300,21 @@ def writefunction(functionobj, headnode, functionlist): ...@@ -302,8 +300,21 @@ def writefunction(functionobj, headnode, functionlist):
for j in i.outargsdataypes: for j in i.outargsdataypes:
inargslist.append(getVariantType(j)) inargslist.append(getVariantType(j))
methodvarname = functionname + "var" methodvarname = functionname + "var"
server.write(writeindent + methodvarname + " = await " + headnode + ".add_method(idx, \"" + funcname +"\", " + functionname + ", " + str(inargslist) + ", "+ str(outargslist) + ")\n\n") server.write(writeindent + methodvarname + " = await " + headnode + ".add_method(idx, \"" + funcname +"\", " + functionname + ", [")
server.write(writeindent + "await " + methodvarname + ".set_modelling_rule(True)\n\n") for a in range(len(inargslist)):
server.write(str(inargslist[a].replace("\'", "")))
if a < len(inargslist) - 1:
server.write(", ")
server.write("], [")
for a in range(len(outargslist)):
server.write(str(outargslist[a].replace("\'", "")))
if a < len(outargslist) - 1:
server.write(", ")
server.write("]")
server.write(")\n")
server.write(writeindent + "await " + methodvarname + ".set_modelling_rule(True)\n")
server.write(writeindent + methodvarname + "description = await " + methodvarname + ".add_property(idx, \"Description\", \"" + i.description + "\")\n")
server.write(writeindent + "await " + methodvarname + "description.set_modelling_rule(True)\n\n")
def writeobjects(objtype, objname, headnode): def writeobjects(objtype, objname, headnode):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment