C++ thread variable error

Hello, When i create a new port variable i get this error in the outputlog on the plcnext: Exception occurs while starting plc component ‘Arp.Plc.Plm’: Exception of type ‘Arp::System::Commons::InvalidOperationException’ was thrownException occurs while starting plc component ‘Arp.Plc.Plm’: Exception of type ‘Arp::System::Commons::InvalidOperationException’ was thrownCould not add data info as root in library ThreadExample: Local variable name ‘i_pCounter’ yet exists. i do not get this error if i declare it in MyProgram.hpp the port is decleared in the myComponents.hpp like this: //#port

//#attributes(Output|Retain)
//#name(i_pCounter)
int16 i_pCounter; I am using the ThreadExample code profided here: https://github.com/PLCnext/CppExamples/tree/master/Examples/ThreadExample Many thanks.

Hello royclappers, did you execute "plcncli generate code " && “plcncli generate config” before building the Application?# Which PLCnextCLI version are you using?

Which SDK version are you using?
Which FW version is your PLCnext Control at? sorry i just saw that it was a Component port.
Component ports are not declared like that.

Component ports are defined in the following way:  
>   //#port   
>    struct PORTS {               
>   //#name(NameOfPort)            
>   //#attributes(Input)     
>   Arp::boolean portField = false;    
>   // The GDS name is "/NameOfPort" if the struct is declared as Hidden          
>   // otherwise the GDS name is "/PORTS.NameOfPort"     
>    } ports;  
>    Create one (and only one) instance of this struct.        
>    Apart from this single struct instance, there must be no other Component variables declared with the #port comment.       
>    The only attribute that is allowed on the struct instance is "Hidden", and this is optional.    
>    The struct can contain as many members as necessary.     
>    The #name comment can be applied to each member of the struct, and is optional.    
>    The #name comment defines the GDS name of an individual port element. If omitted, the member variable name is used as the GDS name.    
>    The members of the struct can be declared with any of the attributes allowed for a Program port.

Complete Support for Component Ports will be provided in one of the next PLCnextCLI Versions.
Oliver

Hello Oliver, i have decleared the port like this: //#port

struct PORTS {
//#name(ArrayCode)
//#attributes(Output|Retain|Opc)
Arp::uint8 ArrayCode [21];
} ports; But on PLCNext Engineer it shows up like this (See attached file), and i can’t connect another port to the port, and it shows up as both a OUT port and IN port. Many thanks.

Hello, like I mentioned Component ports are not yet fully supported in the Engineering chain.

We hope to make this more convenient in the near future.

For now you will have to rebuild the Struct 1 to 1 in the PLCnext Engineer.

Same Name , Spelling, and Variable order.
Then you will be able to connect it.

I dont think Retain and OPC are supported at ComponentPorts yet.
This might cause some issues at code and config generation steps.
These issues should be removed with the upcoming release of the new PLCnextCLI at the end of this year. kind regards,
Oliver

Just to add to Oliver’s answer, there are some examples of using Component ports (with the current firmware version) here: https://www.plcnext-community.net/en/discussions-2-offcanvas/passing-c-array-of-structs-to-ports-fw-2019-6.html … and here: https://github.com/PLCnext/SampleRuntime/blob/master/getting-started/Part-10/README.md The second link shows a nasty hack that can be used to get Component Port variables to appear in the OPC UA server address space. But the best solution is to wait for the next release of the PLCnext CLI tool, as Oliver mentioned. - Martin.

My bad, I added a second call to SetupConfig somewhere in the code causing it too run the declarations twice, giving the error that the variable yet existed. But thanks for the fast replies! - Roy