Okay, last thing I have time to try today but let's give this a shot.
We can try opening a persistent connection to the television, when we connect, we will publish the connection as an object so we can use it elsewhere in the custom panel.
We will then wait for a message (terminated by a newline) to come in before attempting to send a command. First, we will send a newline, then we will send a second newline. Once those have been sent, we should be able to send the POWR0001 or POWR0000 commands.
Here is a custom panel that demonstrates this. Note: it will not work if the television does not send a newline character after each prompt.
<abs contexttype="opengear" style="">
<meta>
<api>function sendNextMessage()
{
var sender = ogscript.getObject('listener');
var messages = ogscript.getObject('messages');
if (sender != null && messages != null && messages.length > 0)
{
var message = messages.splice(0, 1);
sender.writeString(message, false);
return true;
}
return false;
}</api>
</meta>
<listener autostart="true" blockingpause="true" buttontype="toggle" connecthost="172.168.22.41" connectport="10008" delimitertype="newline" height="60" id="TVConnection" left="28" name="Connection" style="style:toggleButton;" top="62" width="150">
<task tasktype="ogscript">if (event.isConnectEvent())
{
ogscript.putObject("listener", this);
ogscript.putObject("messages", ["\r\n", "\r\n"]);
}
else if (event.isMessageEvent())
{
ogscript.debug("GOT " + event.getBytesAsString());
sendNextMessage();
}
else
{
ogscript.putObject("listener", null);
}</task>
</listener>
<button buttontype="push" height="69" left="184" name="Power ON" top="58" width="138">
<task tasktype="ogscript">var messages = ogscript.getObject("messages");
if (messages != null)
{
messages.push("POWR0001\r\n");
sendNextMessage();
}
</task>
</button>
<button buttontype="push" height="69" left="330" name="Power OFF" top="58" width="138">
<task tasktype="ogscript">var messages = ogscript.getObject("messages");
if (messages != null)
{
messages.push("POWR0000\r\n");
sendNextMessage();
}</task>
</button>
</abs>
#DashBoard