CppExamples icon indicating copy to clipboard operation
CppExamples copied to clipboard

Dynamic Ports: Struct metadata can be generated automatically

Open martinboers opened this issue 3 years ago • 2 comments

The Dynamic Ports example lists the limitation that struct metadata is not generated automatically by the plcncli code generator.

It turns out that the //#typeinformation comment can be used to do just that.

The example should be updated to mention this.

martinboers avatar Aug 10 '22 13:08 martinboers

Could you provide a little more detail? I'm looking into creating dynamic ports from config file and I'd like to be able to use structs.

I am unable to find any documentation on this annotation.

ErikTempelaarVO avatar Aug 18 '23 14:08 ErikTempelaarVO

You're right, there is no documentation on this feature. I know that it's on the developer's list of things to do, but I don't know if/when it will be done.

Without testing it, something like this should work:

// Define the struct that will be used to declare port variables.
// The typeinformation attribute means that the plcncli will generate GDS metadata for this struct.
//#typeinformation
struct SampleStruct
{
   float64 ElemA;
   uint32 ElemB;
   uint16 ElemC;
   boolean ElemD;
};

You should then be able to create dynamic ports of this type, in a similar way to ports of elementary data types.

martinboers avatar Aug 18 '23 15:08 martinboers

This is now mentioned in the latest README file in the Dynamic Ports example.

martinboers avatar May 29 '25 08:05 martinboers