Mingcedar

Product: Mingcedar Studio DESIGNER

Bit control: fixed writes, template reuse and status display | Mingcedar Studio

Use two pump control words to practice fixed writes, templates, dynamic targets and bit displays. Each example identifies its source page and script location.

Published Updated

<div class="manual-doc-article manual-doc-article-section"><h2 id="recipe-template-bit-write">Bit control tutorial: Bit control: fixed writes, template reuse and status display</h2>

Use two pump control words to practice fixed writes, templates, dynamic targets and bit displays. Each example identifies its source page and script location.

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

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-1">Preparation: control words, bit indices and pages</h3>

<p>A Tag is a data point configured in Mingcedar. An integer control word uses individual bits for different on/off states. Bit Index starts at 0. Set writes 1, Reset writes 0, and Toggle reverses the current bit. This tutorial assumes PLC_LINE01.PUMP01.CTRL_WORD and PLC_LINE01.PUMP02.CTRL_WORD are writable WORD (16-bit integer) Tags with good quality and initial value 0. Use bits 3 and 5 only on practice equipment; their real meaning comes from your device signal list.</p>

<ol>

<li>Finish example 1, then duplicate its page for later examples. Examples 2, 3 and 4 are separate target-selection approaches. Keep separate copies instead of combining every Page Script on one page.</li>

<li>Insert a rectangle in PowerPoint. Open MX Design → Behaviors → Browse, drag the named behavior from the right-hand catalog onto the component in the left-hand tree, then double-click the behavior to edit it.</li>

<li>For a Page Script example, open MX Design → Scripts → Page Script and use the current page&#39;s script document. For a Click Script example, use the button&#39;s Click Script behavior. Field lists are not JavaScript; do not paste them into a script pane.</li>

<li>Complete all steps in each example, save the PPT, and export the full package through MX Design → Export → Export HTML. Open the corresponding page in Mingcedar. Writes require a real interaction on the runtime page.</li>

</ol>

<p class="doc-step-result"><strong>Expected result</strong> The examples use WORD bits 3 and 5, corresponding to values 8 and 32. Expected integer changes assume an initial value of 0 and no concurrent writes from other programs.</p>

<ul class="doc-related-links">

<li><a href="/en/ppt/manual/first-screen/">First use: create and publish a screen</a></li>

</ul>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-2">Preparation: display both control-word values</h3>

<p>Insert text shapes labelled PUMP01 and PUMP02. Add Tag Text, set Target tag as shown and keep other defaults. Retain them in later page copies.</p>

<p class="doc-table-hint">Scroll horizontally to view the full table</p>

<div class="doc-table-scroll" role="region" aria-label="Preparation: display both control-word values" tabindex="0"><table class="doc-reference-table">

<thead><tr><th scope="col">Text shape</th><th scope="col">Target tag</th></tr></thead><tbody>

<tr><th scope="row">PUMP01</th><td>PLC_LINE01.PUMP01.CTRL_WORD</td></tr>

<tr><th scope="row">PUMP02</th><td>PLC_LINE01.PUMP02.CTRL_WORD</td></tr>

</tbody></table></div>

<p class="doc-step-result"><strong>Expected result</strong> After export, open the page in Mingcedar. Each text shape should show its control word’s current integer value. Confirm that both are 0 before continuing.</p>

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

<li>No value: check the Tag name and communication quality. Confirm readback before trying a write.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-3">Example 1: write a fixed target bit</h3>

<p>Add Write Tag Bit to the rectangle, configure the fields below and label it Set. Make two copies with captions and Actions Reset and Toggle. Bit Action below means Bit write → Action; Target Tag is the parent integer name without [3].</p>

<div class="manual-code" data-code-language="text"><div class="manual-code-toolbar"><span>Write Tag Bit → field settings (enter separately)</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: Write Tag Bit → field settings (enter separately)">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>Target Tag: PLC_LINE01.PUMP01.CTRL_WORD</span></span>

<span class="line"><span>Bit Index: 3</span></span>

<span class="line"><span>Bit Action: Set</span></span>

<span class="line"><span>Condition: true</span></span></code></pre></div>

