Set a value for a NON IEncodeable event field

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

Moderator: uasdknet

Post Reply
uonabi
Jr. Member
Jr. Member
Posts: 1
Joined: 29 Jul 2021, 15:34

Set a value for a NON IEncodeable event field

Post by uonabi »

Hi,
I created a new Variable type called "VarStat" derived from "Types\VariablesType\BaseDataVariableType\DataItemType\BaseAnalogType\AnalogItemType".
VarStat is Double data type and has 3 children: Avg , Max, Min (all Double data type):

VARIABLE TYPE DEFINITION:
VarStat (Double)
Variable - Avg - BaseDataVariableType (TypeDefinition) - Double (DataType)
Variable - Min - BaseDataVariableType (TypeDefinition) - Double (DataType)
Variable - Max - BaseDataVariableType (TypeDefinition) - Double (DataType)

Then I created an event called "LogEvent" with the parameter "NewValue" of "VarStat" type:

EVENT DEFINTION:
NewValue
Variable - NewValue - VarStat (TypeDefinition) - Double (DataType)

In the .Net source code, I call the event and set the value for event field by:
e.Set(e.ToPath(new QualifiedName("2:NewValue"),NewValueVar)
where NewValueVar is a VarStatModel variable.

I have this error:
"Argument 2: cannot convert from VarStatModel to UnifiedAutomation.UABase.IEncodeable"

If I call
e.Set(e.ToPath(new QualifiedName("2:NewValue"),NewValueVar.Value)
the code is without error but the event (in UAExpert) return only the VarStat value (Double) without Avg, Min and Max.

The question is:
How I can set an NON IEncodeable event field ?
Note in the .Net source code I create the tag with :
VarStatModel NewValueVar = new VarStatModel ();
It is not a VarStatType, because it is Double (TypeDefnition is VarStat).

I hope I was clear.
Thanks

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

Re: Set a value for a NON IEncodeable event field

Post by Support Team »

Hello,

Variant does not have a constructor having a Model class as argument. Please use the value of the model (maybe you have to cast the Value to double, depending on your implementation) and pass it to the constructor.
Best regards
Unified Automation Support Team

Post Reply