Reading/writing custom structure to node

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
OskarN
Jr. Member
Jr. Member
Posts: 1
Joined: 06 Nov 2020, 09:13

Reading/writing custom structure to node

Post by OskarN »

Hi!

I have a problem regarding reading/writing structures to/from the OPC server.

The setup:
A B&R PLC running the OPC server.
The PLC defines a structure with two members, an integer and a boolean:
Image

A variable of this structure is enabled in the server. I can read/write to each of the members using UaExpert.

Image

Image

Now! For my client (.NET/C# application), I have defined a class:

Code: Select all

public class TestTyp
{   
  public int IntegerValue { get; set; }
  public bool BoolValue { get; set; }
}
First, I want my client to read this variable and cast the result to an object of this class (type).
Secondly, I want my client to be able to write an object of this class to the variable.
Such as the following pseudo code:

Code: Select all

TestTyp readValues = ReadVariable(node) as TestTyp;
TestTyp writeValues = new TestTyp(1338, true);
WriteVariable(writeValues);
How do I implement the methods ReadVariable and WriteVariable for generic types?

User avatar
Support Team
Hero Member
Hero Member
Posts: 3068
Joined: 18 Mar 2011, 15:09

Re: Reading/writing custom structure to node

Post by Support Team »

Since the structured DataType is known at compile time we recommend to use UAModeler to generated code for this DataType.
Please see the .NET Client HowTo in UaModeler documentation: http://documentation.unified-automation.com/uamodeler/1.6.4/html/howprojnetclientapplication_sec.html
Best regards
Unified Automation Support Team

zyhos
Jr. Member
Jr. Member
Posts: 1
Joined: 02 Dec 2020, 13:26

Re: Reading/writing custom structure to node

Post by zyhos »

thanks
You can resolve your error by using Structured Datatype and UA Modeler. If still, you don’t find the resolution regarding this https://bestwritingsclues.com/reviews/edubirdie-review/ can provide you assistance to resolve this reading and writing problem.

Post Reply