Cancel
Showing results for 
Search instead for 
Did you mean: 

Make a method run an action after it has waited a certain amount of time for a specific condition.

Valued Contributor
Valued Contributor

Hello,

 

My situation is this. I have three stations that are set up to run dependently. They only start processing once all three are ready. I am achieving this using a combination of three entrance controls, with one located on each station.

 

My problem is I want to set it up so that they move on after remaining unready for a certain amount of time. For example: an MU enters the first station, that station waits to process the MU until the other two stations are full. Hours pass because the MU in the first station is the end of an order and no more MUs are coming.

 

I would like the station to recognize that a certain amount of time has passed and that it should go ahead and process instead of continuing to wait.

 

For reference, I am pausing each station as an MU comes in, and then using a waituntil statement on the first station to waituntil all three stations are paused. That is how I am achieving the stations waiting till all three are ready.

 

My first thought was of using another waituntil statement combined with some kind of timer, but I'm not sure how to have this new waituntil statement override the original one. In addition, I'm not really of the best way to identify how much time has passed since the method was activated.

 

Thank you for any suggestions!

7 REPLIES

Re: Make a method run an action after it has waited a certain amount of time for a specific conditio

Legend
Legend

I did something similar.

Not elegant, but before your waituntil statament call a "Timer" method with methcall.

Something like:

is

do

flag := false;

wait (time);

flag := true;

end;

 

in the waituntil statement which you have already done, you should add the condition "or flag = true".

In this way you can exit from the statement if one condition is met.

If you meet the first condition, the timer will be not useful anymore, so you must terminate it to avoid unexpected behaviour.

Re: Make a method run an action after it has waited a certain amount of time for a specific conditio

Valued Contributor
Valued Contributor

Hm yeah, I was hoping for something a little more straightforward, but that should definately work, I'm pretty sure I understand everything well enough to do it, but I'll pop back in if I have anymore questions.

 

Thanks for the answer!!

Re: Make a method run an action after it has waited a certain amount of time for a specific conditio

Valued Contributor
Valued Contributor

Ok I do have a question or two. In your timer method you are using what I believe to be a local variable called flag. How are you getting the state of this local variable to the Entrance control? I tried creating a user defined attribute on the method and using that as the flag, but I keep getting an error.

 

Also, you mention to terminate the timer when I am done with it, this makes sense, but I'm not entirely sure how to do that. What do you recommend?

Re: Make a method run an action after it has waited a certain amount of time for a specific conditio

Legend
Legend

I created a small example.
Have a look and let me know if you understand what I mean.

 

I'm sorry if my model is not so clear, but today I'm in a rushSmiley Happy

 

Re: Make a method run an action after it has waited a certain amount of time for a specific conditio

Valued Contributor
Valued Contributor

No problem at all, the example does definitely answer my first question. However, the thing I'm still not clear on is you mentioned earlier that I should terminate the timer once it is not needed so it doesn't cause weird behavior.

I agree with that, especially with my current use case, but I cannot figure out how to effectively terminate the method.

Re: Make a method run an action after it has waited a certain amount of time for a specific conditio

Legend
Legend

In the example for me "terminate the method" means not change the variable flag.

Basically after the wait line, I check wheter the mu which called the timer is still on the singleproc or not. If not, I don't change the value. In this way if you have several instances of the method running, only the right one will change the value.

 

You can't directly close the method unless you create a wait command using a loop cycle. But this probably will affect your performance!

Re: Make a method run an action after it has waited a certain amount of time for a specific conditio

Valued Contributor
Valued Contributor
Oh ok I see. In my experimenting I had thought about just setting it up in such a way that there could be multiple instances of the timer method running, but I hadn't though of checking the MU to determine if it would be acting on the right part.

Thank you that should do it. Have a good day!