Writing to Siemens tag structure via OPC connection

I am hoping someone can point me/us in the right direction, or offer up some suggestions. We are attempting to write date and time to a Siemens PLC over OPC. For some reason we can only write the “seconds” value, when we try multiple tags everything stops writing. Here’s the setup…

  1. We have OPC connections to Siemens S7 PLCs that we need to write the date and time to. Tags in Siemens are structures with DTL datatype.

  2. When we import them they show up as Document datatype with a JSON value.

  3. We setup UDT with Derived tags using Read and Write jsonGet({source},{TagName}) and jsonSet({source},{TagName},{value}) expressions

  4. We have a derived [System]Gateway/CurrentDateTime tag that triggers the script on changeValue

  5. Script uses system.data.get functions to pull each item that needs to written to derived tags which sets to the JSON
    ts = system.date.now()
    day = system.date.getDayOfMonth(ts)
    hour = system.date.getHour24(ts)
    minute = system.date.getMinute(ts)
    month = system.date.getMonth(ts)+1
    sec = system.date.getSecond(ts)
    weekDay =system.date.getDayOfWeek(ts)
    year = system.date.getYear(ts)

    tagPaths = [
    “…myPath to derived tag…/Day”,
    “…myPath to derived tag…/Hour”,
    “…myPath to derived tag…/Minute”,
    “…myPath to derived tag…/Month”,
    “…myPath to derived tag…/Second”,
    “…myPath to derived tag…/Year”
    ]
    values = [day, hour, minute, month, sec, year]
    system.tag.writeBlocking(tagPaths, values)

  6. When only 1 path and 1 value it works!! ie seconds

  7. When multiple paths and values are written it fails
    We have tried;
    system.tag.writeAsync(tagPaths, values)
    system.tag.writeBlocking(tagPaths, values)
    trigger tag in tag folder, as a UDT and Gateway Timer Script - they all produced the same result… 1 tag, 1 value will update, multiple will not

This is a strategy that we are looking to use for various data structures between the Ignition and the Siemens PLCs

Anyone have an idea of what is happening, wondering if we should be looking at a different approach.

I think you missed the step where you turn on Optimistic Writes for the Tag Group these tags belong to.

1 Like

You are amazing!! Thank you!

Kevin, the Optimistic Writes worked but I am thinking we may be missing else… In the same setup as above, we are finding that if a tag script writes values, the Tag Group Optimistic Write timeout and value changes back to PLC’s value, “0” in this case. The PLC never gets the value… but here’s the crazy thing… I have a debug view with sliders binding to the same tags, when they are modified the writes are seen on the PLC… The script updates the derived tags, JSON values to the OPC tags, all the visualizations but not in the PLC. Any thoughts on what I maybe missing or where to go looking for the issue?

In the settings for the Tag Provider these tags belong to in the gateway, can you try enabling the “Allow Backfill Data” advanced setting and see if that changes anything? If so, we have a ticket open about quick successive writes using system.tag.write* requiring this be enabled, which seems to be a regression of some sort, probably introduced with these backfill changes.

no luck… this case the tags values never see my script write value