如果在plc中的结构化文本中语句
我有一个像这样的功能块:
FUNCTION_BLOCK chujwamwdupe
VAR_INPUT
en:BOOL;
val:INT;
END_VAR
VAR_OUTPUT
oval:INT;
END_VAR
VAR
END_VAR
和代码:
IF (en = TRUE) THEN
oval := val;
END_IF
非常简单。为什么这个块总是执行的?无论en是真实还是错误,它总是会将椭圆形变为Val。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设在PLC上,您是指我用3.5.18.0尝试了这一点,并且在这种情况下,编译器似乎使用可变提升。将代码重组为类似:
您可能想要的是将椭圆形作为这样的输入输出变量:
如果定义为输入输出变量椭圆形,
则如果您不想保留其原始值,则将保留其原始值
您可以初始化椭圆形:
或者可以添加其他语句:
I assume with PLC you mean CODESYS I tried this out with 3.5.18.0 and it seems the compiler employs variable hoisting in this case. Restructuring your code to something like this:
What you probably want is to use oval as an input output variable like this:
If defined as an input output variable oval will retain its original value if en is False
If you dont want to retain its original value
You could initialize oval:
Or you could add an else statement:
我已经用Twincat 3.1.4022对其进行了测试,在这里它可以按照我的意图进行。
但是,FB记得它是从通话到呼叫的椭圆形值,这也许是为什么它看起来总是会更新输出值?
I have tested it with TwinCAT 3.1.4022 and here it works as I think it is intended.
But the FB remembers it's oval value from call to call, is this maybe why it looks like it always updates the output value?