...

View Full Version : C# MF need help with a program please



perkunas
11-10-2012, 06:42 PM
I have a program that works fine, its in C# MF

My problem is with Method_6() and 7
This line
while (anyinputfor6.Read() == true && method_state_6 == true)
I need to reverse the logic, I tried everything it sounds simple but I don't know how to do it.
Tried stuff like
while (anyinputfor6.Read() == false && method_state_6 == true)
But no, that wont work, so I need help as I'm just a newb to programing.
Thanks



namespace NetduinoApplication1
{
public class Program
{
public const int SecondMs = 1000;
public const int MinuteMs = 60 * SecondMs;
public const int HourMs = 60 * MinuteMs;
public const int DayMs = 24 * HourMs;
public const int WeekMs = 7 * DayMs;

static bool method_state_6, method_state_7;


static InputPort anyinputfor6 = new InputPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled);
static InputPort anyinputfor7 = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.Disabled);
static OutputPort ph = new OutputPort(Pins.GPIO_PIN_D2, true);
static OutputPort b = new OutputPort(Pins.GPIO_PIN_D3, true);
static OutputPort a = new OutputPort(Pins.GPIO_PIN_D4, true);
static OutputPort drain = new OutputPort(Pins.GPIO_PIN_D5, true);
static OutputPort solenoid = new OutputPort(Pins.GPIO_PIN_D6, true);
static OutputPort heater = new OutputPort(Pins.GPIO_PIN_D7, true);
static OutputPort phcontroller = new OutputPort(Pins.GPIO_PIN_D8, true);
static OutputPort tdscontrollerA = new OutputPort(Pins.GPIO_PIN_D9, true);
static OutputPort tdscontrollerB = new OutputPort(Pins.GPIO_PIN_D10, true);
static OutputPort led = new OutputPort(Pins.GPIO_PIN_D11, true);



public static void Main()
{

try
{
Thread led_proc = new Thread(new ThreadStart(turn_led));
led_proc.Start();
while (true)
{

method_state_6 = method_state_7 = true;


Method_1();
call2_5();
call6_8();
Method_10();
Thread.Sleep(10000);

}
}
catch
{
//Something has gone wrong; reset to a safe condition
}
}


static void turn_led() //turn led for 16 hr and off for 8hr in loop
{
while (true)
{
led.Write(false);
Thread.Sleep(HourMs * 12);
led.Write(true);
Thread.Sleep(HourMs * 12);
}
}

public static void call2_5()
{
Thread t2 = new Thread(new ThreadStart(Method_2));
t2.Start();
Thread t3 = new Thread(new ThreadStart(Method_3));
t3.Start();
Thread t4 = new Thread(new ThreadStart(Method_4));
t4.Start();
Thread t5 = new Thread(new ThreadStart(Method_5));
t5.Start();
#region Wait for finishing 2-5 methods
t2.Join();
t3.Join();
t4.Join();
t5.Join();
#endregion
}
static void call6_8()
{
Thread t6 = new Thread(new ThreadStart(Method_6));
t6.Start();
Thread t7 = new Thread(new ThreadStart(Method_7));
t7.Start();
Thread t9 = new Thread(new ThreadStart(Method_9));
t9.Start();

// wait for Method_9 finishing
t9.Join();
method_state_6 = method_state_7 = false;
}
public static void Method_1()
{
drain.Write(false);
Thread.Sleep(16 * MinuteMs);
drain.Write(true);
}
public static void Method_2()
{
solenoid.Write(false);
Thread.Sleep(16 * MinuteMs);
solenoid.Write(true);
}
public static void Method_3()
{
a.Write(false);
Thread.Sleep(182 * SecondMs);
a.Write(true);
}
public static void Method_4()
{
b.Write(false);
Thread.Sleep(100 * SecondMs);
b.Write(true);
}
public static void Method_5()
{
ph.Write(false);
Thread.Sleep(5 * SecondMs);
ph.Write(true);
}
public static void Method_6()
{
Thread.Sleep(5 * MinuteMs);
while (anyinputfor6.Read() == true && method_state_6 == true)
{
phcontroller.Write(false);
Thread.Sleep(1 * SecondMs);
phcontroller.Write(true);
Thread.Sleep(5 * MinuteMs);
}
}
public static void Method_7()
{
Thread.Sleep(5 * MinuteMs);
while (anyinputfor7.Read() == true && method_state_7 == true)
{
tdscontrollerA.Write(false);
Thread.Sleep(5454);
tdscontrollerA.Write(true);
tdscontrollerB.Write(false);
Thread.Sleep(3000);
tdscontrollerB.Write(true);
Thread.Sleep(5 * MinuteMs);
}
}
public static void Method_9()
{
heater.Write(false);
for (int i = 0; i < 14; i++)
{
Thread.Sleep(1 * DayMs);
solenoid.Write(false);
Thread.Sleep(20 * SecondMs);
solenoid.Write(true);


}
heater.Write(true); // added this
}
public static void Method_10()
{
drain.Write(false);
Thread.Sleep(16 * MinuteMs);
drain.Write(true);
solenoid.Write(false);
Thread.Sleep(16 * MinuteMs);
solenoid.Write(true);
Thread.Sleep(1 * MinuteMs);

}

}
}

perkunas
11-14-2012, 05:57 PM
Wow, not even one reply, sounds like this site has shortages of programers lol

alykins
11-14-2012, 06:57 PM
what are you trying to accomplish? I don't get what it is you're trying to do... how about something like


while(method_state_6 == true)
{
do
{
...
}while(!anyinputfor6.Read());
}


but I am shooting in the dark here- can you make it clearer what your attempting?

Edit: It looks like you're trying to snake a value off that pin being tripped.... I haven't worked with that PIC so idk the API or the pinouts, but what about tying it high and then invoking the .Read()? You need something to hold that status true until you .Read() it and then flip it off; I imagine the PIC has that functionality. But are you trying to read it on the .Read() being true or false? Also what does the circuit look like on the tail end of that input? If you have nothing filtering the VS and it is rippling it could be flicking true-false-true-false-true-false etc. There are a lot more pieces here than just the code in play.

Edit Edit: Also from my xp here there are little to no EE's so without knowing about this from EE background (self) the amount of ppl looking at this that would know what it is you're even attempting is minimal if not null (in short need a lot more detail :) maybe post a pic of circuit as well)

oracleguy
11-15-2012, 06:16 PM
but I am shooting in the dark here- can you make it clearer what your attempting?


This is why no one replied.

Your code is incredibly obtuse and hard to follow. "Method_1"? Seriously, that gives no indication what the function is supposed to do. For someone to look at your code and understand what it is supposed to be doing is nearly impossible. I'm impressed that you are able to keep it straight. Easier to follow code is much easier for people to help you with it.



Edit Edit: Also from my xp here there are little to no EE's so without knowing about this from EE background (self) the amount of ppl looking at this that would know what it is you're even attempting is minimal if not null (in short need a lot more detail :) maybe post a pic of circuit as well)

Yeah, not a lot (read: hardly none) developers with embedded experience hang out on here. I'm one of them and alykins is the only other person I can remember off the top of my head.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum