This is actually quite tricky, since you want to already sort it out before the actual machines based on time. As a result there is some description involved to explain what I did:
1) When a Material 1 (M1) arrives in the queue there are a few things happening:
- I now always create an event that I've defined on the User Events atom with the name "StartCutOff".
This event will check after a certain time (defined as a variable on the initialize atom named "valMaxWaitingTime" with a value of 20 sec).
You can of course adjust this to the value you want. I've made it a global variable, so that there is one central point where I can update this.
- If the content of the second queue doesn't contain an already waiting Material 2 (M2), I close the M1-queue.
- I register this M1 in a table. That allows me to check within the event if this is also the M1 that triggered the current event.
2) When a M2 arrives at the Queue_M2:
- I set the output channel of Queue_M1 to 1 (machine 1) and open the output of Queue_M1.
3) When a M1 is leaving the Queue_M1
- I close the output of Queue_M1 again (this to prevent Machine1 of already receiving the next M1, although there is no M2 available, which would be the normal behavior).
- I unregister this M1 from the table. That way the event is still going off, but can't find it's related M1 in the table and realizes it is already processed, so no action is needed.
Note that the SendTo statement on the Queue is using a label named "OutgoingChannel" which is defining which Exit Channel needs to be taken.
4) When no M2 is arriving within the set waiting time, the event is going off.
- A check is made if the first M1 in the queue (when one there) is also the first line in the administration table. When that is the case, it was waiting for the maximum time and need to be sent to Machine2.
- Again, when the M1 leaves the Queue_M1, this queue is closed.
5) When the processed M1 leaves Machine1:
- a check is done if there is a product waiting for longer than the maximum time.
If so, then its event was already triggered but there was no option to sent it on. So it is still waiting there a should be sent to Machine2.
If there is one waiting for less than the maximum waiting time, it should wait a bit longer until the scheduled Event is triggered and opens the Queue_M1 (or a M2 arrives).
In the initialize atom there are some labels set back to their original value on reset. Also, some global variable are declared here to make the coding a bit easier to read.
I hope it's all clear, but I think that together with the example model you'll figure it out.
And, of course, I hope the model is doing what you have in mind
Success with your project,