<p class="doc-step-result"><strong>Expected result</strong> Click Set, Set, Reset, Toggle, Toggle, waiting for readback after each action. With initial parent value 0, expect 8, 8, 0, 8, 0. Set and Reset can be repeated; Toggle depends on the bit&#39;s value before the click.</p>

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

<li>Cannot save: remove [3] from Target Tag. Bit Index accepts an integer, not &lt;BIT&gt;, bitIndex or =bitIndex.</li>

<li>A click fails to write: verify that the target exists, is a writable integer, and has an available current value and good quality. Inspect the host&#39;s permission or write error.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-4">Example 2: configure two device template instances</h3>

<p>Duplicate example 1&#39;s page. Change Target Tag on all three buttons to &lt;PLC&gt;.&lt;PUMP&gt;.CTRL_WORD and keep Bit Index 3. &lt;PLC&gt; and &lt;PUMP&gt; are template placeholders filled when configuring an instance; they are not page variables that change during operation.</p>

<ol>

<li>Add a text shape for the device title and group it with the three buttons. Select the whole group, open MX Design → Templates → Library, and click Save selection. Enter Pump bit controls in Template name, confirm PLC and PUMP in Captured variables, and click Save.</li>

<li>After confirming the template was saved, remove the original placeholder group from this page. Save selection only saves to the library; it does not remove the original. Hiding it or moving it to another slide in the same PPT still includes it in a full export.</li>

<li>Double-click the Pump bit controls card twice. Select each whole instance group, open MX Design → Templates → Edit Instance, enter the Template variables below without quotes, and Save. Export, operate each button group, and inspect the two readback values configured earlier.</li>

</ol>

<div class="manual-code" data-code-language="text"><div class="manual-code-toolbar"><span>Template Edit → Template variables for two instances</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: Template Edit → Template variables for two instances">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>// Instance 1: Template variables</span></span>

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

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

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

<span class="line"><span>// Instance 2: Template variables</span></span>

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

<span class="line"><span>PUMP = PUMP02</span></span></code></pre></div>

<p class="doc-step-result"><strong>Expected result</strong> Instance 1 operates bit 3 of PLC_LINE01.PUMP01.CTRL_WORD. Instance 2 operates bit 3 of PLC_LINE01.PUMP02.CTRL_WORD. Their appearance and bit index match; their target devices differ.</p>

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

<li>Unresolved &lt;PLC&gt; or &lt;PUMP&gt; at export: check the selected instance root, Captured variables, and the saved values of both instances.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-5">Example 3: switch the target with a page variable</h3>

<p>Save a separate copy of example 1 with its ordinary buttons and put this code in Page Script. selectedControlTag holds a name string. HQVISU_DECLARE_TAGS lists candidate Tags for export dependencies; it creates neither Tags nor permissions.</p>

<ol>

<li>Set Target Tag on all three Write Tag Bit buttons to =selectedControlTag. Keep Bit Index 3. The leading = explicitly evaluates an expression; do not paste this field value into Page Script. The declaration&#39;s expression has no leading =.</li>

<li>Draw two selector buttons and add Interactions → Set Variable on Click. Set Variable to selectedControlTag on both. Set Value to &quot;PLC_LINE01.PUMP01.CTRL_WORD&quot; and &quot;PLC_LINE01.PUMP02.CTRL_WORD&quot;, including string quotes.</li>

<li>In the host, select PUMP02 and click Set; then select PUMP01 and click Set. Selection changes a page variable. The bit-write button submits the device operation.</li>

</ol>

<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>Page Script → example 3 target page (complete code)</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: Page Script → example 3 target page (complete code)">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:#D73A49">var</span><span style="color:#24292E"> selectedControlTag </span><span style="color:#D73A49">=</span><span style="color:#032F62"> "PLC_LINE01.PUMP01.CTRL_WORD"</span><span style="color:#24292E">;</span></span>

