The idea behind Function Blocks is to provide a pre-canned solution to a machine function.
The simplest function blocks are the TON timers and CTU counters that we all use. Looking at the timer, the ideas of Time base, preset, accumulator, done bit, timing bit and enabled bit are all taken care of by the function block. You never need to go "inside" to see how it works or to debug it because it is already done.
Now imagine a machine builder with a machine with 20 identical index tables. It is very advantageous to be able to write one function block for an index table and use it 20 times. If there is a change in the way the index tables need to function, he changes the code once and automatically he knows the change is applied identically to all index tables. Trying to do something like that in ladder becomes a nightmare of indirect addressing or you have 20 versions of the same code with different addresses. Either way, it's very messy.
To have a decent implementation, the builder needs to make the function block "bullet proof" with extensive testing, using logical status or error outputs from the block and also checking the inputs for things like proper type and range. Done properly, there is nothing for the maintenance person to do besides check if the inputs to the block are what they should be and to look at what the status code coming out of the block is. And, once they figure out how one of the index table blocks work, they know how they all work.
As others have stated, structured text is invaluable and easier to follow for intensive math usage or also for string manipulation. An example of this may be parsing an ascii string received from a gage to pull out the actual dimension and convert it into a number.
The big pitfall I have seen with structured text is when people use it to try to mimic ladder and forget that a rung has two functions:
- Put a 1 in the bit box when the conditions solve true
- Put a 0 in the bit box when the conditions solve false
It is this 2nd one that trips up many programmers. In ST, when you have an IF without an ELSE, you are generally creating a Latch. Fine if you want to use a latch but not if you want to mimic a standard output rung.
The other place where I have used ST and like it is with CASE statements. When you have to do one of several things based on a number this statement lets you selectively run code in a clear way or create a "state machine" if you know that terminology.