(srv)
| 15 | from opcua.common.methods import call_method_full |
| 16 | |
| 17 | def add_server_methods(srv): |
| 18 | @uamethod |
| 19 | def func(parent, value): |
| 20 | return value * 2 |
| 21 | |
| 22 | o = srv.get_objects_node() |
| 23 | v = o.add_method(ua.NodeId("ServerMethod", 2), ua.QualifiedName('ServerMethod', 2), func, [ua.VariantType.Int64], [ua.VariantType.Int64]) |
| 24 | |
| 25 | @uamethod |
| 26 | def func2(parent, methodname, value): |
| 27 | if methodname == "panic": |
| 28 | return ua.StatusCode(ua.StatusCodes.BadOutOfMemory) |
| 29 | if methodname != "sin": |
| 30 | res = ua.CallMethodResult() |
| 31 | res.StatusCode = ua.StatusCode(ua.StatusCodes.BadInvalidArgument) |
| 32 | res.InputArgumentResults = [ua.StatusCode(ua.StatusCodes.BadNotSupported), ua.StatusCode()] |
| 33 | return res |
| 34 | return math.sin(value) |
| 35 | |
| 36 | o = srv.get_objects_node() |
| 37 | v = o.add_method(ua.NodeId("ServerMethodArray", 2), ua.QualifiedName('ServerMethodArray', 2), func2, [ua.VariantType.String, ua.VariantType.Int64], [ua.VariantType.Int64]) |
| 38 | |
| 39 | @uamethod |
| 40 | def func3(parent, mylist): |
| 41 | return [i * 2 for i in mylist] |
| 42 | |
| 43 | o = srv.get_objects_node() |
| 44 | v = o.add_method(ua.NodeId("ServerMethodArray2", 2), ua.QualifiedName('ServerMethodArray2', 2), func3, [ua.VariantType.Int64], [ua.VariantType.Int64]) |
| 45 | |
| 46 | @uamethod |
| 47 | def func4(parent): |
| 48 | return None |
| 49 | |
| 50 | base_otype= srv.get_node(ua.ObjectIds.BaseObjectType) |
| 51 | custom_otype = base_otype.add_object_type(2, 'ObjectWithMethodsType') |
| 52 | custom_otype.add_method(2, 'ServerMethodDefault', func4) |
| 53 | custom_otype.add_method(2, 'ServerMethodMandatory', func4).set_modelling_rule(True) |
| 54 | custom_otype.add_method(2, 'ServerMethodOptional', func4).set_modelling_rule(False) |
| 55 | custom_otype.add_method(2, 'ServerMethodNone', func4).set_modelling_rule(None) |
| 56 | o.add_object(2, 'ObjectWithMethods', custom_otype) |
| 57 | |
| 58 | @uamethod |
| 59 | def func5(parent): |
| 60 | return 1,2,3 |
| 61 | o = srv.get_objects_node() |
| 62 | v = o.add_method(ua.NodeId("ServerMethodTuple", 2), ua.QualifiedName('ServerMethodTuple', 2), func5, [], [ua.VariantType.Int64, ua.VariantType.Int64, ua.VariantType.Int64]) |
| 63 | |
| 64 | |
| 65 |
no test coverage detected