Write Variant Array: BadTypeMismatch | OPC UA Implementation: Stacks, Tools, and Samples | Forum

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
Write Variant Array: BadTypeMismatch
Avatar
Andrea OPC
Member
Members
Forum Posts: 6
Member Since:
07/19/2017
sp_UserOfflineSmall Offline
1
09/04/2019 - 13:41
sp_Permalink sp_Print sp_EditHistory

Hi,
I'm trying to exchange data with an injection molding machine which has got an OPC UA server built in.

I can read and write all scalar values and I can call methods too but I'm not able to write a particular node which represents a list of orders.

 

The node structure stated in the machine manual is the following:

Structure

 

UaExpert Client show a Variant Array[-1] type while dataFEED Client show a Variant type with <null/> value:

 

UAExpert Client

 

dataFEED Client

 

I have tried to write a variant array from UaExpert Client but I receive BadTypeMismatch error:

UAExpert write

UAExpert write error

 

I have tried to implement the following code in a C# project but I always obtain the same error:

Opc.Ua.Variant[] dataValue = {

new Opc.Ua.Variant((UInt16)1),
new Opc.Ua.Variant((UInt32)2),
new Opc.Ua.Variant((string)"3"),
new Opc.Ua.Variant((string)"4"),
new Opc.Ua.Variant((string)"5"),
new Opc.Ua.Variant((string)"6"),
new Opc.Ua.Variant((string)"7"),
new Opc.Ua.Variant((string)"8"),
new Opc.Ua.Variant((string)"9") };

DataValue dataValue1 = new DataValue() { Value = dataValue };

WriteValue valueToWrite = new WriteValue();
valueToWrite.Value = dataValue1;
valueToWrite.NodeId = nodeId;
valueToWrite.AttributeId = Attributes.Value;

WriteValueCollection valuesToWrite = new WriteValueCollection();
valuesToWrite.Add(valueToWrite);

mSession.Write(null, valuesToWrite, out result, out diagnostics);

 

The same code works fine with another demo OPC UA Server which contains a real Variant Array node.

I have made other attemps with object array (mono and bidimensionals) and extension objects with no luck.

 

I assume I cannot understand what the real data type of the node (perhaps...because value is null?).

How can I retrieve the real data type to use? Could you help me please?

Thanks in advance for your reply.

Avatar
Randy Armstrong
Admin
Forum Posts: 270
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
09/04/2019 - 15:30
sp_Permalink sp_Print

You need to read the DataType and ValueRank of the Node and provide an instance that matches that exactly.

If the DataType is Structure (which is abstract) then it should accept any Structure.

You initialize a Variant with a Structure by wrapping it in a ExtensionObject.

e.g. new Variant(new ExtensionObject(new Range() { High = 100, Low = 1 }));

Avatar
Andrea OPC
Member
Members
Forum Posts: 6
Member Since:
07/19/2017
sp_UserOfflineSmall Offline
3
09/05/2019 - 00:17
sp_Permalink sp_Print sp_EditHistory

The DataType and ValueRank are visible in the UAExpert screenshot but I can retrieve the same values with the following code:

 

ReadValueIdCollection itemsToRead = new ReadValueIdCollection();

ReadValueId itemToRead1 = new ReadValueId();
itemToRead1.NodeId = "ns=2;i=115682";
itemToRead1.AttributeId = Attributes.DataType;
itemsToRead.Add(itemToRead1);

ReadValueId itemToRead2 = new ReadValueId();
itemToRead2.NodeId = "ns=2;i=115682";
itemToRead2.AttributeId = Attributes.ValueRank;
itemsToRead.Add(itemToRead2);

DataValueCollection values = null;
DiagnosticInfoCollection diagnosticInfos = null;
ResponseHeader responseHeader = m_Server.Session.Read(null,0,TimestampsToReturn.Both,itemsToRead,out values,out diagnosticInfos);

Results:
values[0]: i=24
values[1]: -1

i=24 is BaseDataType (namespace 0)

So it seem to be a scalar value I suppose...but I would expect an array or structure as shown in the manual.

Thanks.

Avatar
Randy Armstrong
Admin
Forum Posts: 270
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
09/05/2019 - 06:03
sp_Permalink sp_Print

The DataType and ValueRank are visible in the UAExpert screenshot but I can retrieve the same values with the following code:

I am not taking about the type associated with a variant value. I am talking about the value for the DataType and ValueRank attributes.

The value of these attributes tell you what you have to write.

Avatar
Andrea OPC
Member
Members
Forum Posts: 6
Member Since:
07/19/2017
sp_UserOfflineSmall Offline
5
09/05/2019 - 09:12
sp_Permalink sp_Print sp_EditHistory

I'm sorry but it's not clear to me...

 

With the code in my previous reply I read the value for the DataType and ValueRank attributes of the Node "ns=2;i=115682". Correct?

 

I notice the node has the reference HasTypeDefinition: ArbVTypeOrderList

 

TypeDefinition

 

If I read the value for the DataType and ValueRank attributes of this Node ("ns=2;i=906090") I obtain the same values i=24 and -1.

 

What am I doing wrong? Cry

Thanks.

Avatar
Randy Armstrong
Admin
Forum Posts: 270
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
6
09/05/2019 - 13:30
sp_Permalink sp_Print

