Pointer to function block
Hi all,
TLDR, how do i pass a (pointer to) function block to another function block (or program) in PLCNext.
The longer explanation:
Just getting started with PLCNext engineer, but I cannot figure out to get the following to work.
I have am writing control software of a machine that has a tank that must be filled, for this a tank has a pump and some valves and sensors connected. A machine can have multiple of these tanks.
I made a function block that represents a single TANK. (and this actually contains a few function blocks it self to control the hardware)
Now my idea is to have a few state machines that execute a specific use case. Because I have multiple tanks, I want to pass it the pointer to a tank (like tank1 or tank2).
But if I create a variable in PLCNext in the variable list, I can choose 'InOut' to pass reference/address/pointer whatever to a basic type like int,word,etc. But if i choose function block, the only option i can select is 'local' (which i cannot change later on).
Thanks in advance, maybe my solution to handle this is wrong, but i do not want to endup with a case 1234, for every single line in my program.
Comments
"Function block pointers" is a PLCnext Engineer feature that has been on the development roadmap for many years, but unfortunately it probably won't be implemented soon.
As an alternative you could try the old-fashioned way of separating data and function - e.g. define a custom structure for your type (e.g. "Tank"), create one variable of that type for each object (e.g. "Tank 1", "Tank 2"), and then pass each struct as a reference (or as an In/Out variable) to a function block instance that implements the functions of a "Tank", either in the FB itself or as FB methods.
The structs can then be stored in an Array, so (for example) you could iterate through the array in Structured Text and pass each element of the array to a single FB instance in turn. That is sort of like having pointers to FBs ... sort of.
It's unfortunate, but at least now I know I don't need to search any further. Thank you for providing an alternative approach.
Thanks for the clear response.