Bench rig, CPU 1214C, TIA V17. I wrote FB_Valve with an open command, a feedback input and a 5000ms timeout in the statics, and it works fine for valve 1 on Q0.0.
Then I copied the call in OB1, changed the inputs over to valve 2's tags and the output to Q0.1. Now valve 1 won't stay out of it. Command valve 2 from the watch table and Q0.0 comes on as well, and valve 1's timeout starts running.
So I deleted the copy and dragged the FB in fresh from the project tree, a dialog came up, I clicked OK and got exactly the same thing. I swapped the rig wires over too, and the outputs are where I think they are.
Why does the second call change the first one? There was a dialog when I dragged it in and I clicked OK without reading it, is that where I've gone wrong?
Both calls, what does the box above the FB name say, the instance DB? Same name on both?
Both say DB_Valve1. When I dragged it in fresh the dialog was the call options, and I think it picked the existing one out of the list for me. Is that wrong? The inputs are different, so why would the instance matter?
There it is. An FB has memory. Its inputs, outputs and statics live in the instance DB, not in the FB. On each call the input values get copied into that DB and the block works on the DB. Two calls on DB_Valve1 share one memory, so the second call writes valve 2's inputs over valve 1's, that 5000ms timeout is one timer for both, and the output of whichever call ran last is what you see on both valves.
Each call needs its own instance. Delete the second call, drag the FB in again and in the call options choose single instance with a new name, DB_Valve2. Don't pick from the list. Or make both calls multi-instance inside a parent FB, which is what you'll end up doing on real machines.
Logix does the same if you give two AOI calls one backing tag. Different dialog, same headache.
New instance DB_Valve2 on the second call. Valve 2 opens on Q0.1 only, valve 1 stays where it was, both timeouts run separately. Screenshot attached.
Both calls were pointing at DB_Valve1, so the two valves were sharing one set of inputs, statics and outputs without me noticing at all. Giving the second call its own instance was the whole of it.
I get the memory part now. What I'm not sure about is why V17 offers you the list of existing instances in the first place. When would you ever want to call one FB twice on the same DB on purpose? Thanks pnina and louk.
One call, one instance. The dialog default is right, the list is the trap.