I'm trying to develop a package/module in golang which will work similar to a PLC function block.
The main difference between PLC function and function block involves internal memory. So for instance, a function can be described as something like an equation or formula that accepts inputs and calculates an output value. Moreover, it always returns the same output value for the same inputs. In contrast, a function block relies on internal memory. So it is possible to have a different output value with the same inputs because there is another value stored in memory that has an impact on the final output value.
Are there any ways to achieve this in golang?
For example, I want to create a timer block (TON) with inputs IN (bool-start timer), PT (int64-set duration of the timer) and output Q (bool-is the set duration reached), ET (int64-elapsed time) The way it should work is, this method will be called in an infinite loop and must retain it's last state and do it's job!
TON FB: https://help.codesys.com/webapp/ton;product=codesys;version=3.5.11.0