Mingcedar

Product: Mingcedar CONTROL

Calculated Tags: from formula to runtime value | Mingcedar

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

Published Updated

<div class="manual-doc-article manual-doc-article-section"><h2 id="calculated-tags">Operating guide: Calculated Tags: from formula to runtime value</h2>

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.

<div class="doc-card-list doc-tutorial">

<article class="doc-card">

<h3 id="calculated-tags-item-1">1. Prepare an identified input</h3>

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

<ol>

<li>Verify the local raw-pressure Tag’s value, quality, and range in Tag Test; record Device Code and Tag Code.</li>

<li>Before creating, publishing, or toggling a calculated Tag, confirm that the account has the corresponding permission.</li>

<li>Open Tag Management → Calculated Tags and click New calculated Tag.</li>

</ol>

<p class="doc-step-result"><strong>Expected result</strong> The input and permissions are established and the editor is open. Formulas reference local IO or published calculated Tags without directly accessing a PLC.</p>

</article>

<article class="doc-card">

<h3 id="calculated-tags-item-2">2. Choose the Tag and enter a formula</h3>

<p>The editor maintains stable TagRefs; UUID entry or extra aliases are normally unnecessary.</p>

<ol>

<li>Set Calculated Tag name to PressureMPa. Use letters, digits, underscores, and separator dots; spaces and hyphens are not allowed.</li>

<li>Click Choose Tag, select the local PLC / Device on the left, then the raw-pressure Tag on the right.</li>

<li>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.</li>

<li>Set numeric display to 2 decimal places. This changes display only, not internal precision.</li>

<li>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.</li>

</ol>

<p class="doc-step-result"><strong>Expected result</strong> Check the binding and divisor: raw 2500 should produce 0.25 MPa.</p>

</article>

<article class="doc-card">

<h3 id="calculated-tags-item-3">3. Save, publish, and enable</h3>

<p>Save draft persists edits. Publication creates a defined version; enablement starts runtime calculation.</p>

<ol>

<li>Save draft stores edits without changing the runtime version.</li>

<li>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.</li>

<li>Inspect the published generation and enabled state. If published but not enabled, follow the reported guidance and choose Enable and start calculation.</li>

<li>Click Refresh result under Calculation result and inspect value, quality, and evaluation time.</li>

</ol>

<p class="doc-step-result"><strong>Expected result</strong> Input 2500 should produce 0.25. Check other values using the same ratio, plus quality and time.</p>

<div class="doc-step-troubleshooting"><p><strong>If the result differs</strong></p><ul>

<li>Save failure: inspect field findings for name, input, and syntax.</li>

<li>Invalid result: check input quality, then formula, publication, and enablement.</li>

<li>Revision conflict: refresh and reconcile other edits before changing the definition.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="calculated-tags-item-4">4. Add an alarm to the calculated result</h3>

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

<ol>

<li>Click Alarm on the published PressureMPa row, then Add rule.</li>

<li>Choose a condition matching the result type, enter the required threshold, and select an alarm category number defined in Settings.</li>

<li>If needed, set recovery deadband and trigger delay in Advanced settings, keeping units consistent with MPa.</li>

<li>Enable the rule, click Save alarm rule, and inspect the listed condition.</li>

<li>Observe alarm state. If result quality is poor, inspect quality and rule state along with the last value.</li>

</ol>

<p class="doc-step-result"><strong>Expected result</strong> Check rule persistence and alarm activation separately.</p>

</article>

<article class="doc-card">

<h3 id="calculated-tags-item-5">5. Record calculated-result history</h3>

<p>The Trend button manages history recorded from the calculated result.</p>

<ol>

<li>Click Trend on the same row and inspect whether recording is off.</li>

<li>Click Record history to use the automatically selected recommended policy.</li>

<li>For an explicit policy, expand Advanced trend settings, choose the policy and deadband, then save.</li>

<li>After runtime starts, confirm Recording and select the calculated result and time range in historical trends.</li>

<li>Use Stop recording to stop. Publishing a revised formula does not rewrite previously recorded history.</li>

</ol>

<p class="doc-step-result"><strong>Expected result</strong> Recorded intervals contain results; periods before recording are not backfilled.</p>

</article>

<article class="doc-card">

<h3 id="calculated-tags-item-9">6. Read from Python or a screen</h3>

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

<ol>

<li>Open Script Workbench → Code, choose the Project, create scripts/read_calculated.py, paste the code below, and save.</li>

<li>Use the calculated Tag name actually saved in the list; PressureMPa is the example here.</li>

<li>With that file selected, click Run Test. If the file is modified, the action is Save &amp; Test. Compare the console result with the calculated-Tag list.</li>

