Skip to content

Commit ca42c2a

Browse files
AndreasHeineoroulet
authored andcommitted
Create server-extension-object-as-method-argument.py
1 parent 2952ffa commit ca42c2a

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from opcua import Server, ua, uamethod
2+
3+
@uamethod
4+
def callback(parent, in_extobj):
5+
6+
out_extobj = ua.uaprotocol_auto.AxisInformation() # get new instanace of AxisInformation
7+
out_extobj.EngineeringUnits = in_extobj.EngineeringUnits
8+
out_extobj.EURange.Low = in_extobj.EURange.Low
9+
out_extobj.EURange.High = in_extobj.EURange.High
10+
out_extobj.Title = in_extobj.Title
11+
out_extobj.AxisScaleType = in_extobj.AxisScaleType
12+
out_extobj.AxisSteps = in_extobj.AxisSteps
13+
14+
axis_info.set_value(out_extobj) #write values to variable
15+
16+
return [
17+
out_extobj
18+
]
19+
20+
server = Server()
21+
server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
22+
server.set_security_policy([ua.SecurityPolicyType.NoSecurity])
23+
24+
obj = server.get_objects_node()
25+
idx = server.register_namespace("http://examples.freeopcua.github.io")
26+
27+
server.load_type_definitions()
28+
29+
inarg_extobj = ua.Argument()
30+
inarg_extobj.Name = "In"
31+
inarg_extobj.DataType = ua.NodeId(12079, 0)
32+
inarg_extobj.ValueRank = -1
33+
inarg_extobj.ArrayDimensions = []
34+
inarg_extobj.Description = ua.LocalizedText("Wanted AxisInformation")
35+
36+
outarg_extobj = ua.Argument()
37+
outarg_extobj.Name = "Out"
38+
outarg_extobj.DataType = ua.NodeId(12079, 0)
39+
outarg_extobj.ValueRank = -1
40+
outarg_extobj.ArrayDimensions = []
41+
outarg_extobj.Description = ua.LocalizedText("Actual AxisInformation")
42+
43+
method_parent = obj.add_object(idx, "Methods")
44+
method_node = method_parent.add_method(
45+
idx,
46+
"SetAxisInformation",
47+
callback,
48+
[
49+
inarg_extobj
50+
],
51+
[
52+
outarg_extobj
53+
]
54+
)
55+
56+
#add a variable of type AxisInformation
57+
axis_info = obj.add_variable(idx, "AxisInformation", ua.uaprotocol_auto.AxisInformation(), varianttype=ua.VariantType.ExtensionObject)
58+
59+
if __name__ == "__main__":
60+
server.start()

0 commit comments

Comments
 (0)