Skip to content

Calculated Tags: from formula to runtime value

The example converts a raw range of 0–10000 to 0–1 MPa. Use this factor only when the point map defines that range.

Operating guide

Operating guide: Calculated Tags: from formula to runtime value

Choose a local numeric input, author a formula, publish and enable it, then configure alarms and trends. Calculated results are read-only numbers or booleans.

1. Prepare an identified input

The example converts a raw range of 0–10000 to 0–1 MPa. Use this factor only when the point map defines that range.

  1. Verify the local raw-pressure Tag’s value, quality, and range in Tag Test; record Device Code and Tag Code.
  2. Before creating, publishing, or toggling a calculated Tag, confirm that the account has the corresponding permission.
  3. Open Tag Management → Calculated Tags and click New calculated Tag.

Expected result The input and permissions are established and the editor is open. Formulas reference local IO or published calculated Tags without directly accessing a PLC.

2. Choose the Tag and enter a formula

The editor maintains stable TagRefs; UUID entry or extra aliases are normally unnecessary.

  1. Set Calculated Tag name to PressureMPa. Use letters, digits, underscores, and separator dots; spaces and hyphens are not allowed.
  2. Click Choose Tag, select the local PLC / Device on the left, then the raw-pressure Tag on the right.
  3. The picker inserts Device Code.Tag Code as the formula input name and binds it to a stable TagRef. Append / 10000 after that input name.
  4. Set numeric display to 2 decimal places. This changes display only, not internal precision.
  5. Check the conversion ratio against the point map. When changing the input, choose it again from the catalog so its formula name and binding agree.

Expected result Check the binding and divisor: raw 2500 should produce 0.25 MPa.

3. Save, publish, and enable

Save draft persists edits. Publication creates a defined version; enablement starts runtime calculation.

  1. Save draft stores edits without changing the runtime version.
  2. To run the new definition, click Save, publish, and enable. With publication permission only, the action is Save and publish; an account with enablement permission can then enable it.
  3. Inspect the published generation and enabled state. If published but not enabled, follow the reported guidance and choose Enable and start calculation.
  4. Click Refresh result under Calculation result and inspect value, quality, and evaluation time.

Expected result Input 2500 should produce 0.25. Check other values using the same ratio, plus quality and time.

If the result differs

  • Save failure: inspect field findings for name, input, and syntax.
  • Invalid result: check input quality, then formula, publication, and enablement.
  • Revision conflict: refresh and reconcile other edits before changing the definition.

4. Add an alarm to the calculated result

The Alarm button in the calculated-Tag list configures result alarms without another PLC read.

  1. Click Alarm on the published PressureMPa row, then Add rule.
  2. Choose a condition matching the result type, enter the required threshold, and select an alarm category number defined in Settings.
  3. If needed, set recovery deadband and trigger delay in Advanced settings, keeping units consistent with MPa.
  4. Enable the rule, click Save alarm rule, and inspect the listed condition.
  5. Observe alarm state. If result quality is poor, inspect quality and rule state along with the last value.

Expected result Check rule persistence and alarm activation separately.

5. Record calculated-result history

The Trend button manages history recorded from the calculated result.

  1. Click Trend on the same row and inspect whether recording is off.
  2. Click Record history to use the automatically selected recommended policy.
  3. For an explicit policy, expand Advanced trend settings, choose the policy and deadband, then save.
  4. After runtime starts, confirm Recording and select the calculated result and time range in historical trends.
  5. Use Stop recording to stop. Publishing a revised formula does not rewrite previously recorded history.

Expected result Recorded intervals contain results; periods before recording are not backfilled.

6. Read from Python or a screen

Use the dedicated ReadCalculatedTag method with the saved name exactly; do not prepend a PLC or CALC prefix.

  1. Open Script Workbench → Code, choose the Project, create scripts/read_calculated.py, paste the code below, and save.
  2. Use the calculated Tag name actually saved in the list; PressureMPa is the example here.
  3. With that file selected, click Run Test. If the file is modified, the action is Save & Test. Compare the console result with the calculated-Tag list.
  4. In Mingcedar Studio expressions, use ReadCalculatedTag("PressureMPa") and handle null for unpublished, disabled, unauthorized, or invalid-quality results.
scripts/read_calculated.pyPython
value = ReadCalculatedTag("PressureMPa", None)
if value is None:
    raise RuntimeError("Calculated value is unavailable")
print(value)

Expected result Python output matches the calculated result. Ordinary Tag SDK methods and IO State V2 SignalRefs do not automatically become calculated-Tag interfaces.

7. Revise the formula and diagnose errors

Formulas use Mingcedar expression syntax and cannot import Python, execute SQL, or write to PLCs.

  1. Edit the definition using input and operator pickers. Boolean expressions use &&, ||, and !; conditional results can use if(condition, yes, no).
  2. Define the business behavior for a possible zero divisor instead of masking invalid measurements with zero.
  3. Save and republish, then inspect the new published version, quality and evaluation time.
  4. Resolve incompatible alarm rules before changing result type. Address alarm/history definitions and dependencies before deleting the calculated Tag.

Expected result Confirm the new version is running, then check input quality, division, reference and dependency errors.

Permission reference: view, edit, publish, and enable

If an action is unavailable, check the current account permission and calculated-Tag state.

  • calculated-tag:view: inspect definitions, values, and diagnostics.
  • calculated-tag:manage: create, edit, and save drafts.
  • calculated-tag:publish: publish a calculation version.
  • calculated-tag:enable: enable or disable a runtime version.

Numeric verification: pressure scaling

These values describe the 0–10000 to 0–1 MPa formula on this page. Display precision does not change the calculation.

  • Raw 0 → 0 MPa; 2500 → 0.25 MPa; 10000 → 1 MPa.
  • When input quality is unavailable, inspect output quality and evaluation time. Do not present an old value as currently valid.
  • After recovery, check input freshness and evaluation time before confirming the displayed result.

Expression reference: combined states and zero denominators

PumpPLC is an example Device code. Insert your project’s input names using the Tag picker, then add the operators. The two lines below are separate formulas.

  • With run command true and fault false, the first formula returns true. With fault true, it returns false.
  • With 95 good units and 100 total units, the second formula returns 95. This example returns 0 for a zero total; label “no samples” separately from an actual zero yield in the business page.
  • These are calculation expressions, not Python. They do not import modules, access databases, or perform writes.
TextText
PumpPLC.RunCommand && !PumpPLC.FaultActive

if(PumpPLC.TotalCount > 0, PumpPLC.GoodCount / PumpPLC.TotalCount * 100, 0)

Click the image again or press Esc to close