<li>In Mingcedar Studio expressions, use ReadCalculatedTag(&quot;PressureMPa&quot;) and handle null for unpublished, disabled, unauthorized, or invalid-quality results.</li>

</ol>

<div class="manual-code" data-code-language="python"><div class="manual-code-toolbar"><span>scripts/read_calculated.py</span><span class="manual-code-tools"><small>Python</small><button type="button" data-copy-code data-copied="Copied" data-failed="Select and copy the code" aria-label="Copy code: scripts/read_calculated.py">Copy code</button><span class="manual-code-status" role="status"></span></span></div><pre tabindex="0" class="docs-code-block shiki github-light" style="background-color:#fff;color:#24292e" tabindex="0"><code><span class="line"><span style="color:#24292E">value </span><span style="color:#D73A49">=</span><span style="color:#24292E"> ReadCalculatedTag(</span><span style="color:#032F62">"PressureMPa"</span><span style="color:#24292E">, </span><span style="color:#005CC5">None</span><span style="color:#24292E">)</span></span>

<span class="line"><span style="color:#D73A49">if</span><span style="color:#24292E"> value </span><span style="color:#D73A49">is</span><span style="color:#005CC5"> None</span><span style="color:#24292E">:</span></span>

<span class="line"><span style="color:#D73A49"> raise</span><span style="color:#005CC5"> RuntimeError</span><span style="color:#24292E">(</span><span style="color:#032F62">"Calculated value is unavailable"</span><span style="color:#24292E">)</span></span>

<span class="line"><span style="color:#005CC5">print</span><span style="color:#24292E">(value)</span></span></code></pre></div>

<p class="doc-step-result"><strong>Expected result</strong> Python output matches the calculated result. Ordinary Tag SDK methods and IO State V2 SignalRefs do not automatically become calculated-Tag interfaces.</p>

</article>

<article class="doc-card">

<h3 id="calculated-tags-item-10">7. Revise the formula and diagnose errors</h3>

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

<ol>

<li>Edit the definition using input and operator pickers. Boolean expressions use &amp;&amp;, ||, and !; conditional results can use if(condition, yes, no).</li>

<li>Define the business behavior for a possible zero divisor instead of masking invalid measurements with zero.</li>

<li>Save and republish, then inspect the new published version, quality and evaluation time.</li>

<li>Resolve incompatible alarm rules before changing result type. Address alarm/history definitions and dependencies before deleting the calculated Tag.</li>

</ol>

<p class="doc-step-result"><strong>Expected result</strong> Confirm the new version is running, then check input quality, division, reference and dependency errors.</p>

</article>

<article class="doc-card">

<h3 id="calculated-tags-item-6">Permission reference: view, edit, publish, and enable</h3>

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

<ul>

<li>calculated-tag:view: inspect definitions, values, and diagnostics.</li>

<li>calculated-tag:manage: create, edit, and save drafts.</li>

<li>calculated-tag:publish: publish a calculation version.</li>

<li>calculated-tag:enable: enable or disable a runtime version.</li>

</ul>

</article>

<article class="doc-card">

<h3 id="calculated-tags-item-7">Numeric verification: pressure scaling</h3>

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

<ul>

<li>Raw 0 → 0 MPa; 2500 → 0.25 MPa; 10000 → 1 MPa.</li>

<li>When input quality is unavailable, inspect output quality and evaluation time. Do not present an old value as currently valid.</li>

<li>After recovery, check input freshness and evaluation time before confirming the displayed result.</li>

</ul>

</article>

<article class="doc-card">

<h3 id="calculated-tags-item-8">Expression reference: combined states and zero denominators</h3>

<p>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.</p>

<ul>

<li>With run command true and fault false, the first formula returns true. With fault true, it returns false.</li>

<li>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.</li>

<li>These are calculation expressions, not Python. They do not import modules, access databases, or perform writes.</li>

</ul>

<div class="manual-code" data-code-language="text"><div class="manual-code-toolbar"><span>Text</span><span class="manual-code-tools"><small>Text</small><button type="button" data-copy-code data-copied="Copied" data-failed="Select and copy the code" aria-label="Copy code: Text">Copy code</button><span class="manual-code-status" role="status"></span></span></div><pre tabindex="0" class="docs-code-block shiki github-light" style="background-color:#fff;color:#24292e" tabindex="0"><code><span class="line"><span>PumpPLC.RunCommand &#x26;&#x26; !PumpPLC.FaultActive</span></span>

<span class="line"><span></span></span>

<span class="line"><span>if(PumpPLC.TotalCount > 0, PumpPLC.GoodCount / PumpPLC.TotalCount * 100, 0)</span></span></code></pre></div>

</article>

</div>

</div>