Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SOIL2OPC UA Translator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WZL-IQS-Public
Sensor Interfacing Language (SOIL)
SOIL2OPC UA Translator
Commits
ee5c4655
Commit
ee5c4655
authored
1 year ago
by
Susanna Weber
Browse files
Options
Downloads
Patches
Plain Diff
last changes to functions
parent
7c6e1cc8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
writefile.py
+27
-16
27 additions, 16 deletions
writefile.py
with
27 additions
and
16 deletions
writefile.py
+
27
−
16
View file @
ee5c4655
...
@@ -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
(
"
\n
async def main():
"
)
server
.
write
(
"
\n
async 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
==
"
B
oolean
"
:
elif
datatype
==
"
b
oolean
"
:
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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment