Basically... On the consumer panel, I have a "Basic Canvas" called "test_canvas".
This panel also includes a listener for UDP commands. All it does is to listen to UDP commands on the port 53535 [I](same as QLAB by chance *wink wink*)[/I], and then send the message through a custom function called "UDPHideShowElement":
<listener autostart="true" listenport="53535" maxlength="1024" name="UDP Listener" udp="true">
<task tasktype="ogscript">if (event.getEventType() == 1)
{
UDPHideShowElement(event.getBytesAsString());
}
</task>
</listener>
Now, for the custom function, what it does is to simply separate the message into an array, split by / in order to get the different parts of the message.
The custom function that in turn created the function that runs the ogscript is as follows:
<api>function UDPHideShowElement(msg) {
msg = msg.split("/");
var f = "function udpFunction() {ogscript."+msg[1]+"('"+msg[2]+"');}";
eval(f); udpFunction();
}</api>
[I]At the moment, I am only after reveal and hide, so it does not need to do more than this. But basically based on the way ogscript is built up, I can technically check for the msg[1] and create a case as to where it handles differently based on whatever the type of ogscript I want to be able to "build" with UDP.
The fact that I also split by / makes it so that I can put in a simple IF check in my listener for the first character of the UDP message, basically asking for the first character in a "command" like this to be /, allowing me to set up other UDP commands for the panel as well as this dynamic function control.[/I]
Now on the "provider" panel that will hold all my parameters etc, all I need to do now, is send a UDP string to the machine with the consumer panel like so:
ogscript.sendUDPString("localhost", 53535, "/hide/test_canvas");
And this will in turn create a function on the consumer panel that in turn runs the following:
ogscript.hide("test_canvas");
And then I have a UDP command that I can easilly change the UDP string command in order to hide/reveal other panels, simply by changing the last element of the UDP string to match the ID of whatever canvas/button/element in the consumer panel.
This in turn also lets me build up commands and let other devices that can simply send UDP commands as well to trigger either functions, tasks, buttons or hide/reveal panel elements with ease, by building dynamic ogscript code through UDP commands. Think Raspberry PI, Arduino, or any other UDP software for that matter.
Full code on "CONSUMER PANEL":
<abs contexttype="opengear" gridsize="20" id="_top" objectid="localhost:5566<br>Slot 0<br>Device" objecttype="Device" scroll="horizontal">
<meta>
<api>function customUDPCommand(msg) {
msg = msg.split("/");
var f = "function udpFunction() {ogscript."+msg[1]+"('"+msg[2]+"');}";
eval(f); udpFunction();
}</api>
<listener autostart="true" listenport="53535" maxlength="1024" name="UDP Listener" udp="true">
<task tasktype="ogscript">if (event.getEventType() == 1)
{
var udp = event.getBytesAsString();
if (udp.charAt(0) == "/") {
customUDPCommand(udp);
} else {
ogscript.debug("Not custom command...");
}
}
</task>
</listener>
</meta>
<abs height="280" id="test_canvas" left="60" style="bg#5D5D5D;bdr:thick;bdr#BDBDBD;" top="80" width="260"/>
<button buttontype="push" height="100" id="btn1" left="80" name="btn1" top="380" width="100"/>
<button buttontype="push" height="120" id="btn2" left="240" name="btn2" top="460" width="120"/>
</abs>#DashBoard