a) KEYSTATE ME:KEY
b) The KEYSTATE message will respond with "Key is OFF" or "Key is "ON" - use this with ogScript to call params.setValue of your key state parameter with the correct value
c) You'll want to keep track of the current state of the key and, when your button is pressed, call KEYCUT or KEYAUTO if the current state is not the state you want.
Below, you'll see an example of a panel that tracks the key state in a timer (checking every second) and updates a toggle button to show the current state. Changing the toggle button results in the key being transitioned off/on.
Note: You'll want to make sure Cmd Response is set to "OFF" in your RTalk-IN on the Acuity for this particular panel to work properly.
<abs contexttype="opengear">
<timer id="key_timer" pattern="HH:mm:ss" rate="1000">
<timertask tasktype="ogscript">for (var i = 0; i < params.getElementCount('Key'); i++)
{
updateKeyState(params.getValue('ME_Number', 0), (i + 1));
}</timertask>
</timer>
<meta>
<api immediate="true">/*
* This function is passed to our rosstalk sender
* It will parse-out the "Key is ..." response to the KEYSTATE query and update the parameter
*/
function updateParameters(success, cmd, result)
{
if (result != null)
{
result = result.toLowerCase(); //Set it to lowercase so we don't have to worry about On vs ON vs on
}
if (result != null && result.indexOf('key is ') >= 0)
{
var onAir = result.indexOf('on') > 0;
var cmdSplit = cmd.split(':'); //Find out which KEY/ME this response is for
if (cmdSplit.length == 2)
{
var me = parseInt(cmdSplit[0].substr(-1));
var key = parseInt(cmdSplit[1].substr(0, 1));
var newValue = 0;
if (onAir)
{
newValue = 1;
}
ogscript.putObject(me + ":" + key, newValue); //Update our internal values before we set the parameter to avoid setting the keystate again
params.setValue('Key', (key - 1), newValue);
}
}
}
function updateKeyState(meNumber, keyToCheck)
{
var deviceIP = params.getValue('Host_Name', 0);
var devicePort = parseInt(params.getValue('Port_Number', 0));
var command = 'KEYSTATE ' + meNumber + ':' + keyToCheck + '\r\n';
rosstalk.sendMessageWithResponse(deviceIP, devicePort, command, '\n', updateParameters);
}</api>
<params>
<param access="1" constrainttype="INT_CHOICE" name="ME Number" oid="ME_Number" precision="0" type="INT32" value="1" widget="combo">
<constraint key="1">ME 1</constraint>
<constraint key="2">ME 2</constraint>
<constraint key="3">ME 3</constraint>
<constraint key="4">ME 4</constraint>
</param>
<param access="1" constrainttype="INT_CHOICE" name="Key" oid="Key" precision="0" stateless="true" type="INT32_ARRAY" value="0;0;0;0" widget="toggle">
<constraint key="0">Key 1</constraint>
<constraint key="1">Key 1</constraint>
<constraint key="0">Key 2</constraint>
<constraint key="1">Key 2</constraint>
<constraint key="0">Key 3</constraint>
<constraint key="1">Key 3</constraint>
<constraint key="0">Key 4</constraint>
<constraint key="1">Key 4</constraint>
</param>
<param access="1" maxlength="0" name="Host Name" oid="Host_Name" type="STRING" value="172.16.11.11" widget="text"/>
<param access="1" constraint="0.0;65535.0;0.0;65535.0;1" constrainttype="INT_STEP_RANGE" name="Port Number" oid="Port_Number" precision="0" type="INT32" value="7788" widget="spinner"/>
</params>
</meta>
<param expand="true" height="44" left="94" oid="ME_Number" top="66" width="123"/>
<param expand="true" height="87" left="93" oid="Key" style="t:bg#FF3131;f:bg#dark;" top="123" width="371">
<task tasktype="ogscript">var keyIndex = this.getIndex() + 1; //Our array starts with index 0 and goes to 3 - we need to change this to 1 - 4
var newState = this.getValue(); //Get the parameter's value
var meNum = params.getValue('ME_Number', 0); //Get the current ME value
var stateKey = meNum + ':' + keyIndex; //keep track of the previous value so we know whether or not to send something to the switcher
var oldState = ogscript.getObject(stateKey); //Get the 'internal value' of the key state
if (newState != oldState) //if the 'internal value' is equal to the parameter value, do nothing
{
ogscript.putObject(stateKey, newState); //Otherwise, update the internal value
rosstalk.sendMessage(params.getValue('Host_Name', 0), parseInt(params.getValue('Port_Number', 0)), 'KEYAUTO ' + meNum + ':' + keyIndex); //Trigger the RossTalk message
ogscript.asyncExec(function()
{
updateKeyState(meNum, keyIndex);
}, 500);
}</task>
</param>
<param expand="true" height="43" left="95" oid="Host_Name" top="13" width="247"/>
<param expand="true" height="48" left="352" oid="Port_Number" top="9" width="79"/>
</abs>#DashBoard