Ok - so the a ValueRank = -1 is Scalar which means you cannot write an Array to the value. You can only write a scalar value.

DataType = BaseDataType means you can write any value as long as it is scalar.

I can see why it is confusing because the server appears to set the default value to an array which violates the contract specified by the DataType/ValueRank. If the Server wanted to allow arrays the ValueRank should be -2.

Avatar
Andrea OPC
Member
Members
Forum Posts: 6
Member Since:
07/19/2017
sp_UserOfflineSmall Offline
7
09/06/2019 - 00:25
sp_Permalink sp_Print

Therefore the ValueRank seems to be wrong. If the server set the default value to an array should be ok, according to the structure in the manual.

I think I cannot change ValueRank from client. It is a readonly attribute and I do not have access to the server.

If the server expects a scalar value I should be able to write an integer number for example but I tried all available scalar data types and I always receive BadTypeMismatch error.

What else could I try? 

I just don't known what to do...CryCryCry

Avatar
Randy Armstrong
Admin
Forum Posts: 270
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
8
09/06/2019 - 02:39
sp_Permalink sp_Print

You need to contact the Server vendor and explain the bug.

Have you tried an array of int[] instead of an Array of Variants?

int[] dataValue = { 1, 2, 3 };

You can try using an IndexRange to write a single element but I doubt that will work since you are still passing a 1 element array.

Avatar
Andrea OPC
Member
Members
Forum Posts: 6
Member Since:
07/19/2017
sp_UserOfflineSmall Offline
9
09/06/2019 - 08:40
sp_Permalink sp_Print sp_EditHistory

I've tried with int[] array but it doesn't work.

I've tried with IndexRange as you suggested using this code:

Array dataValue6 = Array.CreateInstance(typeof(Opc.Ua.Variant), 9);
dataValue6.SetValue(new Variant((UInt16)1), 0);
dataValue6.SetValue(new Variant((UInt32)2), 1);
dataValue6.SetValue(new Variant((string)"3"), 2);
dataValue6.SetValue(new Variant((string)"4"), 3);
dataValue6.SetValue(new Variant((string)"5"), 4);
dataValue6.SetValue(new Variant((string)"6"), 5);
dataValue6.SetValue(new Variant((string)"7"), 6);
dataValue6.SetValue(new Variant((string)"8"), 7);
dataValue6.SetValue(new Variant((string)"9"), 8);

DataValue dataValue1 = new DataValue() { Value = dataValue6 };
WriteValue valueToWrite = new WriteValue();
valueToWrite.Value = dataValue1;
valueToWrite.NodeId = nodeId;
valueToWrite.AttributeId = Attributes.Value;
valueToWrite.IndexRange = "0:8";

NumericRange indexRange;
ServiceResult result1 = NumericRange.Validate(valueToWrite.IndexRange, out indexRange);
object valueToWrite1 = valueToWrite.Value.Value;
result1 = indexRange.ApplyRange(ref valueToWrite1);
if (ServiceResult.IsGood(result1))
{
valueToWrite.Value.Value = valueToWrite1;
}

valuesToWrite.Add(valueToWrite);

mSession.Write(null, valuesToWrite, out result, out diagnostics);

 

"indexRange.ApplyRange" is ok but "mSession.Write" returns BadIndexRangeNoData

Avatar
Andrea OPC
Member
Members
Forum Posts: 6
Member Since:
07/19/2017
sp_UserOfflineSmall Offline
10
09/09/2019 - 01:19
sp_Permalink sp_Print

The only way it returns no error is with byte arrays (minimum two dimensions, one dimension gives error) but the target node remains empty.

For example:

Byte[,] byteArr = { { 1 }, { 2 }, { 3 } };

DataValue dataValue1 = new DataValue() { Value = byteArr };
WriteValue valueToWrite = new WriteValue();
valueToWrite.Value = dataValue1;
valueToWrite.NodeId = nodeId;
valueToWrite.AttributeId = Attributes.Value;

valuesToWrite.Add(valueToWrite);

mSession.Write(null, valuesToWrite, out result, out diagnostics);

Avatar
Randy Armstrong
Admin
Forum Posts: 270
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
11
09/09/2019 - 01:44
sp_Permalink sp_Print

You will need to contact the Server vendor. It is clear the Server is not behaving as it should according to the spec and there is no guarantee that a hack you find with trial and error will be consistently effective.

Forum Timezone: America/Phoenix
Most Users Ever Online: 143
Currently Online:
23
Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Newest Members:
podsvirov@sktz.ru
Forum Stats:
Groups: 2
Forums: 9
Topics: 565
Posts: 1611

 

Member Stats:
Guest Posters: 1
Members: 98694
Moderators: 10
Admins: 3
Administrators: michael.bryant@opcfoundation.org, thomas.burke@opcfoundation.org, Randy Armstrong
Moderators: matthias.damm@ascolab.com, s.hoppe@beckhoff.com, paul.hunkar@dsinteroperability.com, jouni.aro@prosys.fi, tim.fortin@honeywell.com, Jim.Luth@Schneider-Electric.com, Karl-Heinz Deiretsbacher, stefan.hoppe@opcfoundation.org, alexander.allmendinger@opcfoundation.org, Karl Deiretsbacher