Facility Control

 View Only
  • 1.  Updating listener IP with new port/host or reference of another parameter

    Posted 07-09-2018 18:01
    Hi,
    I'm working on a Dashboard that communicates to a variable number of record decks via AMP. I'm trying to make the script modular enough that I can select the amount of decks and have it populate the Dashboard with the appropriate number of buttons for each deck. I'm able to populate the Dashboard based on the number of decks selected but I'm having an issue with each listener updating with their respective IPs (Based off a text box that each is associated with).

    I looked at the Hyperdeck example and it looks like the listener host and port is referencing the value of the text boxes on the sheet but any time I try to use the %value[var][0]% string the code seems to break. Is there a trick I'm missing or a better way to do this?

    Thanks!


  • 2.  RE: Updating listener IP with new port/host or reference of another parameter

    Posted 07-09-2018 20:54

    Are you using an ogScript variable or a parameter OID for your 'var'?
    Also, if it is a String-based OID, you'll need to put single quotes around it.

    I have just verified this with:
    %value['Server_Host_Name'][0]% as the connection info does work.

    <abs contexttype="opengear" style="">
       <meta>
          <params>
             <param access="1" maxlength="0" name="Outgoing Text" oid="Outgoing_Text" type="STRING" value="Bork bork" widget="text"/>
             <param access="1" maxlength="0" name="Server Host Name" oid="Server_Host_Name" type="STRING" value="localhost" widget="text"/>
          </params>
          <listener autostart="true" delimitertype="newline" id="Fake-Server" listenport="12345">
             <task tasktype="ogscript">if (event.isConnectEvent())
    {
       this.writeString("Connected!\n", false);
    }
    else if (event.isMessageEvent())
    {
       ogscript.debug("GOT : " + event.getBytesAsString());
       this.writeString((event.getBytesAsString() + "").split("").reverse().join("") + "\n", false);
    }</task>
          </listener>
          <listener autostart="true" connecthost="%value['Server_Host_Name'][0]%" connectport="12345" delimitertype="newline" id="TCP-Client">
             <task tasktype="ogscript">if (event.isConnectEvent())
    {
       //We are connected!
       ogscript.putObject('connection', this);
    }
    else if (event.isMessageEvent())
    {
       ogscript.rename("incoming", event.getBytesAsString());
    }
    else if (event.isDisconnectEvent())
    {
       //We are disconnected
       if (ogscript.getObject('connection') == this)
       {
          ogscript.putObject('connection', null);
       }
    }</task>
          </listener>
       </meta>
       <label height="49" id="incoming" left="17" name="Incoming Messages" style="txt-align:west" top="17" width="346"/>
       <param expand="true" height="43" left="16" oid="Outgoing_Text" top="78" width="283"/>
       <button buttontype="push" height="42" left="306" name="Send" top="78" width="95">
          <task tasktype="ogscript">var connection = ogscript.getObject("connection");
    if (connection != null)
    {
       connection.writeString(params.getValue("Outgoing_Text", 0) + "\n", false);
    }</task>
       </button>
    <param expand="true" height="45" left="18" oid="Server_Host_Name" top="148" width="276"/>
       <label height="43" left="302" name="&lt;- Server Host" style="txt-align:west" top="148" width="107"/>
    </abs>

    #DashBoard


  • 3.  RE: Updating listener IP with new port/host or reference of another parameter

    Posted 07-09-2018 22:28

    Hey James,
    Thanks for the response. Hmmm... the problem may be deeper than that then. It looks like my code is correct but for some reason the value won't update.

    var i = 0;
    var tot  = params.getValue('numListeners', 0);
    var x = 16;
    var str = '';
    var posY = 0;
    
    while (i < tot) {
       var listenerIP = 'listener' + i;
       var newIP = {
          "oid" : listenerIP,
          "name": listenerIP,
          "readonly": false,
          "type": "STRING",
          "widget": "TEXT ENTRY",
          "value": "DECK #" + i + " IP ADDR"
       };
    
       var newParam = params.createParam(newIP);
    
       var listenerIPConnection = listenerIP + 'Conn';
    
       posY = 20 + 80*i;
       str = str + '<table height="80" left="20" top="' + posY + '" width="800" insets="3,2,2,2"><tr> \
       <param colspan ="1" fill="both" oid=\'' + listenerIP + '\' rowspan="1" weightx="1.0" weighty="1.0">\
       <task>\
          ogscript.debug(\'new IP: \' + this.getValue());\
       </task>\
       </param>\
       <listener autostart="false" blockingpause="true" buttontype="toggle" connecthost="%value[\'' + listenerIP + '\'][0]%"  connectport="3811" delimitertype="newline" fill="both" weightx="1.0" weighty="1.0" rowspan="1" colspan="1" id="' + listenerIPConnection + '" name="CONNECT" style="style:toggleButton;"> \
          <task>\
          ogscript.debug("TASKINGTASKASK");\
          </task>\
          <task tasktype="ogscript">\
             if (event.isConnectEvent()){ \
             ogscript.debug("CONNECTING TO THINGY");\
             ogscript.putObject("' + listenerIPConnection + '", this); \
             ogscript.debug("CONNECTING TO:' + listenerIPConnection + '");\
             sendNextMessage("' + listenerIPConnection + '", ["CRAT0007204Vtr1\\n"]); \
             } \
             else if (event.isMessageEvent()) \
             { \
                ogscript.debug("[RECEIVED] " + event.getBytesAsString()); \
             } \
             else if (event.isDisconnectEvent()) \
             { \
                ogscript.debug("-- CONNECTION CLOSED! --"); \
             } \
             else \
             { \
                ogscript.putObject("' + listenerIPConnection + '", null); \
             }\
          </task> \
       </listener> \
       <button colspan="1" fill="both" id= "start' + i + '" name="START" rowspan="1" weightx="1.0" weighty="1.0"> \
       <task tasktype="ogscript">ogscript.debug("Button2");sendNextMessage("' + listenerIPConnection + '", ["CMDS00042002\\n"]);</task></button> \
       <button colspan="1" fill="both" id= "stop' + i + '" rowspan="1" weightx="1.0" name="STOP" weighty="1.0"> \
       <task tasktype="ogscript">ogscript.debug("Button3");sendNextMessage("' + listenerIPConnection + '", ["CMDS00042000\\n"]);</task></button> \
    </tr></table>';
    
       i++;
    }
    
    ogscript.setXml('dynamicContent', str);

    When I set connecthost to a static value everything works minus changing of the IP with the parameter text box, but when I try using the %value method it doesn't seem to do anything or trigger any of the tasks tied to the listener. Maybe there's a character escaping that shouldn't? It's pretty rough to debug the code since I'm setting the XML through the button task when I try to edit and look and what code it's creating it goes away.


    #DashBoard


  • 4.  RE: Updating listener IP with new port/host or reference of another parameter

    Posted 07-10-2018 00:48
    Hmmm... Here's an interesting discovery.... I stepped through the debugger and pulled the 'str' variable out and pasted it into a new dashboard panel. I added in my function and the parameters manually and it still didn't work. BUT, when I went to the task and separated out the code with line breaks to 'clean it up' when I saved and applied it worked. I may be even more confused now.
    #DashBoard


  • 5.  RE: Updating listener IP with new port/host or reference of another parameter

    Posted 07-10-2018 13:21
    If you're dynamically-generating your XML via ogScript, then there is no need to use %value...% at all:

    connecthost="' + params.getValue(listenerIP, 0) + '" connectport="3811" delimitertype="newline" fill="both" weightx="1.0"

    Note: If you change the value of your IP parameter, it won't automatically-update the listener using either method until the code surrounding the listener is reloaded. If you want to update your listener at runtime, you'd use

    ogscript.getListenerById('ID_OF_LISTENER').connectTo('NEW_HOST_NAME', PORT);
    #DashBoard


  • 6.  RE: Updating listener IP with new port/host or reference of another parameter

    Posted 07-10-2018 16:12
    Ah, thanks James! I think the .connectTo() method is more of what I'm looking for. Is there possibly another method just to update the host and port? It looks like the .connectTo() method immediately starts the connection on top of updating the host and port.

    Thanks!
    #DashBoard


  • 7.  RE: Updating listener IP with new port/host or reference of another parameter

    Posted 07-10-2018 17:46

    There is not presently a way to do this, no.
    Your best bet would be to not use the listener's toggle button and, instead, create your own. This way you can wait and call 'connectTo' only when you are toggled on.

    <abs contexttype="opengear">
       <meta>
          <api>function updateConnection(listenerNumber)
    {
       var ip = params.getValue('IP_Address' + listenerNumber, 0);
       var port = params.getValue('Port' + listenerNumber, 0);
       var state = params.getValue('Connection_State' + listenerNumber, 0);
       var listener = ogscript.getListenerById('Connection' + listenerNumber);
    
       if (state == 1)
       {
          if (listener.getHost() != ip || listener.getPort() != port)
          {
             listener.connectTo(ip, port);
          }
          else if (!listener.isStarted())
          {
             listener.start();
          }
       }
       else if (listener.isStarted())
       {
          listener.stop();
       }
    }</api>
          <params>
             <param access="1" maxlength="0" name="IP Address" oid="IP_Address1" type="STRING" value="localhost" widget="text"/>
             <param access="1" constraint="0.0;65535.0;0.0;65535.0;1" constrainttype="INT_STEP_RANGE" name="Port" oid="Port1" precision="0" type="INT32" value="2" widget="spinner"/>
             <param access="1" constrainttype="INT_CHOICE" name="Connection State" oid="Connection_State1" precision="0" stateless="true" type="INT32" value="0" widget="toggle">
                <constraint key="0">Connect</constraint>
                <constraint key="1">Connect</constraint>
             </param>
          </params>
          <listener autostart="false" connecthost="localhost" connectport="1234" delimitertype="newline" id="Connection1">
             <task tasktype="ogscript">         if (event.isMessageEvent())
    {
       //DO STUFF
    }</task>
          </listener>
       </meta>
       <param expand="true" height="50" left="20" oid="IP_Address1" top="20" width="274">
          <task tasktype="ogscript">updateConnection("1");</task>
       </param>
       <param expand="true" height="52" left="301" oid="Port1" top="19" width="121">
          <task tasktype="ogscript">updateConnection("1");</task>
       </param>
       <param expand="true" height="62" left="430" oid="Connection_State1" style="style:toggleButton;" top="15" width="117">
          <task tasktype="ogscript">updateConnection("1")
    </task>
       </param>
    </abs>

    #DashBoard


  • 8.  RE: Updating listener IP with new port/host or reference of another parameter

    Posted 07-22-2018 16:16

    Mulaky, what I did was make a push button that needs to be pushed after a IP and/or Port has been updated. Using the method James said on post2, you can just put in a ogscript task on the "load" button and re-load the listener, providing you have assigned it an ID.

    <listener autostart="true" id="1mitti" listenport="%value[configuration.1mitti_port][0]%" maxlength="1024" name="mitti1" udp="true"/>
    <button anchor="west" buttontype="push" fill="both" height="28" name="SET" style="style:buttonReset;" width="50">
    <task tasktype="ogscript">// SET MITTI VTR A Primary Listen Port
    ogscript.reload('1mitti');
    </task>
    </button>

    #DashBoard