Channel problem 2

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
carnm92
Posts: 7
Joined: Wednesday 21 January, 2015 - 10:33

Channel problem 2

Post by carnm92 »

Hi!
I'm here again with a question I can not solve, and i'm sure it's not so difficult. It's related to another post i've made recently.
I have a robot with 3 possible outputs.I want it to send by channel 1 the atoms named 'mec' and other atoms by channels 2 and 3, but not in a random way, but to the first open channel of these two (channels 2 and 3), I mean to the one which has been longest waiting.
I don't know how to set that in 4DScript. I have this example but is the 'random case', and i would like to modify it.

If(
CompareText(Name(first(c)), [mec]) = true,
1,
IndexMax(NrOC(c)-1, OCReady(Count + 1,c)*Random(100000)) + 1
)

Can anyone help me?
Thanks a lot!!
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Channel problem 2

Post by HarryBunnik »

Ha Carnm92,

I've made a small example model in which every third product has the name "mec".
Test.mod
(17.49 KiB) Downloaded 243 times
As you see I made a different type of SendTo statement (code below). After all I need the time at which the last product entered the atom behind the robot (in my case a simple server).

Code: Select all

Case(
  WhichIsTrue( 
    CompareText(Name(first(c)), [mec]) = true,
    Label([LastEntryTime], out(2, c)) <= Label([LastEntryTime], out(3, c)),
    1=1
  ), 
  1,
  2,
  3
)
This time stamp I record with a label [LastEntryTime], which I set when a product leaves the server on the chosen conveyors behind (see the OnExit code of the server).

Code: Select all

Label([LastEntryTime], out(OC(c), c)) := Time
Additionally I've placed a initialize atom to reset the labels to 0 when the reset is pressed.

I hope this helps you further!

Cheers,

Harry
Post Reply