CoDeSys:BOOL 变为“*** INVALID:16#02 ***”外部情况(两个变量之间的链接)
当我跟踪我的程序(使用断点和单步在线)时,我看到, 当到达 Step:=Step+1;
行时,VAR SOpen 变为“* INVALID: 16#02 *”。
更仔细地观察跟踪,我发现在第一次调用“0:”时,Step 从 0 变为 1。这两个 VAR 是两个初始化的并且似乎是链接在一起的。额外的增加将 Step 设置为 2(在第一次运行中!)并将 SOpen 设置为无效。
PROGRAM PLC_PRG
VAR
SerIO: SERCOMM;
Step: BYTE := 0;
Input: ARRAY [0..50] OF DWORD;
SOpen: BOOL := FALSE;
END_VAR
IF Eingang1 THEN
CASE Step OF
0:
IF NOT SOpen THEN
SerIO.FB_ACTION := Open;
SerIO.RECEIVE_BUFFER:=Input[0];
SerIO.COMPORT:=1;
SerIO.EN:=TRUE;
Ausgang1 := NOT SerIO.ERROR;
SOpen :=TRUE;
SerIO.EN:=FALSE;
END_IF;
1:
IF SOpen THEN
SerIO.FB_ACTION:=Read;
SerIO.EN:=TRUE;
Ausgang1 := NOT SerIO.ERROR;
Ausgang2 := (SerIO.BYTES_DONE>3);
SerIO.EN:=FALSE;
END_IF;
2:
IF SOpen THEN
SerIO.FB_ACTION:=Close;
SerIO.EN:=TRUE;
Ausgang1 := NOT SerIO.ERROR;
SOpen :=FALSE;
SerIO.EN:=FALSE;
END_IF;
END_CASE
Step:=Step+1;
IF Step>2 THEN Step :=0; END_IF;
ELSIF SOpen THEN
SerIO.FB_ACTION:=Close;
SerIO.EN:=TRUE;
SerIO.EN:=FALSE;
SOpen :=FALSE;
Step:=0;
END_IF;
When I trace my program (online with breakpoint and singlestep) I see,
that the VAR SOpen becomes "* INVALID: 16#02 *" when the line Step:=Step+1;
is reached.
Watching the trace more careful, I saw, that Step changes from 0 to 1, in the first call of "0:". The two VARs are the two initialized and seem to be linked together. The aditional increase sets Step to 2 (in the 1st run!) and SOpen to invalid.
PROGRAM PLC_PRG
VAR
SerIO: SERCOMM;
Step: BYTE := 0;
Input: ARRAY [0..50] OF DWORD;
SOpen: BOOL := FALSE;
END_VAR
IF Eingang1 THEN
CASE Step OF
0:
IF NOT SOpen THEN
SerIO.FB_ACTION := Open;
SerIO.RECEIVE_BUFFER:=Input[0];
SerIO.COMPORT:=1;
SerIO.EN:=TRUE;
Ausgang1 := NOT SerIO.ERROR;
SOpen :=TRUE;
SerIO.EN:=FALSE;
END_IF;
1:
IF SOpen THEN
SerIO.FB_ACTION:=Read;
SerIO.EN:=TRUE;
Ausgang1 := NOT SerIO.ERROR;
Ausgang2 := (SerIO.BYTES_DONE>3);
SerIO.EN:=FALSE;
END_IF;
2:
IF SOpen THEN
SerIO.FB_ACTION:=Close;
SerIO.EN:=TRUE;
Ausgang1 := NOT SerIO.ERROR;
SOpen :=FALSE;
SerIO.EN:=FALSE;
END_IF;
END_CASE
Step:=Step+1;
IF Step>2 THEN Step :=0; END_IF;
ELSIF SOpen THEN
SerIO.FB_ACTION:=Close;
SerIO.EN:=TRUE;
SerIO.EN:=FALSE;
SOpen :=FALSE;
Step:=0;
END_IF;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我现在将 VAR 转移到 VAR_GLOBAL。这并不是我真正想要的,但现在它有效了。欢迎更好的解决方案并将被接受:)
I transferred the VAR now to VAR_GLOBAL. That's not really what I want, but now it works. Better solutions are welcome and will be accepted :)
问为什么要将 CASE 语句放在 IF 语句中? IF 语句应该调用你的步骤?
在这里调用 FB,从上面的代码获取输入。
有时,如果您不执行全部清理,并且变量列表可能会出现混乱,则有时很难判断无效。
抱歉,我没有看到太多帮助,它来自干净的项目,并查看尚未调用的无效指针。
Question why would you place the CASE statement in an IF statement? The IF statement should be calling your steps?
call FB here that gets inputs from above code.
It's hard to tell the INVALID sometimes if you don't perform a clean all and the variable list gets out of wack that can happen.
Sorry not much of a help I have seen the invalid and it came from clean project and looking at invalid pointer that haven't been called yet.