Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

How to call a method with complex type arguments

More
28 Apr 2020 19:16 #8420 by cadomanis
Thank you for the quick response. Here is the result of the test you asked for:


- Exception {"An OPC-UA operation failure with error ID 'OpcLabs.EasyOpc.UA.UAResultException' occurred, originating from '' and with depth of 1. The inner exception, of type \"OpcLabs.EasyOpc.UA.UAResultException\", contains details about the problem.\r\n+ The client method called was 'CallMultipleMethods'."} System.Exception {OpcLabs.EasyOpc.UA.OperationModel.UAException}
- InnerException (System.Exception) {"The OPC UA server has returned a null result, but this operation requires a non-null value."} System.Exception {OpcLabs.EasyOpc.UA.UAResultException}

Please let me know what else I can do to assist you.

Please Log in or Create an account to join the conversation.

More
28 Apr 2020 18:29 #8419 by support
Hello,

I had a look into the code indicated by the call stack, and there may (or not) be a bug in QuickOPC. What the bug would do is that in case of some exceptions in CallMethod, it would incorrectly throw ArgumentException. If this hypothesis is correct, it would mean that you still have some issue with the Call - but in addition to it, ArgumentException is thrown.

In order to verify this, can you please use CallMultipleMethods instead, passing it an array of just one element, and then check (and post here) what you get in the .Exception property of the element 0 of the result array?

Thank you

Please Log in or Create an account to join the conversation.

More
28 Apr 2020 17:37 #8418 by cadomanis
This is something of a follow-up to the issue in How to Create and Write a Simple Complex Type .

We are trying to call a method on the server which uses a complex type as the first argument. The code we are trying is as follows:
{
            // Instantiate the client object.
            var client = new EasyUAClient();
 
            // Define the structured data TYPE. Including the location of the type definition in the PLC.
            var myStructuredDataType = new StructuredDataType(
                "ST_OpcMoveAbsoluteData",
                "nsu=urn:BeckhoffAutomation:Ua:PLC1 ;ns=4;s=<StructuredDataType>:ST_OpcMoveAbsoluteData")
                {
                    new DataField("fTarget", UAOpcBinaryStandardDataTypes.Double),
                    new DataField("fVelocity", UAOpcBinaryStandardDataTypes.Double),
                    new DataField("fAccel", UAOpcBinaryStandardDataTypes.Double),
                    new DataField("fDecel", UAOpcBinaryStandardDataTypes.Double),
                    new DataField("fDelay", UAOpcBinaryStandardDataTypes.Double)
                };
 
            // Create an instance of the data object to write to the PLC.
            // The data collection was created apparently by the type definition
            // so we can change them instead of "Add" them. Though, the library
            // tolerates an add fine.
            var myStructuredData = new StructuredData(myStructuredDataType);
            myStructuredData.FieldData["fTarget"] = new PrimitiveData(1000d);
            myStructuredData.FieldData["fVelocity"] = new PrimitiveData(100d);
            myStructuredData.FieldData["fAccel"] = new PrimitiveData(50d);
            myStructuredData.FieldData["fDecel"] = new PrimitiveData(50d);
            myStructuredData.FieldData["fDelay"] = new PrimitiveData(5d);
 
            var myGenericData = new UAGenericObject(
                myStructuredData,
                new UAModelNodeDescriptor(
                    "opc.tcp://192.168.1.20:4840",
                    "nsu=urn:BeckhoffAutomation:Ua:PLC1 ;ns=4;s=<StructuredDataType>:ST_OpcMoveAbsoluteData"));
 
            object[] inputs =
            {
                    myGenericData,
                    0
                };
 
            TypeCode[] typeCodes =
            {
                    TypeCode.Empty,
                    TypeCode.UInt16
                };
 
            object[] outputs;
 
            Console.WriteLine();
            Console.WriteLine("Calling...");
            try
            {
 
                outputs = client.CallMethod(
                            "opc.tcp://192.168.1.20:4840",
                            "ns=4;s=OpcCommunication.OpcEffectLinear[1]",
                            "ns=4;s=OpcCommunication.OpcEffectLinear[1]#MoveAbsolute",
                            inputs);
 
            }
            catch (UAException uaException)
            {
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message);
                return;
            }
        }

when attempting to execute that block, there is always an exception thrown when the CallMethod tries to happen. Exception is a System.ArgumentException:
System.ArgumentException
  HResult=0x80070057
  Message=Value does not fall within the expected range.
  Source=OpcLabs.EasyOpcUA
  StackTrace:
   at OpcLabs.EasyOpc.UA.OperationModel.UAException.Create(Exception innerException)
   at OpcLabs.EasyOpc.UA.IEasyUAClientExtension.CallMethod(IEasyUAClient client, UACallArguments callArguments)
   at OpcLabs.EasyOpc.UA.IEasyUAClientExtension.CallMethod(IEasyUAClient client, UAEndpointDescriptor endpointDescriptor, UANodeDescriptor objectNodeDescriptor, UANodeDescriptor methodNodeDescriptor, Object[] inputArguments, Type[] inputTypes)
   at OpcLabs.EasyOpc.UA.IEasyUAClientExtension.CallMethod(IEasyUAClient client, UAEndpointDescriptor endpointDescriptor, UANodeDescriptor objectNodeDescriptor, UANodeDescriptor methodNodeDescriptor, Object[] inputArguments)
   at QuickOpcHmcTest.Form1.buttonMethodStructure_Click(Object sender, EventArgs e) in C:\Users\cadomanis\Source\Repos\quickopchmctest\Form1.cs:line 1361
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at QuickOpcHmcTest.Program.Main() in C:\Users\cadomanis\Source\Repos\quickopchmctest\Program.cs:line 19
 

We have had plenty of success calling methods on the server that only take simple types as the arguments. Wondering if there is something you can pointto in our code on what might be causing these issues.

Thanks

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.049 seconds