# OPC-UA - Method call with "complex" input values

**URL:** <https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205>\
**Category:** Ignition\
**Created:** [January 10, 2020, 9:35am UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205 "2020-01-10T09:35:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ncj](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@ncj](https://forum.inductiveautomation.com/u/ncj)\
**Post date:** [January 10, 2020, 9:35am UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/1 "2020-01-10T09:35:36Z")

</div>

In relation to calling OPC-UA method calls on RFID readers supporting OPC-UA AutoID companion specifications ([https://opcfoundation.org/markets-collaboration/aim/](https://opcfoundation.org/markets-collaboration/aim/)) I am hitting some challenges.

Specifically it is when calling the method “SCAN”  
([https://opcfoundation.org/developer-tools/specifications-unified-architecture/opc-unified-architecture-for-autoid/](https://opcfoundation.org/developer-tools/specifications-unified-architecture/opc-unified-architecture-for-autoid/))  
Here i am trying to pass this structure - [https://reference.opcfoundation.org/v104/AutoID/DataTypes/ScanSettings/](https://reference.opcfoundation.org/v104/AutoID/DataTypes/ScanSettings/)

In the “inputs” parameter of system.opua.callMethod.  
When sending the list i am getting following error message - which makes sense:

INFO | jvm 1 | 2020/01/09 15:17:32 | (2158690304L, u’Bad\_InvalidArgument’, u’One or more arguments are invalid.’)  
INFO | jvm 1 | 2020/01/09 15:17:32 | [(2155085824L, u’Bad\_TypeMismatch’, u"The value supplied for the attribute is not of the same type as the attribute’s value.")]

I would like help on creating the “struct” that is required to send as an input parameter using system.opua.callMethod

My current code looks like this:

```
    ScanSettings = [2000,2,0] 

    result = system.opcua.callMethod(
	    "S000001",
    	"ns=4;i=5002",
    	"ns=4;i=7010",
    	[ScanSettings]
	)
```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 10, 2020, 1:15pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/2 "2020-01-10T13:15:17Z")

</div>

This _miiiiight_ work if you pass anything that’s supposed to be a struct as a JSON string. ScanSettings would be:

```auto
{
    duration: 0.0,
    cycles: 0,
    dataAvailable: false,
    locationType: 0
}

```

---

<div class="post-metadata">

**Author:** ![ncj](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@ncj](https://forum.inductiveautomation.com/u/ncj)\
**Post date:** [January 13, 2020, 9:26pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/3 "2020-01-13T21:26:33Z")

</div>

I tried. Not too successfull 🙂 - throws same error.

Is there anyway to debug what is actually sent “raw” or see how system.opua.callMethod is put together?

I will try a bit more as i have several different AutoID devices. They should all behave similar, but it might prove otherwise testing a bit more.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 13, 2020, 9:30pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/4 "2020-01-13T21:30:01Z")

</div>

Getting a capture with Wireshark might help.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 13, 2020, 9:46pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/5 "2020-01-13T21:46:56Z")

</div>

Ah, also find the logger for `opcua.gateway.scripting.CallMethod` and turn it to DEBUG.

---

<div class="post-metadata">

**Author:** ![ncj](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@ncj](https://forum.inductiveautomation.com/u/ncj)\
**Post date:** [January 14, 2020, 9:51am UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/6 "2020-01-14T09:51:30Z")

</div>

Hi Kevin - Super with the logger.

It looks like this. Do you have an idea what could be the exact reason.

```auto
CallMethod	14Jan2020 09:39:08	coerced outputs: []
CallMethod	14Jan2020 09:39:08	coerced inputs: [Variant{value=null}]
CallMethod	14Jan2020 09:39:08	raw inputs: [u'{"duration":2000.0,"dataAvailable":0,"cycles":4}']
CallMethod	14Jan2020 09:39:08	arguments: MethodArguments(inputArguments=[Argument{Name=Setting, DataType=NodeId{ns=3, id=3010}, ValueRank=-1, ArrayDimensions=[], Description=LocalizedText{text=null, locale=null}}], outputArguments=[Argument{Name=Results, DataType=NodeId{ns=3, id=3007}, ValueRank=1, ArrayDimensions=[], Description=LocalizedText{text=null, locale=null}}, Argument{Name=Status, DataType=NodeId{ns=3, id=3013}, ValueRank=-1, ArrayDimensions=[], Description=LocalizedText{text=null, locale=null}}])
CallMethod	14Jan2020 09:39:08	objectId=NodeId{ns=4, id=5002}, methodId=NodeId{ns=4, id=7010}

```

I sent with different “raw inputs” like below but gets same result:  
raw inputs: [u’{“duration”:2000.0,“locationType”:0,“dataAvailable”:“false”,“cycles”:4}’]  
raw inputs: [u’{“duration”:2000.0,“locationType”:0,“dataAvailable”:0,“cycles”:4}’]  
raw inputs: [u’{“duration”:2000.0,“dataAvailable”:0,“cycles”:4}’]

In “arguments:” above NodeID references looks like this on the server through UaExpert:

Position:  
Root - Types - DataTypes - Enumeration - Structure

- ns=3, id=3007 - RfidScanResult  
 ![1](https://us1.discourse-cdn.com/inductiveautomation/original/2X/3/3e28be69779314e8433f0642d33dc9511593291a.png)
- ns=3, id=3010 - ScanSettings  
 ![2](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6b4c1fab4cd023c0e56298215ef2ff02741f8dac.png)

Root - Types - DataTypes - Enumeration

- ns=3, id=3013 - AutoIdOperationStatusEnumeration  
 ![3](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/7ea6e19d357597b6940463ba59c83b3ea6284c1b.png)

---

<div class="post-metadata">

**Author:** ![ncj](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@ncj](https://forum.inductiveautomation.com/u/ncj)\
**Post date:** [January 14, 2020, 11:51am UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/7 "2020-01-14T11:51:51Z")

</div>

Small addition

Trying it with another RFID reader supporting the OPC-UA AutoID companion specification i get these “Description=” values on the definition of “MethodArguments”.

```auto
MethodArguments(
    inputArguments=
        [
            Argument{Name=Settings, DataType=NodeId{ns=3, id=3010}, ValueRank=-1, ArrayDimensions=[], Description=LocalizedText{text=Settings for reading the UIDs or EPCs , locale=en}}
        ]
    
    , outputArguments=
        [
            Argument{Name=Results, DataType=NodeId{ns=3, id=3007}, ValueRank=1, ArrayDimensions=[], Description=LocalizedText{text=UID, EPC of the tags, locale=en}}, 
            Argument{Name=Status, DataType=NodeId{ns=3, id=3013}, ValueRank=1, ArrayDimensions=[], Description=LocalizedText{text=Status of the scan, locale=en}}
        ]
)

```

Does not reveal much more, but just confirms the other OPC-UA server acts the same way.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 14, 2020, 2:23pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/8 "2020-01-14T14:23:46Z")

</div>

Can you turn the logger you find searching “DataTypeDictionaryReader” to TRACE, edit/save the OPC UA connection to this server, and then once it is connected again export the logs and upload them for me?

Also if you’re aware of a test server or some other way I can test this out myself it would help.

edit: and one more logger: `com.inductiveautomation.ignition.gateway.opcua.util.Conversions`

Try to invoke the method again after edit/saving the connection and letting it connect.

---

<div class="post-metadata">

**Author:** ![ncj](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@ncj](https://forum.inductiveautomation.com/u/ncj)\
**Post date:** [January 15, 2020, 3:07pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/9 "2020-01-15T15:07:44Z")

</div>

Set “DataTypeDictionaryReader” to TRACE and got a reload of the OPC server structure in the log.  
Sent the log to you.

For testing i suggest a Skype session. I have nothing i can expose to you directly.

For the other logger, i cannot find it. Any dependency to OPC-UA module?  
Or can I use the less specific: com.inductiveautomation.ignition.gateway.opcua.util  
My current build is: OPC-UA 8.0.0 (b2019040719)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/5925ff90a28dcb4dcaf2473cbab1b54e824249b5.png)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 15, 2020, 3:16pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/10 "2020-01-15T15:16:37Z")

</div>

Ah, can you upgrade to 8.0.7 while we continue testing?

I’d like to see these same procedure and logs after the upgrade - there should be a little more information, and you should be able to find the Conversions logger.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 15, 2020, 3:37pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/11 "2020-01-15T15:37:09Z")

</div>

Ok, I was able to see the structure definition is a little more complex than the documentation suggested, so the JSON value you feed it has to be a little more complicated as well.

Try this instead:

```auto
{
    "LocationTypeSpecified": 1,
    "Reserved1": 0,
    "Duration": 0.0,
    "Cycles": 0,
    "DataAvailable": false,
    "LocationType": 0
}

```

Alternatively you can omit the LocationType member at the end if you set the “LocationTypeSpecified” member to 0.

Eventually you should not have to include these extra members that should be considered implementation details but the dynamic codec support in our OPC UA SDK is a little bit primitive right now.

I still recommend upgrading to 8.0.7 even if this works, though.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 16, 2020, 1:41pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/12 "2020-01-16T13:41:27Z")

</div>

For anyone who finds this in the future the problem becomes clear with the “Conversions” logger on:

```auto
2020/01/16 02:50:19:445 | DEBUG | [Conversions] 
failed to encode 
    dataTypeId=NodeId{ns=3, id=3010} 
    binaryEncodingId=NodeId{ns=3, id=5015} 
    value={"Cycles":4,"LocationTypeSpecified":0,"Duration":2000.0,"DataAvailable":0,"Reserved1":0}

org.eclipse.milo.opcua.stack.core.UaSerializationException: 
java.lang.ClassCastException: class com.google.gson.internal.LazilyParsedNumber cannot be cast to class java.lang.Integer (com.google.gson.internal.LazilyParsedNumber is in unnamed module of loader com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader @2232ff6c; java.lang.Integer is in module java.base of loader 'bootstrap')
	at org.eclipse.milo.opcua.stack.core.types.OpcUaDefaultBinaryEncoding.encode(OpcUaDefaultBinaryEncoding.java:85)
	at org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject.encode(ExtensionObject.java:219)

```

It’s an issue that needs to be fixed in the OPC UA SDK and then integrated into Ignition once it’s released.

---

<div class="post-metadata">

**Author:** ![321liftoff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/321liftoff/32/27544_2.png) [@321liftoff](https://forum.inductiveautomation.com/u/321liftoff)\
**Post date:** [August 22, 2020, 10:09am UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/13 "2020-08-22T10:09:05Z")

</div>

Hi Kevin,

This may be a simple question, but I’m trying to send an array of strings as the input arguments. How would I construct this in my Ignition Script?

Attached is a wireshark capture of a good method call through UA Expert.

[Good method call.zip](https://forum.inductiveautomation.com/uploads/short-url/2TmpdYKGYHMMJLifZQyNz3hYjWW.zip) (824 Bytes)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 22, 2020, 12:08pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/14 "2020-08-22T12:08:41Z")

</div>

You’ll have to do something annoying like this to create an array value for now:

```auto
	import jarray
	from java.lang import String
	
	arg = ["foo", "bar"]
	arr = jarray.array(arg, String)

```

We can probably add support for just using a list without conversion to an array first to `system.opcua.callMethod` but for now you’ll have to do the conversion yourself.

---

<div class="post-metadata">

**Author:** ![321liftoff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/321liftoff/32/27544_2.png) [@321liftoff](https://forum.inductiveautomation.com/u/321liftoff)\
**Post date:** [August 22, 2020, 3:15pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/15 "2020-08-22T15:15:13Z")

</div>

Thanks, that works for me!

---

<div class="post-metadata">

**Author:** ![automatisation](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@automatisation](https://forum.inductiveautomation.com/u/automatisation)\
**Post date:** [October 19, 2020, 6:26pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/16 "2020-10-19T18:26:09Z")

</div>

Trying to do the same but I can’t figure out the error.  
Siemens AutoId Reader, trying to call the ReadTag method, which works fine with UAExpert.

Arguments should be

- Identifier
- CodeType
- Region
- Offset
- Length
- Password

No matter what I input, the result is always “The value supplied for the attribute is not of the same type as the attribute’s value.”

Output of the callMethod return :  
((2158690304L, u’Bad\_InvalidArgument’, u’One or more arguments are invalid.’), [(2155085824L, u’Bad\_TypeMismatch’, u"The value supplied for the attribute is not of the same type as the attribute’s value."), (0L, u’Good’, u’Good; unspecified.’), (0L, u’Good’, u’Good; unspecified.’), (0L, u’Good’, u’Good; unspecified.’), (0L, u’Good’, u’Good; unspecified.’), (2155085824L, u’Bad\_TypeMismatch’, u"The value supplied for the attribute is not of the same type as the attribute’s value.")], [])

Debug messages for one of my attempt :  
Arguments on this call :  
res = system.opcua.callMethod(“SIL\_E2\_RFID”, “ns=4;i=5002”, “ns=4;i=7009”, [  
system.util.jsonEncode({‘Identifier’ : 0}), ‘UId’, 0, 0, 8, system.util.jsonEncode({‘Password’ : ‘’}) ])

| CallMethod | 19Oct2020 14:17:46 |
| --- | --- |
| | coerced inputs: [Variant{value=null}, Variant{value=UId}, Variant{value=0}, Variant{value=0}, Variant{value=8}, Variant{value={“Password”:""}}] |
| Conversions | 19Oct2020 14:17:46 |
| | failed to encode dataTypeId=NodeId{ns=3, id=3020} binaryEncodingId=NodeId{ns=3, id=5030} value={“Identifier”:0} |
| CallMethod | 19Oct2020 14:17:46 |
| | raw inputs: [u’{“Identifier”:0}’, ‘UId’, 0, 0, 8, u’{“Password”:""}’] |
| CallMethod | 19Oct2020 14:17:46 |
| | arguments: MethodArguments(inputArguments=[Argument(name=Identifier, dataType=NodeId{ns=3, id=3020}, valueRank=-1, arrayDimensions=[], description=LocalizedText{text=null, locale=null}), Argument(name=CodeType, dataType=NodeId{ns=3, id=3031}, valueRank=-1, arrayDimensions=[], description=LocalizedText{text=null, locale=null}), Argument(name=Region, dataType=NodeId{ns=0, id=5}, valueRank=-1, arrayDimensions=[], description=LocalizedText{text=null, locale=null}), Argument(name=Offset, dataType=NodeId{ns=0, id=7}, valueRank=-1, arrayDimensions=[], description=LocalizedText{text=null, locale=null}), Argument(name=Length, dataType=NodeId{ns=0, id=7}, valueRank=-1, arrayDimensions=[], description=LocalizedText{text=null, locale=null}), Argument(name=Password, dataType=NodeId{ns=0, id=15}, valueRank=-1, arrayDimensions=[], description=LocalizedText{text=null, locale=null})], outputArguments=[Argument(name=ResultData, dataType=NodeId{ns=0, id=15}, valueRank=-1, arrayDimensions=[], description=LocalizedText{text=null, locale=null}), Argument(name=Status, dataType=NodeId{ns=3, id=3013}, valueRank=-1, arrayDimensions=[], description=LocalizedText{text=null, locale=null})]) |

Maybe the issue is related to the fact the argument is considered an Union Datatype ([https://reference.opcfoundation.org/v104/AutoID/v100/docs/9.4.2/](https://reference.opcfoundation.org/v104/AutoID/v100/docs/9.4.2/)) but I have no idea how to format it.

Ho, Ignition is 8.0.16 (b2020082513)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 19, 2020, 7:03pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/17 "2020-10-19T19:03:20Z")

</div>

According the response the ‘Identifier’ and ‘Password’ arguments you’ve supplied are incorrect.

I think ‘Identifier’ needs to have a JSON value more like this, though I don’t know what type in that union you’re actually trying to use, and it will affect the switch value and object contents:

```auto
{"SwitchField":2,"String":"stringIdGoesHere"}

```

‘Password’ in this method is actually supposed to be a `ByteString`… which is a bit difficult to create. Maybe something like this:

```auto
from org.eclipse.milo.opcua.stack.core.types.builtin import ByteString
	
pwd = "my_password"
pwd_bs = ByteString.of(pwd.encode())

```

edit:  
if the value for 'Identifier" is really supposed to be 0 it may be this:

```auto
{"SwitchField":4,"Custom":0}

```

---

<div class="post-metadata">

**Author:** ![automatisation](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@automatisation](https://forum.inductiveautomation.com/u/automatisation)\
**Post date:** [October 19, 2020, 7:29pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/18 "2020-10-19T19:29:19Z")

</div>

```auto
{"SwitchField":0,"Custom":0}

```

did the trick for the 1st argument. It was working with None (0) in UAExpert.

Sadly, 2nd part for the last argument fails : I can’t import milo

| script | 19Oct2020 15:27:22 |
| --- | --- |
| | Error running action ‘dom.onClick’ on test@D/root/Button: Traceback (most recent call last): File “function:runAction”, line 2, in runAction ImportError: No module named milo |

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 19, 2020, 7:32pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/19 "2020-10-19T19:32:16Z")

</div>

Ah, right, you wouldn’t be able to.

See if the server will accept a String argument instead, then.

---

<div class="post-metadata">

**Author:** ![automatisation](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@automatisation](https://forum.inductiveautomation.com/u/automatisation)\
**Post date:** [October 19, 2020, 7:49pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205/20 "2020-10-19T19:49:42Z")

</div>

For the purpose of testing, the reader has no security, so no password. Putting security would have been the next step 🙂

I tried a few strings to no avail :

- None
- “”
- “Password:None”
- “Password:”
- b""
- {} \>\> Crash (Not a built-in type: class org.python.core.PyDictionary)
- {“Password”: “”} \>\> Crash (Not a built-in type: class org.python.core.PyDictionary)
- 0x00

[Next page](https://forum.inductiveautomation.com/t/opc-ua-method-call-with-complex-input-values/31205.md?page=2)
