WACI Control Page Source Code Samples

Welcome to the WACI programming sample page. This is the place to be if you are doing WACI development. We will be constantly updating these pages with new demos and sample programs. We have provided source code for some of our demos so you can quickly learn how to program a WACI using standard web languages (flash, dhtml, etc). The source code is provided as-is. If you are having trouble getting anything to work, or need something more specific please post a message to the forum and one of our WACI experts will get back to you. If you have developed a new way of accessing the WACI's RPC server, we would like to hear about it. Please post it on our forums, and we will add it to this list.

Currently sample code is available for the following programming languages:

Macromedia Flash
Javascript / DHTML / AJAX
C#
ASP 3.0
Visual Basic / VB.NET
JAVA

Coming Soon:

XML-RPC
PHP
SOAP




WACI Functions
Flash Programming Demo

If you are programming a WACI for the first time using Flash, Download this file now. It will save you a LOT of time making the connections to the WACI and setting up your commands. This file will demonstrate executing 6 different functions on the WACI RPC server from within A flash movie. You should only need basic flash experience to get this to work. Just look at the source code and read the detailed comments and you will be on your way to creating WACI control pages in no time.

This component will allow you to make the connection to the WACI and has the most popular functions already coded into it. Feel free to view the source so you can make your own modifications to it.

WACI NX+ and WACI NX Jr

Download Flash 8 Source Code (.FLA)

Download Flash MX 2004 Source Code (.FLA)

WACI + and WACI Jr

Download Flash 5 Source Code (.FLA)

Download Flash MX 6 Source Code (.FLA)

Download Flash MX 2004 Source Code (.FLA)

WACI Event Tester

This is a quick program created to test clock events. Often when creating a scheduled event, it helps to be able to test the actions to ensure everything works correctly. Just type the event name into this program and it will force the event to run now.

Download Event Tester (.ZIP)

You're in Control
Generic projector control page demo

This is a control page that uses the Logging features of the WACI to allow you to save a list of serial commands used to control a projector. You can store up to 10 command presets on the WACI to control all different types of projectors.

Download Compiled SWF Files



We also have formatted this program to work from a PDA. It has been tested with the IPAQ h2200
Download Compiled SWF Files for PDA

VTune Pro

One way VTune control page. This does not do 2 way feedback, however it can be easily modified to get feedback on the volume, channel, etc...

Download Compiled SWF & FLA Source code
(requires Flash MX 2004)

XTune Pro / DVD Control Page

Control a DVD player via IR and an XTune via RS-232

Download Compiled SWF & FLA Source code
(requires Flash MX 2004)

NEC LCD 4000 / XTune Demo

Simple one-way control page for an XTune and NEC LCD4000

Download Compiled SWF
Download FLA Source Code (requires Flash MX 2004)

Universal Demo

This is a demo made with Flash MX 2004. It features the WACI Component that gets the IP and Date from the WACI.

Download Flash MX 2004 Files

Magenta Research Switcher

This is a control page which controls an 8x8 Magenta Research MultiView Switcher. It displays the current status of the crosspoints in a grid and allows for editing the label of the Sources and Outputs.

Download Flash MX 2004 Files + ASP Script

This is a mini flash demo to get the WACI time. Every 60 seconds it will retrive the time off of the WACI.

Download Flash MX 2004 File

This is a mini flash demo for inactivity on a touch screen or kiosk. This file has a counter that will count to 10 if there is no mouse movement, and once it hits 10 it will display a message or you can have it go back to a main screen. If the mouse moves, then the timer will go back to 0 meaning there is activity on the panel.

Download Flash MX 2004 File

View Demo

This is a sample on how you can create an on press/release volume button.

Download Flash MX 2004 File

View Demo

