Product: Mingcedar Studio DESIGNER
Calculated Tags: read host results by name | Mingcedar Studio
ReadCalculatedTag(name, fallbackValue?) reads the latest available result of a published Mingcedar calculated Tag. Supply its saved name without selecting a PLC. The call does not execute the formula in the page.
<div class="manual-doc-article manual-doc-article-section"><h2 id="calculated-tag-read">Data access: Calculated Tags: read host results by name</h2>
ReadCalculatedTag(name, fallbackValue?) reads the latest available result of a published Mingcedar calculated Tag. Supply its saved name without selecting a PLC. The call does not execute the formula in the page.
<div class="doc-card-list">
<article class="doc-card">
<h3 id="calculated-tag-read-item-1">1. Method and supported fields</h3>
<p>Select Calculated Tag / Read in the function picker. Use the method in animation Value, Condition, Script Text, or page scripts. The global method and hqVisuDesigner.ReadCalculatedTag follow the same read rules.</p>
<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>ReadCalculatedTag("Line01TotalFlow")</span></span>
<span class="line"><span>ReadCalculatedTag("Line01TotalFlow", null)</span></span>
<span class="line"><span>ReadCalculatedTag("Line01Ready", false)</span></span>
<span class="line"><span>hqVisuDesigner.ReadCalculatedTag("Line01TotalFlow", null)</span></span></code></pre></div>
</article>
<article class="doc-card">
<h3 id="calculated-tag-read-item-2">2. Names and read-only behavior</h3>
<p>Use the name saved in the Mingcedar calculated Tag list. Line01TotalFlow requires no PLC or CALC prefix. If the saved name is Line01.TotalFlow, retain the full name. Calculated Tags have no write method and cannot serve as PLC Tag write targets for Input.</p>
<ul>
<li>Names are at most 128 characters. Use ASCII letters, digits, underscores, and separator dots; each segment starts with a letter or underscore.</li>
<li>Bit suffixes such as [0] are not supported.</li>
<li>An ordinary Tag with the same name is not read as a calculated result.</li>
<li>Renaming an unpublished draft does not change the active published name. Update page references after publishing the new name.</li>
</ul>
</article>
<article class="doc-card">
<h3 id="calculated-tag-read-item-3">3. Defaults and data quality</h3>
<p>A valid result with good quality returns a number or boolean, preserving 0 and false. Unloaded, unpublished, disabled, poor-quality, unauthorized, or unavailable subscriptions return the supplied default. Omitting the default returns null. A fallback supports display handling and is not a valid calculated result.</p>
<ul>
<li>Use null and display “--” when data is unavailable to distinguish it from a valid zero.</li>
<li>Use false when a condition requires a boolean fallback.</li>
<li>Use <code>ReadTagQuality("Line01TotalFlow")</code> to inspect quality. Data quality and process alarms have different meanings.</li>
</ul>
</article>
<article class="doc-card">
<h3 id="calculated-tag-read-item-4">4. Combine a template, a name variable, and a result variable</h3>
<p>Set template parameter CALCULATED_TAG to Line01TotalFlow. In Setup Script, store the replaced name in calculatedTagName, then read the result. Display Text formats the result. A template parameter used in several fields must satisfy every field's requirements. Use separate parameters, such as CALCULATED_TAG and SETPOINT_TAG, for calculated reads and PLC write targets. Enter Setup Script and Display Text in their respective fields.</p>
<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>JavaScript</span><span class="manual-code-tools"><small>JavaScript</small><button type="button" data-copy-code data-copied="Copied" data-failed="Select and copy the code" aria-label="Copy code: JavaScript">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:#6A737D">// Setup Script</span></span>
<span class="line"><span style="color:#D73A49">var</span><span style="color:#24292E"> calculatedTagName </span><span style="color:#D73A49">=</span><span style="color:#032F62"> "<CALCULATED_TAG>"</span><span style="color:#24292E">;</span></span>
<span class="line"><span style="color:#D73A49">var</span><span style="color:#24292E"> totalFlow </span><span style="color:#D73A49">=</span><span style="color:#6F42C1"> ReadCalculatedTag</span><span style="color:#24292E">(calculatedTagName, </span><span style="color:#005CC5">null</span><span style="color:#24292E">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// Script Text: Text</span></span>
<span class="line"><span style="color:#24292E">totalFlow </span><span style="color:#D73A49">===</span><span style="color:#005CC5"> null</span><span style="color:#D73A49"> ?</span><span style="color:#032F62"> "--"</span><span style="color:#D73A49"> :</span><span style="color:#24292E"> totalFlow.</span><span style="color:#6F42C1">toFixed</span><span style="color:#24292E">(</span><span style="color:#005CC5">1</span><span style="color:#24292E">) </span><span style="color:#D73A49">+</span><span style="color:#032F62"> " m³/h"</span></span></code></pre></div>
</article>
<article class="doc-card">
<h3 id="calculated-tag-read-item-5">5. Runtime verification</h3>
<p>Confirm that the host calculated Tag is published, enabled, and has good quality. Then check the page name and permissions. A dynamically supplied name must resolve to a full name string. Reads reuse host latest values and subscriptions without additional PLC polling.</p>
</article>
</div>
</div>