基于Beckoff定义的方法的特点之一site是这样的:
All data of a method are temporary and are only valid while the method is executed (stack variables). This means that TwinCAT re-initializes all variables and function blocks, which you have declared in a method, with each call of the method.
有没有办法在plc循环中使用一个方法作为warm start!
这意味着我们使用的方法没有重新初始化并且方法声明变量在我们第一次调用它时只运行一次,其余时间被调用的变量保留它们自己的值?
最佳答案
是的,这可以通过 VAR_INST
或 VAR_STAT
实现。
只需将您的变量声明为 VAR_INST/VAR_STAT
,然后它们将在调用之间保留它们的值。
VAR_INST
意味着它对于方法所在的功能 block 的每个实例都是唯一的,而 VAR_STAT
将充当静态/全局(所有实例将指向到相同的内存位置)。
https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2528798091.html&id=
https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2528787339.html&id=
关于twincat - 如何在 TwinCAT 中热启动一个方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66269561/