Automatically loading Flash animations on start (you don't have to click on the animation to activate it) - only Internet Explorer

index.html file will look like that :

<script language="Javascript">
thispage = location.href;
URLarr = thispage.split("/");
theIP = URLarr[2];

<!-- this is the place where you need to put the name of your flash file //-->

theFILE = "test.swf";
</script>

<HTML>
<HEAD>
<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">

<!-- this is the reference to the script which allows you to automatically activate Flash animations in IE //-->

<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
window.open(href, windowname, 'width=700,height=500,scrollbars=yes');
return false;
}
//-->
</SCRIPT>
<script language="JScript" type="text/jscript" src="activateActiveX_onload.js"></script>

<TITLE>
WACI Control System
</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">

<script type="text/javascript" language="JavaScript">
document.write('<object id="WACI" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100%" height="100%">');
document.write('<param name="movie" value="'+theFILE+'" />');
document.write('<param name="quality" value="high" />');
document.write('<param name="FlashVars" value="callerID='+theIP+'" />');
document.write('<embed name="flashMovie" src="'+theFILE+'" FlashVars="callerID='+theIP+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="100%" height="100%"></embed>');
document.write('</object>');
</script>

<br><br>

</BODY>
</HTML>

In the index.html file there is a reference to "activateActiveX_onload.js" file. This is the file that allows you to automatically open Flash animations in IE without clicking on them first to activate. This is the code for this file:

//trap onload event
window.onload = function () {
//Determine browser, we only need this for Internet Explorer
if (navigator.appName == "Microsoft Internet Explorer") {

//Array of elements to be replaced
var arrElements = new Array(3);
arrElements[0] = "object";
arrElements[1] = "embed";
arrElements[2] = "applet";


//Loop over element types
for (n = 0; n < arrElements.length; n++) {

//set object for brevity
replaceObj = document.getElementsByTagName(arrElements[n]);

//loop over element objects returned
for (i = 0; i < replaceObj.length; i++ ) {

//set parent object for brevity
parentObj = replaceObj[i].parentNode;

//grab the html inside of the element before removing it from the DOM
newHTML = parentObj.innerHTML;

//remove element from the DOM
parentObj.removeChild(replaceObj[i]);

//stick the element right back in, but as a new object
parentObj.innerHTML = newHTML;

}
}
}
}

Using new WACI NX component to automatically get an IP address from the browser

On frame 1 of your flash put this code:

if ((_root.callerID == "" || _root.callerID == undefined)
&& (_global.ipAddress == "" || _global.ipAddress == undefined))
{
//That will be the default IP address if we are testing in Flash
//It will not longer apply if the flash file is opened from WACI using web browser
_root.callerID = "188.188.188.188";
}
else
{
//If the globals have not been set yet, set them now based on FlashVars
if (_root.callerID == undefined){ _root.callerID = _global.ipAddress; }
}

_root.waci.waci_IP = _root.callerID;

 

index.html file will look like that:

<script language="Javascript">
thispage = location.href;
URLarr = thispage.split("/");
theIP = URLarr[2];

<!-- this is the place where you need to put the name of your flash file //-->

theFILE = "test.swf";
</script>

<HTML>
<HEAD>
<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">

<TITLE>
WACI Control System
</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">

<script type="text/javascript" language="JavaScript">
document.write('<object id="WACI" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100%" height="100%">');
document.write('<param name="movie" value="'+theFILE+'" />');
document.write('<param name="quality" value="high" />');
document.write('<param name="FlashVars" value="callerID='+theIP+'" />');
document.write('<embed name="flashMovie" src="'+theFILE+'" FlashVars="callerID='+theIP+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="100%" height="100%"></embed>');
document.write('</object>');
</script>

<br><br>

</BODY>
</HTML>

If you did everything correctly, you should be able to automatically get an IP address using web browser, accessing WACI's files. Right now there is no need for setting an IP address in the WACI NX component, since it would not be used anymore.

Accessing the WACI's Functions using Flash Actionscript LoadVars.sendAndLoad()

On frame 1 of your flash put this code:

//Create a global variable which stores the WACI’s IP address
//Later I will show you how to pull this from the WACI automatically using a simple ASP script
_global.waciIPADDRESS = “192.168.1.172”;


On your buttons/moveclips put this code:

on (press) {

//Create a new object and get it ready to do the HTTP Post
_root.WACI_Call = new LoadVars();

//Give the WACI the method name (function call) you want to run
_root.WACI_Call.method = "Serial_Send";

//The first parameter for Serial_Send is the serial port to send through
_root.WACI_Call.param1 = "1";

//The second Parameter which is the string to send
_root.WACI_Call.param2 = "!KEY_1%0D";

//The third parameter which is the timeout for the serial.. I always use 200
_root.WACI_Call.param3 = "200";

// Here is where we get more advanced. We will set up a function to listen
// for when the WACI responds.
//When it responds we want to do something with the data that comes back
//For just doing serial send you will not get any useful data back, but other functions like
// GetVariableValueByName() will need to return the variable value

_root.WACI_Call.onLoad = function(){

//Send the response to flash's output window so we can see what's going on
trace(“Here is the data that came back: “ + _root.WACI_Call.toString());


}

//Execute the HTTP Post to the RPC server
_root.WACI_Call.sendAndLoad("http://"+_global.waciIPADDRESS+"/RPC", _root.WACI_Call, "POST");

//Use trace statements so when you are testing in flash you know whats going on.
trace("Sending RPC callPADDRESS+"/RPC", _root.WACI_Call, "POST");

//Use trace statements so when you are testing in flash you know whats going on.
trace("Sending RPC call to WACI ("+_global.waciIPADDRESS+"): "+_root.WACI_Call.toString()); }



SUBMITTED BY: Chris Kolkman
Precision Data Products, Inc.

In an effort to make it easier to program for the WACI in programming languages that support the .NET framework I have been working on a custom control. This control models the behavior of the WACI Flash Demo project available.

Download it here

Once the control has been added to your form accessing it is simple.
Example: Waci.General.GetFrameworkVersion() 'returns the framework version of the WACI.

All examples are done using VB.NET, but the control can be used in other languages as well. A demo program is included in the zip file, along with all of the source code. HTML help files have also been included.
Just about every function listed in the WACI manual has been added to the control.

Any suggestions/comments/bugs on this VB example please report them to chris.kolkman@precision.com.

Click here for Instructions on how to use these files


Here is an example using ASP VBScript to call functions on the WACI:

Dim waciUser
set waciUser = CreateObject("WACI.UserAPI.1")

'Gets the current value of "myInputVar"
inputId = waciUser.GetVariableByName("myInputVar")
inputValue = waciUser.GetVariableValue(inputId)

'Sets the current value of "myInputVar"
setInputVar = waciUser.AssignVariable("myInputVar", "0", "newvalue")

'Find out how many relays the WACI has
relayCount = waciUser.Relay_GetPortCount()

'Turn Relay On
setRelay1ON = waciUser.Relay_On(1)

'Turn Relay Off
setRelay1OFF = waciUser.Relay_Off(1)

'Get Relay Status (on or off)
getRelay1Status = waciUser.Relay_GetState(1)



For more information on how this works, click here


<script language="JavaScript">

///////////////////////////////////////////////
//DHTML SCRIPT V2 - SETUP
///////////////////////////////////////////////

//Set your WACI IP or Hostname Here *****************************
var WACIip = "192.168.1.165";

///////////////////////////////////////////////
//
// To Send IR Commands make a link to: "javascript:IRSend(port, group, command)"
// To Send Serial Commands make a link to: "javascript:serialSend(port, command, timeout)"
// To Trigger an Event make a link to: "javascript:TriggerEventByName('eventname', '0', '0', '0')"
// To Trigger an Event make a relay turn on: "javascript:relayToggle('Relay_On', '1')"
// To Trigger an Event make a relay turn off: "javascript:relayToggle('Relay_Off', '1')"
//
///////////////////////////////////////////////

var RPCurl = "http://"+WACIip+"/RPC";

var xmlhttp = null;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}

function getResponse(){
if (xmlhttp.readyState == 4) {

}
alert(xmlhttp.readyState);


}

function relayToggle(method, param1) {

// Relay Example:
// Param 1: RPC Method Name
// Param 2: Relay Port

xmlhttp.open("POST",RPCurl,false);
var theString = "method=" + method + "&Param1=" + param1;
xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = getResponse;
xmlhttp.send(theString);
}


function serialSend(param1, param2, param3) {

// Param 1: Port
// Param 2: Serial String
// Param 3: Timeout

xmlhttp.open("POST",RPCurl,false);
var theString = "method=Serial_Send&Param1=" + param1 + "&Param2=" + param2 + "&Param3=" + param3;
xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(theString);
}

function IRSend(param1, param2, param3) {

// Param 1: IR port on WACI to send from
// Param 2: Group name of the IR commands
// Param 3: Name of the command to send

xmlhttp.open("POST",RPCurl,false);
var theString = "method=IR_SendCommand&Param1=" + param1 + "&Param2=" + param2 + "&Param3=" + param3;
xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(theString);
}

function TriggerEventByName(param1, param2, param3, param4) {

// Param 1: Name of event to trigger

xmlhttp.open("POST",RPCurl,false);
var theString = "method=TriggerEventByName&Param1=" + param1 + "&Param2=" + param2 + "&Param3=" + "&Param4=" + param4;
xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(theString);
}

</script>

<br><br><br><br>

<a href="javascript:TriggerEventByName('test', '0', '0', '0')">Run 'test' event</a><br><br>

<a href="javascript:relayToggle('Relay_On', '1')">r1 on</a><br><br>

<a href="javascript:relayToggle('Relay_Off', '1')">r1 off</a><br><br>

<a href="javascript:serialSend(1, 'SOME DATA', 200)">Send data through Serial 1</a><br><br>

<a href="javascript:IRSend(1, 'VCR', 'POWER')">Send VCR Power Command</a><br><br>



import java.net.*;
import java.io.*;

class HttpPost
{
public static void main(String args[])

{
if (args.length < 1)
{
System.err.println
("usage: java HttpPost [WACI_IP_Address]");
System.exit(1);
}
try
{
// Construct Date
String data = URLEncoder.encode("method", "UTF-8") + "=" + URLEncoder.encode("Relay_On", "UTF-8");
data += "&" + URLEncoder.encode("param1", "UTF-8") + "=" + URLEncoder.encode("1", "UTF-8");

URL url = new URL("http", args[0], 80, "/RPC");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());

// Send Data
wr.write(data);
wr.flush();

// Get the reponse
BufferedReader rd =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
catch (MalformedURLException e)
{ System.err.println(e.toString()); }
catch (IOException e)
{ System.err.println(e.toString()); }
}
}

Download Full JAVA Source Code


Here is how you would do an HTTP Post using C#

public static string HttpPost(string URI, string Parameters)
{
System.Net.WebRequest request = System.Net.WebRequest.Create(URI);
//request.Proxy = new System.Net.WebProxy(ProxyString, true);//Not needed
//Add these, as we're doing a POST
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Timeout = 7000;
byte [] bytes = System.Text.Encoding.Default.GetBytes(Parameters);
request.ContentLength = bytes.Length;
System.IO.Stream os = request.GetRequestStream();
os.Write (bytes,0,bytes.Length); //Push it out there
os.Close ();
System.Net.WebResponse resp = request.GetResponse();
//resp.Close();

if (resp == null) return null;
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default);
string i = sr.ReadToEnd().Trim();
sr.Close();
resp.Close();
return i;
}


Download the latest WACI Firmware


Download

WACI Distributed

WACI Tutorials

WACI Setup Instructions
WACI Setup Instructions PDF
Upgrading Firmware
One-Way DHTML Control Pages
Monitor serial port and email results

 

Need Help?

Trouble Shooting

Post a message on our forums
to get a quick response
to your problem.

   

By using or downloading any of the above code you do so at your own risk. Aurora Multimedia or WACIWorld will not be responsible if it does not work or if it crashes your computer.
We can not give tech support for this code on the phone. Please use the forums if you need help.
If you find any errors, or if you've made changes to improve the code please post the changes on the forum and we will update this page with the new code.

 

 


WACIWorld.com 2008 - Aurora Multimedia Corp