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.

Writing Array Values (OPC-UA)

More
20 Jun 2012 09:54 #904 by support
W.,
Thank you. Here are my findings:

1.<span style="font: 7pt "Times New Roman""> Yes, the TypeCode does not allow to specify an array. This is something I know about and should be addressed in a future version. Until this is ready, the plan was that in such case, the developer would be responsible for passing in the array of the precise type that the OPC server expects, i.e. the component would not convert the value before writing. This is done by specifying TypeCode.Object, or not specifying TypeCode at all. Since the Tag1 is an array of 16-bit words, the array should be created as an array of UInt16 elements, so the resulting code looks like this:

UInt16[] arrayValues = new UInt16[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
easyUAClient1.WriteValue("opc.tcp://localhost:49380", "nsu=TOP Server;s=Channel1.Device1.Tag1", arrayValues);

2.<span style="font: 7pt "Times New Roman""> There is, however, a problem inside the component that causes a conversion error anyway. I have fixed it now. You will therefore need a build 1.00.1263.1, which I will post later today.

3.<span style="font: 7pt "Times New Roman""> Note that there is also a mistake in your original code, where you create the arrayValues, but you still pass in just 123, not this array, to the Write call.

Best regards

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

More
20 Jun 2012 09:53 #903 by support
From: W.
Sent: Tuesday, June 19, 2012 11:06 PM
To: Zbynek Zahradnik
Subject: RE: OPC UA Write Error

Zbynek,

I changed Tag1 from Address R0001 to Address R0001[10]. Attached is the project for you.

Thanks,

W.

From: Zbynek Zahradnik
Sent: Tuesday, June 19, 2012 3:32 PM
To: W.
Subject: RE: OPC UA Write Error

Win, can you send me the TOP Server configuration, for this case? (I think this time Tag1 is configured differently, right? – and I want to be sure I give you a code that works with it).

From: W.
Sent: Tuesday, June 19, 2012 6:59 PM
To: Zbynek Zahradnik
Subject: RE: OPC UA Write Error

Zbynek,

[.....]. I am able to read an Array using the following code:
READING AN ARRAY
OpcLabs.EasyOpc.UA.UAAttributeData AttributeData;

//read the tag
AttributeData = easyUAClient1.Read("opc.tcp://localhost:49380", "nsu=TOP Server;s=Channel1.Device1.Tag1");

int[] arrayValues = (int[])AttributeData.Value;

//display the returned data to the user
listBox1.Items.Add(String.Format("Value: {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9} ", arrayValues[0], arrayValues[1], arrayValues[2], arrayValues[3], arrayValues[4], arrayValues[5], arrayValues[6], arrayValues[7], arrayValues[8], arrayValues[9]));
READING AN ARRAY

The problem comes when I want to Write to this array. The code is below. The problem is the arrayType is of type Object. There is no TypeCode for an Array. TOP Server rejects this with an OPC Exception with message “BadTypeMismatch” error in C# and in VB I get an “InvalidCastExpection”. Do you know of a work around to write to arrays?

WRITING AN ARRAY
UAAttributeData myData = new UAAttributeData(123, UASeverity.GoodOrSuccess, DateTime.Now, DateTime.Now);

int[] arrayValues = new int[10] {1,2,3,4,5,6,7,8,9,10};

TypeCode arrayType = Type.GetTypeCode(arrayValues.GetType());

easyUAClient1.Write("opc.tcp://localhost:49380", "nsu=TOP Server;s=Channel1.Device1.Tag1", new UAAttributeData(123, UASeverity.GoodOrSuccess), arrayType);
WRITING AN ARRAY


Thanks,

W.

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

Moderators: support
Time to create page: 0.055 seconds