better than school for me. I very new to programming but I'm usually a pretty quick learner. I'm hoping to implement a
system using the code at http://www.schuurman...r-netduino-plus . It's a clever little web
server for starting and stopping things on the board. I got it working just how it describes without any problems. I could
go to http://ipaddress/settled/on and it worked as it should. But I'm trying to get it to do more advanced things now like
running other scripts so to speak. For example http://ipaddress/flashled/on . I played with the code and I was sort of
able to achieve this. But then I couldn't stop it from flashing because it was stuck in a loop. So I decided it would be
good if for the future I started these advanced routine's in there own thread. So I did. But when I run blinkythread.abort
it throws an exception. Maybe I'm going about it all the wrong way. What I'm hoping to achieve is to be able to send a get
request through a browser like http://ipaddress/setbath/36 . And have another thread start a new cs file and go about
opening the solenoid's and reading the temperature to fill it to the right temp. But while that tread is still executing
still be able to receive cmd's to turn on light's and stuff. Hope this makes sense. I've read the book about threading a
couple of times and can't quite grasp it.
I'm trying to configure this as a base framework to start all my gadgets off. Once I'm able to start and stop complex
operations in their own thread and kill them at will. I'll be laughin.
here is how I've changed the code so far and got stuck.
using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; using Blinq.Netduino.Web; namespace ServerExample { /// <summary> /// Example for using the Blinq.Netduino.Webserver class /// </summary> public class Program { public static OutputPort onBoardLed = new OutputPort(Pins.ONBOARD_LED, false); public static void Main() { // Instantiate a new web server on port 80. WebServer server = new WebServer(80); // Add a handler for commands that are received by the server. server.CommandReceived += new WebServer.CommandReceivedHandler(server_CommandReceived); // Add a command that the server will parse. // Any command name is allowed; you will decide what the command does // in the CommandReceived handler. The server will only fire CommandReceived // for commands that are defined here and that are called with the proper // number of arguments. // In this example, I define a command 'setLed', which needs one argument (on/off). // With this statement, I defined that we can call our server on (for example) // http://[server-ip]/setled/on // http://[server-ip]/setled/off server.AllowedCommands.Add(new WebCommand("setled", 1)); server.AllowedCommands.Add(new WebCommand("flashled", 1)); // Start the server. server.Start(); // Make sure Netduino keeps running. while (true) { Debug.Print("Netduino still running..."); Debug.Print("Memory: " + Microsoft.SPOT.Debug.GC(false).ToString()); Thread.Sleep(10000); } } /// <summary> /// Handles the CommandReceived event. /// </summary> private static void server_CommandReceived(object source, WebCommandEventArgs e) { Debug.Print("Command received:" + e.Command.CommandString); switch (e.Command.CommandString) { case "setled": { // Do you stuff with the command here. Set a led state, return a // sampled value of an analog input, whatever. // Use the ReturnString property to (optionally) return something // to the web user. // Read led state from command and set led state. bool state = ( e.Command.Arguments[0].Equals("on") ? true : false); onBoardLed.Write(state); // Return feedback to web user. e.ReturnString = "<html><body>You called SetLed with argument: " + e.Command.Arguments[0].ToString() + "</body></hmtl>"; break; } case "flashled": { bool state = (e.Command.Arguments[0].Equals("on") ? true : false); { blinky blinkyobject = new blinky(); Thread blinkythread = new Thread(blinkyobject.blinkygo); if (state == true) { Debug.Print("blinky start"); blinkythread.Start(); e.ReturnString = "<html><body>You called FlashLed with argument: " + e.Command.Arguments[0].ToString() + "</body></hmtl>"; } if (state == false) { //Debug.Print("blinky stop"); blinkyobject.RequestStop(); Thread.Sleep(500); blinkythread.Join(); Debug.Print("main thread: Worker thread has terminated."); e.ReturnString = "<html><body>You called FlashLed with argument: " + e.Command.Arguments[0].ToString() + "</body></hmtl>"; } } break; } } } } }
Thanks in advance.
also, sorry to the moderators if I sent this twice. Browser issues.