Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WriteSwitchField #198

Open
tmoers opened this issue Jan 4, 2025 · 6 comments
Open

WriteSwitchField #198

tmoers opened this issue Jan 4, 2025 · 6 comments

Comments

@tmoers
Copy link

tmoers commented Jan 4, 2025

Hi,

I defined a union type

<opc:DataType SymbolicName="PlcReadoutValue" BaseType="ua:Union" IsUnion="true">
    <opc:Fields>
        <opc:Field Name="Bool" DataType="ua:Boolean" ValueRank="Scalar" />
        <opc:Field Name="Int32" DataType="ua:Int32" ValueRank="Scalar" />
    </opc:Fields>
</opc:DataType>

And the generated code requires IEncoder to have the method WriteSwitchField which isn't
defined.

Am I doing something wrong?

Best regards,

Tom

@opcfoundation-org
Copy link
Contributor

Which version of the ModelCompilier are you using?

@tmoers
Copy link
Author

tmoers commented Jan 5, 2025

I was using an older version first and that one resulted in something similar to a regular structure, with all the fields of the union available. So then I updated to the latest tag 2.6.0:

https://github.com/OPCFoundation/UA-ModelCompiler/tree/2.6.0

The generated code looked promising with the additional switchfield. Unfortunately, it doesn't compile. Maybe I need some additional package?

@opcfoundation-org
Copy link
Contributor

That version should be linking to a preview version of the SDK. Can you build the Debug version which builds the SDK from source?

@opcfoundation-org
Copy link
Contributor

The DemoModel links fine and it has a Union.

SwitchField = (SampleUnionFields)decoder.ReadSwitchField(typeof(SampleUnionFields));

I would like figure out why there is an issue on your machine.

@tmoers
Copy link
Author

tmoers commented Jan 6, 2025

I checked the DemoModel and that indeed compiles fine. The difference is that I have the following reference:

<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua" Version="1.5.374.118" />

When I change this to what the demo model uses:

<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Core" Version="1.5.377-preview.ga511586173" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Server" Version="1.5.377-preview.ga511586173" />

It also compiles. Unfortunately, reading the values (using UaExpert) now results in the following error:

Internal Error: UaGenericStructureValue::setGenericValue returned BadEncodingLimitsExceeded

image

@opcfoundation-org
Copy link
Contributor

A lot of things to check:

  1. DataTypeDefinition Attribute for the DataType Node. It should have correct Union definition;
  2. Confirm your server is setting the SwitchField and ExtensionObject.TypeId correctly.

If those look fine it may be worth writing a simple client using pre-compiled classes and verifying that works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants