Search code examples
c#siemenstia-portal

How to retrieve Interface variables of a function block (FB) in TIA Portal Openness API?


I am working with the TIA Portal Openness API and trying to retrieve interface variables (like Input, Output, InOut) of a specific Function Block (FB). I have successfully accessed the block, but I am not sure how to proceed to get its interface variables. Here is the relevant part of my code:

Siemens.Engineering.HW.DeviceItem deviceItemToGetService = deviceItem as Siemens.Engineering.HW.DeviceItem;
SoftwareContainer softwareContainer1 = deviceItemToGetService.GetService<SoftwareContainer>();
if (softwareContainer1 != null)
{
    PlcSoftware software = softwareContainer1.Software as PlcSoftware;
    if (software != null)
    {
        _apiWrapper.PlcSoftwares.Add(software);
    }
}

if (_apiWrapper.PlcSoftwares[0].BlockGroup.Blocks.Find(_apiWrapper.ProjectTreeLeaf.Name) != null)
{
    _apiWrapper.ProjectSelectedPlcBlock = _apiWrapper.PlcSoftwares[0].BlockGroup.Blocks.Find(_apiWrapper.ProjectTreeLeaf.Name);
    Console.WriteLine($"TREE VIEW: SELECTED BLOCK = {_apiWrapper.ProjectSelectedPlcBlock.Name}");
    // How to get interface variables? What is in section Input, Output, InOut?
}

I am able to find the block and get its name, but I am stuck on how to access its interface variables. How can I list all interface variables from sections Inputs, Outputs, and InOuts?

I would appreciate any guidance or examples on how to achieve this using the TIA Portal Openness API.

Thank you in advance for your help!

Unfortunately, I wasn't able to find any informations on the Internet and chatGPT halucinating and make up new clasess :/


Solution

  • There is no way to do this directly yet (TIA/Openness v19). You must export the block as XML and then examine the interface section.

    See the export example at the bottom of this section: https://support.industry.siemens.com/cs/mdm/109826886?c=168247351179&lc=en-US

    Information on the XML structure of the interface section: https://support.industry.siemens.com/cs/mdm/109826886?c=157037369611&lc=en-US