How to get the result code after calling a method.|OPC UA Standard|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
How to get the result code after calling a method.
Avatar
Yi Han
Member
Members
Forum Posts: 7
Member Since:
04/11/2018
sp_UserOfflineSmall Offline
1
07/20/2018 - 04:45
sp_Permalink sp_Print

Hi,

 

I am trying to call a method without of output parameter.

This is how i created the method on server side:

 #region Input Method
                    MethodState ReceiveMessageMethod = CreateMethod(root, "ReceiveMessage", "ReceiveMessage");
                    // set input arguments
                    ReceiveMsiMethod.InputArguments = new PropertyState<Argument[]>(ReceiveMsiMethod);
                    ReceiveMsiMethod.InputArguments.NodeId = new NodeId(ReceiveMsiMethod.BrowseName.Name + "InArgs", NamespaceIndex);
                    ReceiveMsiMethod.InputArguments.BrowseName = BrowseNames.InputArguments;
                    ReceiveMsiMethod.InputArguments.DisplayName = ReceiveMsiMethod.InputArguments.BrowseName.Name;
                    ReceiveMsiMethod.InputArguments.TypeDefinitionId = VariableTypeIds.PropertyType;
                    ReceiveMsiMethod.InputArguments.ReferenceTypeId = ReferenceTypeIds.HasProperty;
                    ReceiveMsiMethod.InputArguments.DataType = DataTypeIds.String;
                    ReceiveMsiMethod.InputArguments.ValueRank = ValueRanks.OneDimension;
 
ReceiveMsiMethod.InputArguments.Value = new Argument[]
                    {
                        new Argument() { Name = "String value", Description = "String value",  DataType = DataTypeIds.String, ValueRank = ValueRanks.Scalar }
                    };
 
ReceiveMessageMethod.OnCallMethod = new GenericMethodCalledEventHandler(OnInputCall);

and the default OnInputCall method from foundation's SDK:

        private ServiceResult OnInputCall(
            ISystemContext context,
            MethodState method,
            IList<object> inputArguments,
            IList<object> outputArguments)
        {
 
            // all arguments must be provided.
            if (inputArguments.Count < 1)
            {
                return StatusCodes.BadArgumentsMissing;
            }
 
            return ServiceResult.Good;
        }

 

This is how I call this method on client side:

IList<object> val = session.Call(new NodeId("ns=2;s=Root"), new NodeId("ns=2;s=ReceiveMessage"), "Test string");

 

The problem now, is that I want to know if the call was successful or not. On client side, how can I get the ServiceResult from server?

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
07/20/2018 - 09:02
sp_Permalink sp_Print

The stack throws a ServiceResultException. Trap that and you have the StatusCode.

Avatar
Yi Han
Member
Members
Forum Posts: 7
Member Since:
04/11/2018
sp_UserOfflineSmall Offline
3
07/24/2018 - 01:42
sp_Permalink sp_Print sp_EditHistory

Thanks for the answer.

But with ServiceResultException I can only get the result codes from exceptions.

Is it possible to get the "Good" result code directly(assuming that the method is called successfully)?

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
07/24/2018 - 09:21
sp_Permalink sp_Print

Returning "good" StatusCodes other than a simple "good" is not supported for service calls. A Method call is similar to a service call but you could call the raw Call method on the channel if you need a non-simple Good value. I do not recommend it because a lot of programming languages impose this limitation on the APIs exposed to developers.

Avatar
Sameer AL-Qadasi
Member
Members
Forum Posts: 4
Member Since:
03/01/2017
sp_UserOfflineSmall Offline
5
01/14/2020 - 02:56
sp_Permalink sp_Print

Hello Randy,

I have a question related to Method StatusCodes, and I thought it would be better to continue the discussion here rather than starting a new topic.

The question is: if I want to use self-defined StatusCodes, I would define an output argument, in which I can store this self-defined StatusCode. But in this case, which StatusCode should the Call Service return?

For example: I have a method which divide two doubles and returns the dicvision result and a the mathimatical operation StatusCode. So the method has two input arguments (double x, double y) and two output arguments (double z=x/y, int status). By division by zero the mathimatical operation is wrong and I write, let's say BAD_MATH_ZERO_DIVISION, in the status output argument. Should the call service StatusCode be in this case UA_STATUSCODE_GOOD or should I use a UA StatusCode, which represents an error like UA_STATUSCODE_BAD_INVALID_ARGUMENT?

Best regards

Sameer

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
6
01/15/2020 - 02:16
sp_Permalink sp_Print

StatusCodes are set by the specification and cannot be replaced with vendor defined codes.

You should look at the available status codes and find one that is close.

If you need something more specific you can use the SymbolicName in the DiagnosticInfo to return your vendor defined code.

Adding an output argument is also an option.

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 24
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1435
Posts: 4855