Here is the code I ended up implementing for this.
The main function that was supplied by Hari that I modified.
private static string ProcessRequest(string receivedStr)
{
//-- Parse the first line of the request: "GET /led/1 HTTP/1.1\r" --
string firstLine = receivedStr.Substring(0, receivedStr.IndexOf('\n'));
string sReturn = "Command executed at " + DateTime.Now.ToString();
string[] words = firstLine.Split(' ');
string[] parts = words[1].Split('/');
string cmd = parts.Length > 1 ? parts[1] : "";
string param1 = parts.Length > 2 ? parts[2] : "";
string param2 = parts.Length > 3 ? parts[3] : "";
bool bValue;
bValue = param2 == "1" ? true : false;
//-- Add more commands and param handling here --
switch (cmd)
{
case "led13":
sReturn = ProcessOutputPort(led13, param1 ,ref bValue);
break;
case "led12":
sReturn = ProcessOutputPort(led12, param1,ref bValue);
break;
case "in0":
sReturn = ProcessInputPort(in0, param1,ref bValue);
break;
case "in1":
sReturn = ProcessInputPort(in1, param1,ref bValue);
break;
default:
sReturn = "Unknown Command at " + DateTime.Now.ToString();
break;
}
//-- Optional string to return to caller --
return sReturn;
}
The code to process InputPorts
private static string ProcessInputPort(InputPort inport, string sAction,ref Boolean bValue )
{
string sreturn;
switch (sAction)
{
case "state":
bValue = inport.Read();
sreturn = "Port is " + (bValue ? "On" : "Off");
break;
default:
sreturn = "Unknown Parameter at " + DateTime.Now.ToString();
break;
}
return sreturn;
}
And the code for the output ports
private static string ProcessOutputPort(OutputPort outport, string sAction,ref Boolean bValue)
{
string sreturn;
switch (sAction)
{
case "state":
bValue = outport.Read();
sreturn = "Port is " + (bValue ? "On" : "Off");
break;
case "set":
outport.Write(bValue);
sreturn = "Port set to " + (bValue ? "On" : "Off");
break;
default:
sreturn = "Unknown Parameter at " + DateTime.Now.ToString();
break;
}
return sreturn;
}
Now I just need to make the changes to do something instead of just write back to the browser that I determined something.