Is it possible to write function blocks with some static parameterization? Specifically, can I make a buffer with a static capacity, but such that different instances can have different capacities?
Ideally, I'd imagine some constant parameters, like so:
FUNCTION_BLOCK FB_Buffer
VAR_INPUT CONSTANT
StorageSize : DINT;
END_VAR
VAR
Storage : ARRAY [1..StorageSize] OF REAL;
END_VAR
Instancing would then be something like this:
FUNCTION_BLOCK FB_Usage
VAR
SmallBuffer : FB_Buffer := (StorageSize := 10);
LargeBuffer : FB_Buffer := (StorageSize := 1000);
END_VAR
Assuming this isn't possible, what is the best approach to manage different storage sizes for different function block instances?
I'll post my least-bad workaround as an aswer.