在Codesys中循环的怪异

发布于 2025-01-22 22:31:15 字数 563 浏览 2 评论 0原文

我试图创建一个定时循环到一个数组中,但是发现某些事情无法正常工作,所以我回到了一个更简单的示例。现在,我发现我的循环一直跳过索引,并具有值。因此,我进入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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∝单色的世界 2025-01-29 22:31:15

对于循环,已经增加了迭代器,因此vcount:= vcount +1;行是问题所在。只需将其删除:

FOR vCount := 0 TO 9 DO
    vVsample[vCount] := INT_TO_REAL(WORD_TO_INT(vVin));
END_FOR

或更改为ther循环:

vCount := 0;
WHILE vCount <> 10 DO
    vVsample[vCount] := INT_TO_REAL(WORD_TO_INT(vVin));
    vCount := vCount +1;
END_WHILE

FOR loops already do increment the iterator, thus the vCount := vCount +1; line is the problem. Just remove it:

FOR vCount := 0 TO 9 DO
    vVsample[vCount] := INT_TO_REAL(WORD_TO_INT(vVin));
END_FOR

Or change to a while loop:

vCount := 0;
WHILE vCount <> 10 DO
    vVsample[vCount] := INT_TO_REAL(WORD_TO_INT(vVin));
    vCount := vCount +1;
END_WHILE
姜生凉生 2025-01-29 22:31:15

我自己发现答案已经准备就绪,就不需要以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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文