Facility Control

 View Only
  • 1.  Adding elements to a struct array

    Posted 03-13-2019 04:14
    I've got a struct array defined with a couple elements in it. I'd like to programatically add more elements to the array.

    I've tried something like:

    params.setValue("dstList.15.vd",0,"25");

    but when I run an

    ogscript.debug("15: " + params.getValue("dstList.15.vd",0))

    the output is 15 null

    It works as expected if I access array element 1.

    When I run a params.getElementCount before and after supposedly adding elements to the struct array the result is the same both times.

    What am I missing? Is there a better way to do this?


  • 2.  RE: Adding elements to a struct array

    Posted 03-14-2019 20:11
    Let's say you have a struct array called "dstList" and you currently have 15 elements in it it (indices 0-14).

    If I have 2 string-based sub-parameters "vd" and "ad", I would add the 16th element like this:

    params.setValue('dstList', 15, {"vd": "25", "ad":"25"});
    #DashBoard


  • 3.  RE: Adding elements to a struct array

    Posted 04-06-2019 18:47

    Hey James, I've finally gotten back to this and it's working great.  I'm having difficulty getting values to show now though.

    I do the following:

    <param fill="both" insets="4,0,4,0" oid="dstList.0.vs" widget="text-display"/>

    and it gives me nothing.  I know there's a value there, I can get it in a script via a getParam.

    Also, the new forum layout, not such a fan.  Plus somehow my previous forum profile now is Erik Barone.  How'd that happen?


    #DashBoard


  • 4.  RE: Adding elements to a struct array

    Posted 04-08-2019 17:45

    Hi Erik.

    If the element exists in your array at the time the panel is built, it should should appear correctly in the UI.

    If the element is created afterwards, the panel would need to reload at least part of the UI for the new element to appear.

    You might try turning-off the 'text-display' (just remove the 'widget' attribute) if 'dstList.0.vs' is not a primitive param type.

    If you are still stuck and are able to post your panel, we may  be able to help you further.

    I have also passed your feedback on the new forum software to our web team.

    Cheers.

    James


    #DashBoard


  • 5.  RE: Adding elements to a struct array

    Posted 04-11-2019 01:05

    I threw together a smaller sub panel that should illustrate what I've got going on (without lots of extra stuff).

    I've pasted it in below.  Is there no way to do a code block in this new software?  The editor doesn't have that as an option.  Seems like it's time for a revert!

    Hopefully the panel is pretty self-explanatory.

    <abs contexttype="opengear" id="_top">
    <meta>
    <api>function checkLookup() {
    for (var i = 0; i &lt; params.getElementCount("dstList"); i++) {
    ogscript.debug(i + " rtr: " + params.getValue("dstList."+i+".rtr",0));
    ogscript.debug(i + " vd: " + params.getValue("dstList."+i+".vd",0));
    ogscript.debug(i + " ac: " + params.getValue("dstList."+i+".ac",0));
    ogscript.debug(i + " vs: " + params.getValue("dstList."+i+".vs",0));
    }
    }

    function buildLookup() {
    ogscript.debug("in size " + params.getElementCount("dstList"));
    var dests = [
    [1,59,2],
    [1,60,0]
    ];
    for (var i = 0; i &lt; dests.length; i++) {
    params.setValue("dstList", i, {"rtr": parseInt(dests[i][0]), "vd": parseInt(dests[i][1]), "ac": parseInt(dests[i][2])});
    if ((parseInt(dests[i][2]) &gt; 0) &amp;&amp; (parseInt(dests[i][0]) == 1)) {
    params.setValue("dstList", i, {"a1d": parseInt(dests[i][3]),"a2d": parseInt(dests[i][4])});
    }
    }
    ogscript.debug("out size " + params.getElementCount("dstList"));
    }

    function updateSRC() {
    for (var i = 0; i &lt; params.getElementCount("dstList"); i++) {
    ogscript.debug('updateSRC ' + i);
    params.setValue("dstList",i, {"vs" : "Test " + i});
    }
    }</api>
    <params>
    <param access="1" constrainttype="STRUCT" name="Router Destination Info Template" oid="dstListTemplate" structtype="dstListTemplate" type="STRUCT" widget="table">
    <value>
    <subparam access="1" constraingtype="INT_NULL" name="Router" precision="0" suboid="rtr" type="INT16" value="0" widget="default"/>
    <subparam access="1" constrainttype="INT_NULL" name="Video Destination" precision="0" suboid="vd" type="INT16" value="0" widget="default"/>
    <subparam access="1" constrainttype="INT_NULL" name="Audio Channels" precision="0" suboid="ac" type="INT16" value="0" widget="default"/>
    <subparam access="1" maxlength="-1" name="Video Source" stateless="true" suboid="vs" type="STRING" value="None" widget="default"/>
    </value>
    </param>
    <param access="1" constrainttype="STRUCT" name="Router Destination Info" oid="dstList" stateless="true" structtype="dstListTemplate" templateoid="dstListTemplate" type="STRUCT_ARRAY" widget="table"/>
    </params>
    <context contexttype="opengear" id="Ultrix.1" objectid="Ultrix-50198224007&lt;br&gt;Slot 0&lt;br&gt;Ultrix" objecttype="Ultrix"/>
    </meta>
    <button buttontype="push" height="40" left="10" name="Build" top="10" width="100">
    <task tasktype="ogscript">buildLookup();</task>
    </button>
    <button buttontype="push" height="40" left="120" name="Update" top="10" width="100">
    <task tasktype="ogscript">updateSRC();</task>
    </button>
    <button buttontype="push" height="40" left="230" name="Check" top="10" width="100">
    <task tasktype="ogscript">checkLookup();</task>
    </button>
    <table left="10" top="60">
    <tr>
    <blank height="40" width="40"/>
    <label name="Source 1" style="txt-align:center" width="200"/>
    <label name="Source 2" style="txt-align:center" width="200"/>
    </tr>
    <tr>
    <label height="40" name="rtr" style="txt-align:center"/>
    <param element="0" expand="true" oid="dstList.0.rtr" widget="1"/>
    <param element="0" expand="true" oid="dstList.1.rtr" widget="1"/>
    </tr>
    <tr>
    <label height="40" name="vd" style="txt-align:center"/>
    <param element="0" expand="true" oid="dstList.0.vd" widget="1"/>
    <param element="0" expand="true" oid="dstList.1.vd" widget="1"/>a
    </tr>
    <tr>
    <label height="40" name="ac" style="txt-align:center"/>
    <param element="0" expand="true" oid="dstList.0.ac" widget="1"/>
    <param element="0" expand="true" oid="dstList.1.ac" widget="1"/>
    </tr>
    <tr>
    <label height="40" name="vs" style="txt-align:center"/>
    <param element="0" expand="true" oid="dstList.0.vs" widget="1"/>
    <param element="0" expand="true" oid="dstList.1.vs" widget="1"/>
    </tr>
    </table>
    </abs>


    #DashBoard


  • 6.  RE: Adding elements to a struct array

    Posted 04-11-2019 13:35

    Thanks, Erik - I'll take a look.

    As for code blocks, you can do them in the new software - you just need to select the little menu at the left of the toolbar.


    #DashBoard


  • 7.  RE: Adding elements to a struct array

    Posted 04-11-2019 14:17

    Hi Erik.

    The issue you are experiencing is because the parameter entries do not exist at the time your panel is loaded. If you add new elements to your struct and want to show them in the UI, you will need to reload that part of the UI.

    The only time you wouldn't is if you are showing the entire struct as a table parameter - this may be the best option for you.

    Another issue you will experience with your panel:

    If you add an entry to a struct without all sub-OIDs, the sub-OIDs that were not defined in your new entry will be removed.  There is an option to turn this feature off by making your parameter 'additive'.  I'm attaching an example that shows displaying your struct as a table parameter instead of a <table/> tag and uses the 'additive' feature to retain all sub-OIDs.

     

    <abs contexttype="opengear" id="_top">
    <meta>
    <api immediate="true">function checkLookup() {
    for (var i = 0; i &lt; params.getElementCount("dstList"); i++) {
    ogscript.debug(i + " rtr: " + params.getValue("dstList."+i+".rtr",0));
    ogscript.debug(i + " vd: " + params.getValue("dstList."+i+".vd",0));
    ogscript.debug(i + " ac: " + params.getValue("dstList."+i+".ac",0));
    ogscript.debug(i + " vs: " + params.getValue("dstList."+i+".vs",0));
    }
    }

    function buildLookup()
    {
    ogscript.debug("in size " + params.getElementCount("dstList"));
    var dests = [
    [1,59,2],
    [1,60,0]
    ];
    for (var i = 0; i &lt; dests.length; i++)
    {
    params.setValue("dstList", i, {"rtr": parseInt(dests[i][0]), "vd": parseInt(dests[i][1]), "ac": parseInt(dests[i][2])});
    if ((parseInt(dests[i][2]) &gt; 0) &amp;&amp; (parseInt(dests[i][0]) == 1))
    {
    params.setValue("dstList", i, {"a1d": parseInt(dests[i][3]),"a2d": parseInt(dests[i][4])});
    }
    }
    ogscript.debug("out size " + params.getElementCount("dstList"));
    }

    function updateSRC() {
    for (var i = 0; i &lt; params.getElementCount("dstList"); i++) {
    ogscript.debug('updateSRC ' + i);
    params.setValue("dstList",i, {"vs" : "Test " + i});
    }
    }</api>
    <params>
    <param access="1" constrainttype="STRUCT" name="Router Destination Info Template" oid="dstListTemplate" structtype="dstListTemplate" type="STRUCT" widget="table">
    <config key="p.additive">true</config>
    <value>
    <subparam access="1" constraingtype="INT_NULL" name="Router" precision="0" suboid="rtr" type="INT16" value="0" widget="default"/>
    <subparam access="1" constrainttype="INT_NULL" name="Video Destination" precision="0" suboid="vd" type="INT16" value="0" widget="default"/>
    <subparam access="1" constrainttype="INT_NULL" name="Audio Channels" precision="0" suboid="ac" type="INT16" value="0" widget="default"/>
    <subparam access="1" maxlength="-1" name="Video Source" stateless="true" suboid="vs" type="STRING" value="None" widget="default"/>
    </value>
    </param>
    <param access="1" constrainttype="STRUCT" name="Router Destination Info" oid="dstList" stateless="true" structtype="dstListTemplate" templateoid="dstListTemplate" type="STRUCT_ARRAY" widget="table"/>
    </params>
    <context contexttype="opengear" id="Ultrix.1" objectid="Ultrix-50198224007&lt;br&gt;Slot 0&lt;br&gt;Ultrix" objecttype="Ultrix"/>
    </meta>
    <button buttontype="push" height="40" left="10" name="Build" top="10" width="100">
    <task tasktype="ogscript">buildLookup();</task>
    </button>
    <button buttontype="push" height="40" left="120" name="Update" top="10" width="100">
    <task tasktype="ogscript">updateSRC();</task>
    </button>
    <button buttontype="push" height="40" left="230" name="Check" top="10" width="100">
    <task tasktype="ogscript">checkLookup();</task>
    </button>
    <table left="10" top="60">
    <tr>
    <blank height="40" width="40"/>
    <label name="Source 1" style="txt-align:center" width="200"/>
    <label name="Source 2" style="txt-align:center" width="200"/>
    </tr>
    <tr>
    <label height="40" name="rtr" style="txt-align:center"/>
    <param element="0" expand="true" oid="dstList.0.rtr" widget="1"/>
    <param element="0" expand="true" oid="dstList.1.rtr" widget="1"/>
    </tr>
    <tr>
    <label height="40" name="vd" style="txt-align:center"/>
    <param element="0" expand="true" oid="dstList.0.vd" widget="1"/>
    <param element="0" expand="true" oid="dstList.1.vd" widget="1"/>a</tr>
    <tr>
    <label height="40" name="ac" style="txt-align:center"/>
    <param element="0" expand="true" oid="dstList.0.ac" widget="1"/>
    <param element="0" expand="true" oid="dstList.1.ac" widget="1"/>
    </tr>
    <tr>
    <label height="40" name="vs" style="txt-align:center"/>
    <param element="0" expand="true" oid="dstList.0.vs" widget="1"/>
    <param element="0" expand="true" oid="dstList.1.vs" widget="1"/>
    </tr>
    </table>
    <param expand="true" height="255" left="90" oid="dstList" showlabel="false" top="358" width="763"/>
    </abs>

    #DashBoard