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.

OPC UA .NET C# Reading to Array, License Problem

More
21 Sep 2022 18:24 #11114 by support
Thank you, it is much clearer now.

The Cam_Array is one-dimensional array of custom structures. In order to write to it, you will need the Complex Data feature.

But, from the expanded tree picture from the Connectivity Explorer, I can also see that (most likely) the same information that is available in single node (Cam_Array) is accessible through individual nodes. And, there are nodes for elements, such as Cam_Array[0] (these nodes will be structures), and nodes for individual fields of the structures (such as the dA node under Cam_Array[0] ). So, your second option might be without Complex Data types: Simply do multiple "simple" Write-s, with the individual node IDs, and individual field values.

For efficiency, this should be done with WriteMultipleValues method, and not with looping and writing each node individually.

Best regards
The following user(s) said Thank You: amlynar

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

More
21 Sep 2022 17:54 #11112 by amlynar
I have attached the photos of the requested information.


Attachments:

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

More
21 Sep 2022 15:40 #11110 by support
Thank you.

It looks like that the server does not support subscriptions to attributes other than the Value attribute, so you have resolved it perfectly by using the Read instead.

Unfortunately the "Value" column is too narrow to show the full DataType. Can you please make it wider so that the DataType can be seen in its entirety?

But I can already see two possible problems:

- The ValueRank indicates that the node is one-dimensional array (and, it has 101 elements, according to the ArrayDimensions attribute). But you are trying to write a 2-dimensional array to it. Note that instead of 2-dimensional array of Byte-s, there can also be an array of arrays (so-called jagged array) - which, on the first level, is a one-dimensional array. It would probably be represented as "Byte[][]" instead of "Byte[,]" in .NET. However, there is second issue, so this is probably not the case anyway:

- Although I could not see the full DataType, I can already see it is some custom data type (the namespace, indicated by the "nsu=", shows that the data type is not in namespace 0, which contains the types defined by the OPC Foundation). So, unless that type is based on Byte (which is unlikely - and we can verify that after you send the full DataType), you have an incorrect element type - it will not be Byte, but something else - probably a custom structure - for which you will need the Complex Data feature.

Regards

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

More
21 Sep 2022 12:58 #11109 by amlynar
I used the ConnectivityExplorer. When I hit the "Add Row" it gave an error message, but if I hit the read button it produced results. I attached both photos. The first row is DataType, the second is ValueRank, the third is ArrayDimensions.
Attachments:

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

More
21 Sep 2022 10:09 #11107 by support
Hello,

judging from "byte[,] byteArray ", you are trying to write a 2-dimensional array of Byte-s, correct? We need to verify that the variable has this data type in the server. Can you please obtain the DataType, ValueRank and ArrayDimensions attribute values of the Cam_Array node? Either using some short code, or from an interactive OPC client. ConnectivityExplorer can be used, too: Select the node, then switch to the Inspect tab, select the AttributeId you want, and press "Add Row" then.

Regards

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

More
20 Sep 2022 18:34 #11105 by amlynar
Code Snippet:
public void WriteCamArrayToPAC()
{
List<CamItem> camItems = RmgSegmentDataConverter.ToCamItems(SegmentList);
byte[,] byteArray = CamArrayConverter.ConvertCamListToByteArray(camItems);

OpcClient opcClient = OpcClient.Get();
opcClient.WriteToTag(Tags.GenV_Cam_Array, byteArray);

byte[] camRefByteArray = (byte[]) opcClient.ReadTag(Tags.GenV_Cam_Ref);

CamRef camRef = CamArrayConverter.ConvertByteArrayToCamRef(camRefByteArray);

camRef.nElements = (short) camItems.Count;
camRef.xStart = camItems.Count > 0 ? camItems[0].dX : 0;
camRef.xEnd = camItems.Count > 0 ? camItems[camItems.Count - 1].dX : 0;

camRefByteArray = CamArrayConverter.ConvertCamRefToByteArray(camRef, camRefByteArray);
opcClient.WriteToTag(Tags.GenV_Cam_Ref, camRefByteArray);
}

// OPC UA Write function within OpcClient Class
public void WriteToTag(string nodeId, object value)
{
int attempts = 0;
while (IsInitialized && attempts++ < MAX_RETRY_ATEMPTS)
{
try
{
easyUAClient1.WriteValue(Tags.ENDPOINT_DESCRIPTOR, nodeId, value);
attempts = MAX_RETRY_ATEMPTS;
}
catch (UAException e)
{
Log.E(TAG, e.ToString());
}
}
}

// OPC UA Read function within OpcClient Class
public object ReadTag(string nodeId)
{
object ret = null;
if(IsInitialized)
{
int attempts = 0;
UAException uaException = null;
while (attempts++ < MAX_RETRY_ATEMPTS)
{
try
{
ret = easyUAClient1.ReadValue(Tags.ENDPOINT_DESCRIPTOR, nodeId);
attempts = MAX_RETRY_ATEMPTS;
}
catch (UAException e)
{
uaException = e;
Log.E(TAG, e.ToString());
}
}
if (ret == null)
{
throw uaException;
}
}
return ret;
}

This is the code that I am trying to get to run. It worked perfectly fine with the OPC DA functions but not for the OPC UA. As I was converting my program from DA TO UA this is the only part that breaks. I also attached a photo of Cam_Ref for DA
Attachments:

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

More
20 Sep 2022 18:14 #11104 by support
For Cam_Array, please provide the code snippet doing the Write.

For Cam_Ref, show me that some other OPC UA client can read or write it (its Value attribute). I do not think this is the case. I have explained that it is an Object, and UA Objects do not have values. You are asking for something that is not possible.

Regards

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

More
20 Sep 2022 17:56 #11103 by amlynar
1. Cam_Array I want to write to the tag.
2. Cam_Ref I want to write and read to it.

Sorry for the confusion, I should have stated more properly.

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

More
20 Sep 2022 17:42 #11102 by support
I thought we are talking about Write-s, because you write "...error I receive when I try to write to the array.".
However, in your last post, you have provided a code snippet that calls ReadValue.
Please clarify.

Also, Cam_Ref is an OPC UA Object, so that explains why it does not have a Value attribute and you cannot read from it.

Regards

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

More
20 Sep 2022 17:37 #11101 by amlynar
The arrays are byte[ , ] and byte[ ]. I am sending the correct data type that they use, but it still refuses to work. This is the error I receive when trying to run the code below.

easyUAClient1.ReadValue(opc.tcp://192.168.10.50:4840/, nsu=CODESYSSPV3/3S/IecVarAccess ;ns=4;s=|var|B-Nimis MC-Pi Prime S01.Application.GenV.Cam_Ref);

UAStatusCodeException: Status is not good: {BadAttributeIdInvalid}. The attribute is not supported for the specified Node.
+ The attribute Id used was 'Value'.
+ The node descriptor used was: NodeId="nsu=CODESYSSPV3/3S/IecVarAccess ;ns=4;s=|var|B-Nimis MC-Pi Prime S01.Application.GenV.Cam_Ref".
+ The client method called (or event/callback invoked) was 'ReadMultiple[1]'.
Attachments:

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

Moderators: support
Time to create page: 0.067 seconds