<span class="line"><span style="color:#6F42C1">HQVISU_DECLARE_TAGS</span><span style="color:#24292E">({</span></span>

<span class="line"><span style="color:#24292E"> expression: </span><span style="color:#032F62">"selectedControlTag"</span><span style="color:#24292E">,</span></span>

<span class="line"><span style="color:#24292E"> read: [</span><span style="color:#032F62">"PLC_LINE01.PUMP01.CTRL_WORD"</span><span style="color:#24292E">, </span><span style="color:#032F62">"PLC_LINE01.PUMP02.CTRL_WORD"</span><span style="color:#24292E">],</span></span>

<span class="line"><span style="color:#24292E"> write: [</span><span style="color:#032F62">"PLC_LINE01.PUMP01.CTRL_WORD"</span><span style="color:#24292E">, </span><span style="color:#032F62">"PLC_LINE01.PUMP02.CTRL_WORD"</span><span style="color:#24292E">]</span></span>

<span class="line"><span style="color:#24292E">});</span></span></code></pre></div>

<p class="doc-step-result"><strong>Expected result</strong> The same buttons operate PUMP02 and then PUMP01. Reopening the page restores the initial selection from Page Script.</p>

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

<li>The target does not change: check the Variable spelling, quoted Value, and = in Target Tag. Do not reinitialize selectedControlTag in a button&#39;s Setup Script. Add new devices to both the declaration and the selectors.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-6">Example 4A: pass the selected device from an entry page</h3>

<p>Copy example 3’s target page and remove device selectors. Set Page Code to pump_bits in MX Design → Page → Nav Path. On a separate entry page, give a button this Click Script to pass pump=PUMP02.</p>

<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>Click Script → entry page’s Open PUMP02 button</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: Click Script → entry page’s Open PUMP02 button">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:#D73A49">return</span><span style="color:#24292E"> hqVisuDesigner.</span><span style="color:#6F42C1">openPage</span><span style="color:#24292E">(</span><span style="color:#032F62">"pump_bits"</span><span style="color:#24292E">, {</span></span>

<span class="line"><span style="color:#24292E"> parameters: [{ key: </span><span style="color:#032F62">"pump"</span><span style="color:#24292E">, value: </span><span style="color:#032F62">"PUMP02"</span><span style="color:#24292E"> }]</span></span>

<span class="line"><span style="color:#24292E">});</span></span></code></pre></div>

<p class="doc-step-result"><strong>Expected result</strong> The target page receives the pump parameter. This does not change &lt;PUMP&gt; in Template Edit. Complete the next step to convert the parameter into a target name.</p>

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

<li>The target does not open: verify its actual Page Code and inclusion in the exported package. This script belongs on the entry button, not in the target page&#39;s Page Script.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-7">Example 4B: validate the page parameter and select a target</h3>

<p>Replace the entire pump_bits Page Script; do not append after the old initialization. Only the two configured devices are allowed. Missing or unknown parameters leave the target uninitialized, even if the page displays. Keep Target Tag =selectedControlTag and Bit Index 3 on all three buttons.</p>

<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>Page Script → pump_bits target page (replace existing script)</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: Page Script → pump_bits target page (replace existing script)">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:#D73A49">var</span><span style="color:#24292E"> pumpCode </span><span style="color:#D73A49">=</span><span style="color:#6F42C1"> GetPageParameter</span><span style="color:#24292E">(</span><span style="color:#032F62">"pump"</span><span style="color:#24292E">, </span><span style="color:#032F62">""</span><span style="color:#24292E">);</span></span>

<span class="line"><span style="color:#D73A49">if</span><span style="color:#24292E"> (pumpCode </span><span style="color:#D73A49">!==</span><span style="color:#032F62"> "PUMP01"</span><span style="color:#D73A49"> &#x26;&#x26;</span><span style="color:#24292E"> pumpCode </span><span style="color:#D73A49">!==</span><span style="color:#032F62"> "PUMP02"</span><span style="color:#24292E">) {</span></span>

<span class="line"><span style="color:#D73A49"> throw</span><span style="color:#D73A49"> new</span><span style="color:#6F42C1"> Error</span><span style="color:#24292E">(</span><span style="color:#032F62">"Open this page with PUMP01 or PUMP02 selected"</span><span style="color:#24292E">);</span></span>

<span class="line"><span style="color:#24292E">}</span></span>

<span class="line"><span style="color:#D73A49">var</span><span style="color:#24292E"> selectedControlTag </span><span style="color:#D73A49">=</span><span style="color:#032F62"> "PLC_LINE01."</span><span style="color:#D73A49"> +</span><span style="color:#24292E"> pumpCode </span><span style="color:#D73A49">+</span><span style="color:#032F62"> ".CTRL_WORD"</span><span style="color:#24292E">;</span></span>

