How to change dynamically the source tag path of a Reference Tag

Hi,

I’m trying to dynamically build the source tag path of a Reference Tag.

I have been reading this post but I cannot make it work.

I have a UDT, Probe_UDT, with a tag to read temperature, PV:

Probe_UDT
{
  "name": "Probe_UDT",
  "typeId": "",
  "tagType": "UdtType",
  "tags": [
    {
      "name": "01_Inputs",
      "tagType": "Folder",
      "tags": [
        {
          "opcItemPath": {
            "bindType": "parameter",
            "binding": "ns\u003d1;s\u003d[Sample_Device]_Meta:Ramp/Ramp{TankNumber}"
          },
          "valueSource": "memory",
          "expression": "dateExtract(now(), \"sec\")",
          "dataType": "Float4",
          "historyProvider": "IGN_Historian",
          "name": "PV",
          "historyEnabled": false,
          "tagType": "AtomicTag",
          "opcServer": "Ignition OPC UA Server"
        }
      ]
    }
  ]
}

I have mobile tanks that can get their temperature reading from a different probe, depending their position. So I have a UDT, CoolTank_UDT, to handle tanks. One of the fields is a reference tag. I would like to change dynamically its “Source Tag Path” to point the relevant temperature probe.

I tried to build the “Source Tag Path” at the reference tag, but it didn’t work; the expression wasn’t executing. So I added an expression tag to build the probe tag path and added the expression tag in the “Source Tag Path” of the reference tag. But it doesn’t work neither.

PV_Path expression tag expression:
{[.]TankPath} + "/" + {[.]Probe} + "/01_Inputs/PV"

CookTank_UDT Jason definition:

CookTank_UDT

{
  "name": "CoolTank_UDT",
  "typeId": "",
  "tagType": "UdtType",
  "tags": [
    {
      "name": "01_Inputs",
      "tagType": "Folder",
      "tags": [
        {
          "valueSource": "memory",
          "dataType": "String",
          "name": "Probe",
          "tagType": "AtomicTag"
        },
        {
          "valueSource": "expr",
          "expression": "{[.]TankPath} + \"/\" + {[.]Probe} + \"/01_Inputs/PV\"",
          "dataType": "String",
          "name": "PV_Path",
          "tagType": "AtomicTag"
        },
        {
          "valueSource": "memory",
          "dataType": "String",
          "name": "TankPath",
          "tagType": "AtomicTag"
        },
        {
          "sourceTagPath": {
            "bindType": "parameter",
            "binding": "{[.]PV_Path}"
          },
          "valueSource": "reference",
          "dataType": "Float4",
          "name": "PV",
          "tagType": "AtomicTag"
        }
      ]
    }
  ]
}

Example:
Probe tag:

Tank tag: PV_Path has the right path to Probe1 PV, but Tank 1 PV SourceTagPath doesn’t get the value of PV_Path (I have tried with [.]PV_Path, without the {} too, with the same result):


If I harcoded the value in PV_Path in the “Source Tag Path” of the reference tag (PV), it works.
Do you know why the “Source Tag Path” doesn’t get compiled?

Can you try adding tag() function in your PV_Path tag expression?

So in your case it should be like tag([default]Probes/Probe1/01_Inputs/PV).

Thank you for your reply.
I tried as you said but I had these errors:

PV_Path expression now:
"tag(" + {[.]TankPath} + "/" + {[.]Probe} + "/01_Inputs/PV)"

PV_Path value:
tag([default]Probes/Probe1/01_Inputs/PV)

If PV reference tag “Source Tag Path”:

[.]PV_Path

PV reference tag quality:
Error_TypeConversion("Error trying to coerce 'tag([default]Probes/Probe1/01_Inputs/PV)' to a number.")

I don’t know why it happened this error as: [default]Probes/Probe1/01_Inputs/PV is a Float and Quality is good.

If PV reference tag “Source Tag Path”:

{[.]PV_Path}

PV reference tag quality:
Error_Configuration

Your PV_Path should be a string:

PV_Path.value = tag('[default]Probes/Probe1/01_Inputs/PV')

And PV should be a Float. With this setup, it should work correctly.

Make sure PV_Path is enclosed in quotes when assigning its value.

Thanks again for you quick reply.

I confirm that PV_Path is data type String; the value source is expression.

I have updated the expression to get the value that you indicated:

"tag('"+ {[.]TankPath} + "/" + {[.]Probe} + "/01_Inputs/PV')"

PV_Path.value = tag('[default]Probes/Probe1/01_Inputs/PV')

I confirm that:

PV in the CoolTank _UDT is data type Float and value source Reference

PV in the probe type is data type Float and value source Memory

If I hardcode the Source Tag Path to PV in the CoolTank_UDT:
[default]Probes/Probe1/01_Inputs/PV

it works:

I don't know it doesn't work when I add the string value from PV_Path

Tag configuration parameters like source tag path cannot bind to tags. They can only bind to UDT parameters. Only actual expression tags can freely bind to anything.

You will need to use a script to write to that configuration property when necessary.

Caveat: Alarm properties can also bind to anything, but are only executed on alarm events. They do not track any references.

Thank you very much.
This script worked:

path = "[default]Tanks/Tank1/01_Inputs/PV.SourceTagPath"
value = "[default]Probes/Probe1/01_Inputs/PV"
system.tag.writeBlocking(path,value)

Thanks again to Gaurav and pturmel.