public static void Method_7() // reads the nutrient controller realy contactcts if opend/closed when closed it does this { static bool nutrientState = false; nutrientState = phcontroller.Read(); while (nutrientState == true) { a.Write(false); Thread.Sleep(5454); a.Write(true); b.Write(false); Thread.Sleep(3000); b.Write(true); Thread.Sleep(5 * MinuteMs); } }
static bool
#1
Posted 28 November 2012 - 03:55 PM
#2
Posted 28 November 2012 - 03:59 PM
#3
Posted 28 November 2012 - 04:27 PM
#4
Posted 28 November 2012 - 04:56 PM
This does what you want:
public static void Method_7() { bool nutrientState = phcontroller.Read(); while (nutrientState == true) { a.Write(false); Thread.Sleep(5454); a.Write(true); b.Write(false); Thread.Sleep(3000); b.Write(true); Thread.Sleep(5 * MinuteMs); } }
phcontroller.Read() is a method call and returns a bool. nutrientState stores the value returned. When you compare it in "nutrientState == true", phcontroller.Read() is not called again, the value stored in nutrientState is used.
Note that the way it is coded, the loop will run forever until the thread is aborted.
#5
Posted 28 November 2012 - 06:05 PM
#6
Posted 28 November 2012 - 06:43 PM
in that case you can create the variable outside the scope of the method.
static bool nutrientState = false;//initial value public static void Method_7() { nutrientState = phcontroller.Read();//read the port and assign result to nutrientState while (nutrientState == true)//run until nutrientState is set to false { a.Write(false); Thread.Sleep(5454); a.Write(true); b.Write(false); Thread.Sleep(3000); b.Write(true); Thread.Sleep(5 * MinuteMs); } }
Here it is a static class member and you can set it to false somewhere else. Of course if you set nutrientState to false while it is performing the stuff inside the loop, it'll complete it first and then check nutrientState - if this is not the behaviour you want, you must take a moment and rethink how to implement your logic.
#7
Posted 28 November 2012 - 07:18 PM
got it trying to meet two conditions
seems easier then trying to kill the thread.
bool phState = phcontroller.Read(); while (phState == true && method_state_6 == true)
Many thanks you guys are the best
#8
Posted 29 November 2012 - 01:01 PM
Its not just going to check it just once is it?.
public static void Method_6() // reads the PH controller realy contactcts if opend/closed when closed it does this { bool phState = phcontroller.Read(); while (phState == true && method_state_6 == true) { ph.Write(false); Thread.Sleep(1 * SecondMs); ph.Write(true); Thread.Sleep(5 * MinuteMs); }
#9
Posted 29 November 2012 - 01:45 PM
public static void Method_6() { while (phcontroller.Read() && method_state_6) { ph.Write(false); Thread.Sleep(1 * SecondMs); ph.Write(true); Thread.Sleep(5 * MinuteMs); } }
or +verbose:
public static void Method_6() { while (phcontroller.Read()==true && method_state_6 == true) { ph.Write(false); Thread.Sleep(1 * SecondMs); ph.Write(true); Thread.Sleep(5 * MinuteMs); } }
or ++(really unnecessary)verbose:
public static void Method_6() { bool phState = phcontroller.Read(); while (phState == true && method_state_6 == true) { ph.Write(false); Thread.Sleep(1 * SecondMs); ph.Write(true); Thread.Sleep(5 * MinuteMs); phState = phcontroller.Read(); } }
To be honest, I think you should study a good c# book before moving forward with your project... your questions are language/logic related. Don't let the difficulties discourage you, gather more knowledge and when you succeed it'll be even more gratifying.
#10
Posted 06 December 2012 - 01:01 AM
or +verbose:
public static void Method_6() { while (phcontroller.Read()==true && method_state_6 == true) { ph.Write(false); Thread.Sleep(1 * SecondMs); ph.Write(true); Thread.Sleep(5 * MinuteMs); } }
or ++(really unnecessary)verbose:
public static void Method_6() { bool phState = phcontroller.Read(); while (phState == true && method_state_6 == true) { ph.Write(false); Thread.Sleep(1 * SecondMs); ph.Write(true); Thread.Sleep(5 * MinuteMs); phState = phcontroller.Read(); } }
These two methods are not equivalent. The last one only Reads once. Did you mean something like this instead, which is definitely way too verbose?
public static delegate bool PhStateDelegate(); public static bool CheckPhState() { return phcontroller.Read(); } public static void Method_6() { PhStateDelegate phState = CheckPhState; while (phState() == true && method_state_6 == true) { ph.Write(false); Thread.Sleep(1 * SecondMs); ph.Write(true); Thread.Sleep(5 * MinuteMs); phState = phcontroller.Read(); } }
#11
Posted 06 December 2012 - 02:23 AM
These two methods are not equivalent. The last one only Reads once. Did you mean something like this instead, which is definitely way too verbose?
I think you missed the last line inside the loop since you tried to assign a bool to a delegate
#12
Posted 06 December 2012 - 04:59 AM
I think you missed the last line inside the loop since you tried to assign a bool to a delegate
haha!! You are correct, I *completely* missed that line. Guess I should have written this in the compiler before posting.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users