<span class="line"><span style="color:#6F42C1">HQVISU_DECLARE_TAGS</span><span style="color:#24292E">({</span></span>

<span class="line"><span style="color:#24292E"> expression: </span><span style="color:#032F62">"selectedControlTag"</span><span style="color:#24292E">,</span></span>

<span class="line"><span style="color:#24292E"> read: [</span><span style="color:#032F62">"PLC_LINE01.PUMP01.CTRL_WORD"</span><span style="color:#24292E">, </span><span style="color:#032F62">"PLC_LINE01.PUMP02.CTRL_WORD"</span><span style="color:#24292E">],</span></span>

<span class="line"><span style="color:#24292E"> write: [</span><span style="color:#032F62">"PLC_LINE01.PUMP01.CTRL_WORD"</span><span style="color:#24292E">, </span><span style="color:#032F62">"PLC_LINE01.PUMP02.CTRL_WORD"</span><span style="color:#24292E">]</span></span>

<span class="line"><span style="color:#24292E">});</span></span></code></pre></div>

<p class="doc-step-result"><strong>Expected result</strong> Duplicate the entry button and change PUMP02 to PUMP01 in its code. Open each target and confirm its write through readback. Then temporarily change one entry parameter to PUMP99 and export again. Its bit-write buttons must not write a device. Restore the valid parameter afterwards.</p>

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

<li>Parameter error: the key must be pump, and the value must be exactly PUMP01 or PUMP02. Page parameters choose context; they are not proof of write permission.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-8">Example 5A: configure bit and action selectors</h3>

<p>Copy example 3 with its Page Script and selectors, then append these two lines. Replace the three Write Tag Bit buttons with an Execute button and Click Script; configure it next. Bit Index cannot take variables, so dynamic indices require the script API.</p>

<ol>

<li>Draw Bit 3 and Bit 5 selector buttons with Set Variable on Click. Set Variable to selectedBitIndex and Value to the numbers 3 and 5 without quotes.</li>

<li>Draw Set, Reset and Toggle selector buttons with Set Variable on Click. Set Variable to selectedBitAction and Value to &quot;Set&quot;, &quot;Reset&quot; and &quot;Toggle&quot;, including quotes.</li>

<li>These selectors only change variables. Execute submits one write. Do not also attach Write Tag Bit to the Execute button.</li>

</ol>

<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>Page Script → example 5 page (append at the end)</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: Page Script → example 5 page (append at the end)">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:#D73A49">var</span><span style="color:#24292E"> selectedBitIndex </span><span style="color:#D73A49">=</span><span style="color:#005CC5"> 3</span><span style="color:#24292E">;</span></span>

<span class="line"><span style="color:#D73A49">var</span><span style="color:#24292E"> selectedBitAction </span><span style="color:#D73A49">=</span><span style="color:#032F62"> "Set"</span><span style="color:#24292E">;</span></span></code></pre></div>

<p class="doc-step-result"><strong>Expected result</strong> The page holds three selections: device target, bit index and action. Changing them has not yet written to the device.</p>

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

<li>Undefined variable: append these lines to example 3&#39;s Page Script, not to a selector button&#39;s local script.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-9">Example 5B: validate and execute the write</h3>

<p>Put this code in Execute → Click Script. The example allows two devices, bits 3/5 and Set/Reset/Toggle. Pass variables directly, without = or quoted variable names.</p>

<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>Click Script → Execute button</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: Click Script → Execute button">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:#D73A49">if</span><span style="color:#24292E"> ([</span><span style="color:#032F62">"PLC_LINE01.PUMP01.CTRL_WORD"</span><span style="color:#24292E">, </span><span style="color:#032F62">"PLC_LINE01.PUMP02.CTRL_WORD"</span><span style="color:#24292E">].</span><span style="color:#6F42C1">indexOf</span><span style="color:#24292E">(selectedControlTag) </span><span style="color:#D73A49">&#x3C;</span><span style="color:#005CC5"> 0</span><span style="color:#24292E">) {</span></span>

<span class="line"><span style="color:#D73A49"> throw</span><span style="color:#D73A49"> new</span><span style="color:#6F42C1"> Error</span><span style="color:#24292E">(</span><span style="color:#032F62">"The device is not in the allowlist"</span><span style="color:#24292E">);</span></span>

<span class="line"><span style="color:#24292E">}</span></span>

