Sunday, October 22, 2006

ASP page for TC+ Flags

One of the first things I added to my system with sC was the ability to replicate all the WinEVM MegaController functions in ASP scripts (using the IIS web server in Win2k). This code enumerates all the flags defined in WinEVM, shows their state and allows them to be turned on & off. It can be easily modifed for relays (replacing DeviceCollection = Devices.Flags; with DeviceCollection = Devices.Relays;) or X10 (DeviceCollection = Devices.X10Devices;). You can find my first iteration of ASP pages over on the PTS example page. Grab the ASP MegaController zip file for sample code to control IR, DIs, AIs, Timers and Variables from your browser.


<%@ LANGUAGE=JScript %>
<html>
<head><title>Flags</title></head>
<body bgcolor=#A5DFBA><center><font face=arial>
<%

// flag page
// set/clear flags
// (c) 2002-2006 kJ's Doghouse.com
// http://www.doghouselabs.com

var Devices;
var DeviceCollection;
var EnumDevice;
var EnumItem;

//
Devices = Server.CreateObject("starCOMplus.PTSDevices");

var Name = Request.Form("Name").item;
var Control = Request.Form("Control").item;

// perform the command if we got one
if (Control=="ON") {
Response.Write("<B><center>Issued: " + Name + " ON</center></b>");
Devices.Flags.Item(Name).State = 1;
} else if (Control=="OFF") {
Response.Write("<b><center>Issued: " + Name + " OFF</center></b>");
Devices.Flags.Item(Name).State = 0;
} else {
Response.Write("<B><center> </center></b>");
}


Response.Write("<center><table border=0>");
var odd=1;

// enumerate flag devices
DeviceCollection = Devices.Flags;
EnumDevice = new Enumerator(DeviceCollection);
for (; !EnumDevice.atEnd(); EnumDevice.moveNext()) {
EnumItem=EnumDevice.item();
if (EnumItem.Name.length >1) {
if (odd==1) {
Response.Write("<Tr>");
}
Response.Write("<td>");
Response.write("<b>" + EnumItem.Name + "</b></td>");
Response.Write("<form method=POST action="+Request.ServerVariables("Script_name")+">");
Response.Write("<td width=1> </td>");
if (Name==EnumItem.Name) {
if (Control=="OFF") {
Response.Write("<td width=55>\n");
Response.Write("<center><font color=red><b>");
Response.Write("OFF");
} else if (Control=="ON") {
Response.Write("<td width=55>\n");
Response.Write("<center><font color=green><b>");
Response.Write("ON");
}
} else {
if (Devices.Flags.Item(EnumItem.Name).State==0) {
Response.Write("<td width=55>\n");
Response.Write("<center><font color=red><b>");
Response.Write("OFF");
} else {
Response.Write("<td width=55>\n");
Response.Write("<center><font color=green><b>");
Response.Write("ON");
}
}
Response.Write("</td>\n");


//ON Button
Response.Write("<td>");
Response.Write("<input type=submit value=ON name=Control>");
Response.Write("<input type=hidden name=Name value=" + EnumItem.Name + "></td>");
//OFF button
Response.Write("<td><input type=submit value=OFF name=Control></td>\n");
Response.Write("</form>");

// blank form to keep spacing good
Response.Write(" <form method=POST action="+Request.ServerVariables("Script_name")+">");
Response.Write("<td width=28> </td></form>");

if (odd<2) {
Response.Write("<td width=1> </td>");
odd=odd+1;
} else {
Response.Write("</tr>");
odd=1;
}
}
}
Response.Write("</table>");



// clear stuff out
Devices = null;
DeviceCollection = null;
EnumItem = null;
EnumDevice = null;

%>
</body></html>

No comments:

Post a Comment