How to set I/O values in siemens PLC Device?

884 views Asked by At

I am creating a Web API for a local network in the .net framework(C#). In that user can import/export IO Tags from excel or set them as a static string array. I have added (Siemens.Engineering.Hmi.dll) but still, it shows a not found compile-time error.

We have also connected to TIAPortal and it works well the only roadblocks are I/O tags import/export or set static values and HMISoftware.

  • Project: Web API(.Net Framework 4.6.1)

  • Tia Portal: v16.0

  • License Type: Trial

Kindly revert me if anyone have idea or any suggestion. It would be highly appriciated.

2

There are 2 answers

0
Andras On

The issue you are experiencing is that (most probably) you didn't set the copy local property of the referenced Siemens.Engineering.Hmi.dll to false. So, the dependencies of the referenced Siemens.Engineering.Hmi.dll cannot be found. As a remark: add the Siemens.Engineering.dll as a reference besides Siemens.Engineering.Hmi.dll

Having a not-local-assembly then requires AssemblyResolving. The simplest way of doing it is to use the App.config file.

Please see this page from Siemens about this topic: support.industry.siemens.com

The second issue I see is the access of Tags. As you most certainly know, there are HMI Tags and PLC Tags. Accessing them is possible through the respective DeviceItems. These DeviceItems expose different Services. You can access the Services through the <YourEngineeringObject>.GetService<T>() method. In this case you will need the SoftwareContainer service.

To become familiar with the data model of TIA Openness, please have a look at the TIA Openness Explorer

Also, to deepen your understanding of working with TIA Openness, please refer to SIMATIC TIA Portal Openness: API for automation of engineering workflows

0
Sean Li On

The solution I'm importing IO tags is to use .xml files

Its advantage is that it can access and set the properties of IO tags, such as IO tagstable's name, datatypename, externalaccessible, externalvisible, externalwritable, logicaladdress, tagName, comment.

For Example .xml

<?xml version="1.0" encoding="utf-8"?>
<Document>
  <Engineering version="V16" />
  <SW.Tags.PlcTagTable ID="0">
    <AttributeList>
      <Name>IO Table</Name>
    </AttributeList>
    <ObjectList>
      <SW.Tags.PlcTag ID="1" CompositionName="Tags">
        <AttributeList>
          <DataTypeName>Bool</DataTypeName>
          <ExternalAccessible>true</ExternalAccessible>
          <ExternalVisible>true</ExternalVisible>
          <ExternalWritable>true</ExternalWritable>
          <LogicalAddress>%I0.0</LogicalAddress>
          <Name>Tag</Name>
        </AttributeList>
        <ObjectList>
          <MultilingualText ID="2" CompositionName="Comment">
            <ObjectList>
              <MultilingualTextItem ID="3" CompositionName="Items">
                <AttributeList>
                  <Culture>en-US</Culture>
                  <Text>Tag</Text>
                </AttributeList>
              </MultilingualTextItem>
            </ObjectList>
          </MultilingualText>
        </ObjectList>
      </SW.Tags.PlcTag>   
    </ObjectList>
  </SW.Tags.PlcTagTable>
</Document>

You only need to modify the tags attribute in. XML, including the ID value. For example, first tag ID = 1, and the second tag ID = 2.ID's value is not repeatable!

For Example .cs

var fileInfo = new FileInfo(@"IO MAP.xml");

SoftwareContainer softwareContainer = Project.Devices[0].DeviceItems[1].GetService<SoftwareContainer>();
Software softwareBase = softwareContainer.Software;
PlcSoftware plcSoftware = softwareBase as PlcSoftware;
PlcTagTableGroup PlcTagTableGroup = plcSoftware.TagTableGroup;

PlcTagTableGroup.TagTables.Import(fileInfo, ImportOptions.Override);

You only need to modify the target of SoftwareContainer , which depends on the PLC model you use, in the case of s7-1516.

If you have any questions, please contact me。