在Codesys中循环的怪异
我试图创建一个定时循环到一个数组中,但是发现某些事情无法正常工作,所以我回到了一个更简单的示例。现在,我发现我的循环一直跳过索引,并具有值。因此,我进入Index0,Index1,Index3仅值。我不明白为什么会发生这种情况,我会显示我的代码。
FOR vCount := 0 TO 9 DO
vVsample[vCount] := INT_TO_REAL(WORD_TO_INT(vVin));
vCount := vCount +1;
END_FOR
结果将是:
vVsample[0] = value vVin
vVsample[1] = did not change the value and is therefore 0
vVsample[2] = value vVin
vVsample[3] = did not change the value and is therefore 0
vVsample[4] = vVin
等到VCOUNT = 10,
我正在使用CODESYS v2.3,并以simmulation模式对此进行了测试
I was trying to create a timed loop into an array but than I discovered something was not working right so I got back to a simpler example. Now I discovered that my loop skips all the time 1 index and places a value. So I get in index0, index1, index3 only values. I do not understand why this is happening, I'll show my code.
FOR vCount := 0 TO 9 DO
vVsample[vCount] := INT_TO_REAL(WORD_TO_INT(vVin));
vCount := vCount +1;
END_FOR
The result will be:
vVsample[0] = value vVin
vVsample[1] = did not change the value and is therefore 0
vVsample[2] = value vVin
vVsample[3] = did not change the value and is therefore 0
vVsample[4] = vVin
etc up to vCount = 10
I'm using Codesys V2.3 and tested this in simmulation mode
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于循环,已经增加了迭代器,因此
vcount:= vcount +1;
行是问题所在。只需将其删除:或更改为ther循环:
FOR loops already do increment the iterator, thus the
vCount := vCount +1;
line is the problem. Just remove it:Or change to a while loop:
我自己发现答案已经准备就绪,就不需要以1数来计数VCount。
执行此操作时,它将始终跳过阵列的一个索引。
我愚蠢的错误
I have found the answer by myself allready it is not needed to count up vCount by 1.
When doing this it will skip always one index of the array.
Silly mistake by me