Skip to content

C++ tag/Port import

Is it possible to import tags using xml/csv without manually adding ports in C++. Here is a sample of the ports definition.

I do have a ton of tags (about 500 per say) and creating each tag is a tedious task. Just wondering if there is a better way to define the ports. Please help.

Comments

  • You can import variables into a PLCnext Engineer program from a CSV file, if you want (version 2022.3) :


    If you want to create the ports in a C++ program you could use the "dynamic GDS ports" feature, i.e. create ports in the program constructor, using information from a file (for example).

  • Thank you Martin for your prompt response.

  • How can I accessing the variable in the JSON object and use that in C++. I would like to modify the output based on input in C++. Example shows to write to input port variables using UA expert, but I would like to have that control in C++ .Please help.

  • If you add the port variables to a collection in the program constructor, like in the example, then you can reference individual elements in that collection in the C++ program. The "name" given to each dynamic port when it is created is stored in the GDS. If you want to refer to variables in a collection by the same name, then you could use something like a std::map and store the name of the port as the key.

  • Martin,

    Thank you! I was able to access the variables. The program structure already included the variables I need and i was able to use them in the code.

    One more question: Since the ports created are not visible on PLCNext, what is the best way for a modbus client to access these ports/tags? I can see its visible with OPC UA but would like to know if it can be accessed via modbubs/Rest api. Please help.

  • the ports created are not visible on PLCNext, ...

    That's not strictly true - the ports are "visible" in the Global Data Space at run-time, but they can't be seen in PLCnext Engineer at design-time.

    GDS port variables defined in C++ will be accessible via REST when the C++ Hmi port attribute (or perhaps a new Rest attribute?) is implemented. There is currently no indication if or when this will happen.

    Another possibility is to create GDS port variables in an IEC program in PLCnext Engineer, and then use a custom .gds.config file to link the IEC port variables to the C++ port variables, similar to what is shown at the end of the example in Github. The IEC port variables can then be marked with the "HMI" attribute, making them accessible via REST. The values in the IEC port variables can also be copied through a Modbus server block in a PLCnext Engineer project, making those values accessible to Modbus clients. Or, if you are writing your own Modbus server in any language, you could use the gRPC server to read and write GDS port data, using the DataAccess or Subscription gRPC services.

  • Thanks! Will try that out.

  • Martin,

    I tried creating IEC variables and and linking them to C++ variables. However, it does not work as expected. I have put some screenshots and what i am trying to achieve in the attached word document. I have also attached the output log for your reference.

    I am not sure if I am missing something obvious when i created the IEC variables. Please review the document and let me know what I am doing wrong. Thanks!

  • It is only allowed to connect OUT ports to IN ports. PLCnext Engineer enforces this restriction, but the .gds.config file shown in that document is trying to connect IN ports to IN ports, and OUT ports to OUT ports. That is probably the cause of the error shown in the Output.log file.

  • edited May 2022

    Martin, How would that work for assigning the IO ports? If I change the IN ports and Out ports now my IN00 is assigned to Sitting room light (which is an out port per the dynamic ports example). Can you help me understand how to make it work with using IEC variables, and have the same dynamic ports example work using gds config file.

    Does this only work one way. You can only assign IEC with C++ or C++ with the IO but not C++ --> IEC --> IO? Please advise.

  • It doesn't matter where a GDS port is defined (IO, C++ or IEC), it can be connected to any other port of the opposite type (i.e. OUT port to IN port).

    In your example, it looks like you want the same OUT port value (e.g. from Arp.Io.AxlC/0.IN00) to be copied to two IN port variables (e.g. both Arp.Plc.Eclr/DynamicPortsProgram1.Outside_mvt and DynamicPortsComponent1/DynamicPortsProgram1.Outside_movement). In that case, I would just connect the same OUT port variable (Arp.Io.AxlC/0.IN00) to both IN port variables, rather than trying to daisy-chain them - which will not work, as you have discovered.

    So the connection in PLCnext Engineer can stay the same, but the .gds.config file should change so that there are only OUT ports on the left (startPort), and only IN ports on the right (endPort).

  • Martin, I was able to get it working. I corrected the IN and OUT port variables in PLCNext Engineer and assigned them to the IO ports. My gds config assigns C++ variable to the IEC variable.

    Data flow works as expected and the variables are visible. I just want to make sure this is the right way to do it and I wont see any performance issues in the PLC.

Sign In or Register to comment.