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.