使用dot赋值参数和将put作为数组赋给函数块有什么不同?
下面是一个简单的示例代码。
Timer1(IN:=TRUE,PT:=T#2S);
IF Timer1.Q THEN
i:=i+1;
Timer1.IN:=FALSE;
END_IF
Timer2(IN:=TRUE,PT:=T#2S);
IF Timer2.Q THEN
j:=j+1;
Timer2(IN:=FALSE);
END_IF虽然它在代码中将FALSE显示为实时值,但它本应通过此Timer1.IN:=FALSE;赋值重置Timer1,但什么也没有发生!

任何帮助都将不胜感激。
发布于 2021-02-14 19:09:00
只有两个字符在结果之间产生了巨大的差异:()。括号表示函数块被调用,这意味着函数块的实现部分被执行。
为了说明不同之处,让我创建一个示例功能块来说明不同之处。
示例
在这里,我定义了一个具有一个输入Increment和一个输出Count的功能块。每次调用函数块时,它都会在实现部分运行代码。实现部分将通过Increment递增当前的Count。
FUNCTION BLOCK FB_Counter
VAR_INPUT
Increment : UINT := 1;
END_VAR
VAR_OUTPUT
Count : UINT := 0;
END_VAR
// Implementation part
Count := Count + Increment; 让我在程序Runner中为这个函数块创建一个实例counter,这样我们就可以看到当我们调用它时会发生什么。
PROGRAM Runner
VAR
counter : FB_Counter;
END_VAR
counter(); // Count is set to 1 since the function block implementation is called
counter.Increment := 2; // Increment is set to 2, Count is still at 1 since the implementation of the function block is not called.
counter(); // Count is set to 3 since the implementation of the function block is now executed
counter(Increment:=1); // Increment is set back to 1 and the function block is called again, increasing the Count to 4.如果您使用断点单步执行上述代码,则可以看到在此过程中的每一步都发生了什么。
https://stackoverflow.com/questions/66141029
复制相似问题