Facility Control

 View Only
  • 1.  Switching router destination with dashboard

    Posted 11-22-2017 15:04
    Hi ,

    Is there a way to create a panel that will "listen" to a the nk router destination , and will make an other destination switch at the same time . Ex: when the Someone make a switch Camera1 on destination X on is nkm panel, dashboard will switch same source Camera1 to a destination Y ?

    Thanks


  • 2.  RE: Switching router destination with dashboard

    Posted 11-22-2017 20:42

    You can create an NK Custom Panel and attach ogscript to the nkstatchange event.
    The trick is to check the nkstatchange event to see if the changed destination/level are the ones you are interested in. I have included an example that contains an tag you can copy into your panel to get a function that will check this for you.

    Once you know that your destination's source has changed, you can get the new source with nk.getStatus and set your other destination to the same source. In my example, I am looking at level 5 and setting destination 2 whenever destination 1 changes.

    <meta>
       <api immediate="true">function isEventValid(event, dest, levelNum)
    {
       var levelMask = (1 &lt;&lt; (levelNum - 1)); //TRANSFORM THE LEVEL NUMBER INTO A LEVEL MASK SINCE THAT'S WHAT THE STATUS EVENT USES
       return (levelMask &amp; event.getChangedLevels()) != 0;   //CHECK TO SEE IF THE EVENT LEVEL MASK CONTAINS THE LEVEL WE WANT
    }
    </api>
       <ogscript handles="nkstatchange">var dstNum = 1;                              //DST TO TRACK (Starts at 1)
    var secondDestination = 2;                   //SECOND DESTINATION TO TRACK (Starts at 1)
    var levelNum = 5;                            //LEVEL TO TRACK (Starts at 1)
    
    if (isEventValid(event, dstNum, levelNum))   //CALL FUNCTION IN OUR API BLOCK TO CHECK IF THE EVENT IS FOR THE DST WE CARE ABOUT
    {
       var newSrc = nk.getStatus(dstNum, levelNum);    //GET THE NEW SRC
       var oldMask = nk.getLevelMask();                //SAVE THE CURRENT LEVEL MASK (DOING THE SWITCH WILL CHANGE IT)
       nk.doSwitchWithLabels(secondDestination, newSrc, levelNum)        //DO THE SWITCH
       nk.setLevelMask(oldMask);                       //RESTORE THE OLD LEVEL MASK
    }</ogscript>
    </meta>

    #DashBoard