<span class="line"><span style="color:#D73A49">var</span><span style="color:#24292E"> rawBit </span><span style="color:#D73A49">=</span><span style="color:#24292E"> selectedBitIndex;</span></span>

<span class="line"><span style="color:#D73A49">if</span><span style="color:#24292E"> ((</span><span style="color:#D73A49">typeof</span><span style="color:#24292E"> rawBit </span><span style="color:#D73A49">!==</span><span style="color:#032F62"> "number"</span><span style="color:#D73A49"> &#x26;&#x26;</span><span style="color:#D73A49"> typeof</span><span style="color:#24292E"> rawBit </span><span style="color:#D73A49">!==</span><span style="color:#032F62"> "string"</span><span style="color:#24292E">) </span><span style="color:#D73A49">||</span><span style="color:#6F42C1"> String</span><span style="color:#24292E">(rawBit).</span><span style="color:#6F42C1">trim</span><span style="color:#24292E">() </span><span style="color:#D73A49">===</span><span style="color:#032F62"> ""</span><span style="color:#24292E">) {</span></span>

<span class="line"><span style="color:#D73A49"> throw</span><span style="color:#D73A49"> new</span><span style="color:#6F42C1"> Error</span><span style="color:#24292E">(</span><span style="color:#032F62">"Select a valid bit index"</span><span style="color:#24292E">);</span></span>

<span class="line"><span style="color:#24292E">}</span></span>

<span class="line"><span style="color:#D73A49">var</span><span style="color:#24292E"> bit </span><span style="color:#D73A49">=</span><span style="color:#6F42C1"> Number</span><span style="color:#24292E">(rawBit);</span></span>

<span class="line"><span style="color:#D73A49">if</span><span style="color:#24292E"> (</span><span style="color:#D73A49">!</span><span style="color:#24292E">Number.</span><span style="color:#6F42C1">isInteger</span><span style="color:#24292E">(bit) </span><span style="color:#D73A49">||</span><span style="color:#24292E"> [</span><span style="color:#005CC5">3</span><span style="color:#24292E">, </span><span style="color:#005CC5">5</span><span style="color:#24292E">].</span><span style="color:#6F42C1">indexOf</span><span style="color:#24292E">(bit) </span><span style="color:#D73A49">&#x3C;</span><span style="color:#005CC5"> 0</span><span style="color:#24292E">) {</span></span>

<span class="line"><span style="color:#D73A49"> throw</span><span style="color:#D73A49"> new</span><span style="color:#6F42C1"> Error</span><span style="color:#24292E">(</span><span style="color:#032F62">"This page permits only bits 3 and 5"</span><span style="color:#24292E">);</span></span>

<span class="line"><span style="color:#24292E">}</span></span>

<span class="line"><span style="color:#D73A49">var</span><span style="color:#24292E"> action </span><span style="color:#D73A49">=</span><span style="color:#24292E"> selectedBitAction;</span></span>

<span class="line"><span style="color:#D73A49">if</span><span style="color:#24292E"> ([</span><span style="color:#032F62">"Set"</span><span style="color:#24292E">, </span><span style="color:#032F62">"Reset"</span><span style="color:#24292E">, </span><span style="color:#032F62">"Toggle"</span><span style="color:#24292E">].</span><span style="color:#6F42C1">indexOf</span><span style="color:#24292E">(action) </span><span style="color:#D73A49">&#x3C;</span><span style="color:#005CC5"> 0</span><span style="color:#24292E">) {</span></span>

<span class="line"><span style="color:#D73A49"> throw</span><span style="color:#D73A49"> new</span><span style="color:#6F42C1"> Error</span><span style="color:#24292E">(</span><span style="color:#032F62">"Select Set, Reset or Toggle"</span><span style="color:#24292E">);</span></span>

<span class="line"><span style="color:#24292E">}</span></span>

<span class="line"><span style="color:#D73A49">return</span><span style="color:#6F42C1"> WriteTagBit</span><span style="color:#24292E">(selectedControlTag, bit, action);</span></span></code></pre></div>

<p class="doc-step-result"><strong>Expected result</strong> Select PUMP02, bit 5 and Set, then Execute. From initial value 0, PUMP02 becomes 32 and PUMP01 remains unchanged. Select Reset and Execute again to return PUMP02 to 0. Bit 4, blank bit indices and unknown actions are rejected before submission.</p>

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

<li>A trusted-user-action error means writing must occur during a real user click. Do not write from Page Script initialization, color evaluation or a timer. The declaration still needs every possible selectedControlTag; an allowlist does not replace host authorization.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-10">Example 6A: read bit 3 with a status lamp and text</h3>

<p>Copy example 1, keep the write buttons, and add a lamp and text box. State Color and Tag Text show readback; the buttons submit writes.</p>

<ol>

<li>Add Visual States → State Color to the circle. Leave Setup Script empty and use the expression below in Condition. In Action, enable TRUE, FALSE and Fill color. Set TRUE to green #22C55E and FALSE to gray #94A3B8.</li>

<li>In State Color&#39;s Quality Override, select Follow data quality (border / hide) and set Bad to orange. A fallback false during bad quality is not confirmation that the device is stopped.</li>

<li>Add Text → Tag Text to the text box. Set Target tag to PLC_LINE01.PUMP01.CTRL_WORD[3], Fallback value to &quot;--&quot;, Prefix to &quot;Bit 3 = &quot; and Suffix to &quot;&quot;. This is a read target, so [3] belongs in its name.</li>

</ol>

<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>State Color → Condition</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: State Color → Condition">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:#6F42C1">ReadTagBoolean</span><span style="color:#24292E">(</span><span style="color:#032F62">"PLC_LINE01.PUMP01.CTRL_WORD[3]"</span><span style="color:#24292E">, </span><span style="color:#005CC5">false</span><span style="color:#24292E">)</span></span></code></pre></div>

<p class="doc-step-result"><strong>Expected result</strong> After Set and device readback, the lamp turns green and the text shows the bit&#39;s Boolean value. Reset makes the lamp gray. Even without the write buttons, an external parent-Tag update still changes the display.</p>

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

<li>Text shows the whole integer 8: add [3] to Target tag. A lamp never changes: check the bit-read Condition and enable both TRUE and FALSE. A parent Tag name alone is not a Boolean condition.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-11">Example 6B: let the display follow the dynamic device and bit</h3>

<p>Duplicate example 5 and copy in example 6A&#39;s lamp and text box. Keep its Page Script and append this read-only declaration. It covers two devices × two bits, for four bit-read names. Write declarations still contain only parent Tags.</p>

<ol>

<li>Change State Color&#39;s Condition to ReadTagBoolean(selectedControlTag + &quot;[&quot; + selectedBitIndex + &quot;]&quot;, false).</li>

<li>Change Tag Text&#39;s Target tag to =selectedControlTag + &quot;[&quot; + selectedBitIndex + &quot;]&quot; and Prefix to &quot;Selected bit = &quot;. The leading = belongs only in the target configuration field.</li>

<li>In the host, switch PUMP01/PUMP02 and bit 3/5. The selected bit&#39;s readback should appear without clicking Execute.</li>

</ol>

<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>Page Script → example 6B page (append read declaration)</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: Page Script → example 6B page (append read declaration)">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:#6F42C1">HQVISU_DECLARE_TAGS</span><span style="color:#24292E">({</span></span>

<span class="line"><span style="color:#24292E"> expression: </span><span style="color:#032F62">'selectedControlTag + "[" + selectedBitIndex + "]"'</span><span style="color:#24292E">,</span></span>

<span class="line"><span style="color:#24292E"> read: [</span></span>

<span class="line"><span style="color:#032F62"> "PLC_LINE01.PUMP01.CTRL_WORD[3]"</span><span style="color:#24292E">, </span><span style="color:#032F62">"PLC_LINE01.PUMP01.CTRL_WORD[5]"</span><span style="color:#24292E">,</span></span>

<span class="line"><span style="color:#032F62"> "PLC_LINE01.PUMP02.CTRL_WORD[3]"</span><span style="color:#24292E">, </span><span style="color:#032F62">"PLC_LINE01.PUMP02.CTRL_WORD[5]"</span></span>

<span class="line"><span style="color:#24292E"> ]</span></span>

<span class="line"><span style="color:#24292E">});</span></span></code></pre></div>

<p class="doc-step-result"><strong>Expected result</strong> Display and execution share the selection. Changing it changes what you observe; Execute submits the write.</p>

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

<li>Export cannot resolve the dynamic read target: match the declaration&#39;s expression to the concatenation used by both display behaviors, and include all four bit names in read. Do not put [3]/[5] names in write.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-12">Example 7A: set on press and reset on release</h3>

<p>Save a separate copy of example 1. Add Interactions → Press/Release Script to a new ordinary button. This behavior has no separate Condition. Use a fixed target and bit here so the device cannot change while held. Do not add Click Script or Write Tag Bit to the same button. Put the following code only in Pointer Press.</p>

<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>Press/Release Script → Pointer Press</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: Press/Release Script → Pointer Press">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:#D73A49">return</span><span style="color:#6F42C1"> WriteTagBit</span><span style="color:#24292E">(</span><span style="color:#032F62">"PLC_LINE01.PUMP01.CTRL_WORD"</span><span style="color:#24292E">, </span><span style="color:#005CC5">3</span><span style="color:#24292E">, </span><span style="color:#032F62">"Set"</span><span style="color:#24292E">);</span></span></code></pre></div>

<p class="doc-step-result"><strong>Expected result</strong> Press the button with the primary pointer&#39;s left button in Mingcedar. Bit 3 receives a Set request. Holding it does not automatically repeat the script.</p>

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

<li>No action: use a real primary-pointer press in the exported host page rather than the PowerPoint editing canvas, then inspect the host&#39;s press-write result.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-13">Example 7B: configure release and understand its limits</h3>

<p>Put the following code in Pointer Release of the same Press/Release Script behavior and save. Use Reset for release; Toggle is not a substitute for resetting. Add example 6A&#39;s status display and test pressing, releasing, and dragging outside before release.</p>

<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>Press/Release Script → Pointer Release</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: Press/Release Script → Pointer Release">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:#D73A49">return</span><span style="color:#6F42C1"> WriteTagBit</span><span style="color:#24292E">(</span><span style="color:#032F62">"PLC_LINE01.PUMP01.CTRL_WORD"</span><span style="color:#24292E">, </span><span style="color:#005CC5">3</span><span style="color:#24292E">, </span><span style="color:#032F62">"Reset"</span><span style="color:#24292E">);</span></span></code></pre></div>

<p class="doc-step-result"><strong>Expected result</strong> Normally bit 3 becomes 1 after press and 0 after release. The runtime also handles matching pointercancel and lostpointercapture release events. Receiving an event is not proof that equipment has reset.</p>

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

<li>Browser exit, page destruction, network loss or an uncertain host write result can prevent delivery of the release write. Equipment that needs hold-to-run or jog control must ensure its final reset through PLC timeouts, interlocks or other device-side mechanisms.</li>

</ul></div>

</article>

<article class="doc-card">

<h3 id="recipe-template-bit-write-item-14">Equipment application limits</h3>

<ul>

<li>Choose the index for the actual parent integer width: 0–7 for 8-bit, 0–15 for 16-bit, and 0–31 for 32-bit. Bit writing does not currently support 64-bit parent integers.</li>

<li>WriteTagBit returns the write result; displays use device readback. When several clients or PLC logic update one parent word, do not assume that every protocol guarantees an atomic bit write.</li>

<li>Template substitution, page variables, page parameters and allowlists have different purposes. Mingcedar still enforces device-write permissions, confirmation and auditing.</li>

</ul>

<ul class="doc-related-links">

<li><a href="/en/ppt/manual/write-tag-bit/">Write Tag Bit fields and API</a></li>

<li><a href="/en/ppt/manual/variables-tags-template-expressions/">Variables, Tags and template parameters</a></li>

<li><a href="/en/ppt/manual/state-color/">State Color reference</a></li>

<li><a href="/en/ppt/manual/press-release-script/">Press/Release Script reference</a></li>

</ul>

</article>

</div>

</div>