07-05-2016 02:32 AM
Hi,
I made a loop "for" with
for(i=0;i==359;i++) {//code}
but the program don't want to enter in the loop "for".
Sometimes I have "warning : will never be executed" by speaking about i++ so I tried with i=i+1 this don't change anything. And this error doesn't stop the run of the program that stop only the enter in the loop.
Somebody knows why I have this problem?
07-05-2016 03:47 AM
The problem lies in the exit loop condition: see this page for reference.
07-05-2016 04:35 AM
I have this code :
int CVICALLBACK StartMot (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
int i;
ComWrt(1,"\r",StringLength("\r"));
for(i=0;i==359;i++)
{
/* begin the rotation */
ComWrt(1,"SK(i)",StringLength("SK(i)"));
/* wait 5 seconds the time to make the measure */
ComWrt(1,"\r",StringLength("\r"));
DelayWithEventProcessing (5);
/* stop the measure */
ComWrt(1,"CP(i)",StringLength("CP(i)"));
ComWrt(1,"\r",StringLength("\r"));
//break;
}
GetCtrlVal(panelHandle,PANEL_intervalTimer,&IntervalTimer);
return 0;
}
return 0;
}
I think it's the same that example that you sent me.
07-05-2016 04:56 AM
It seems you have not read the page I linked before Let me quote some text highlighting the relevant one:
for ( init; condition; increment ) { statement(s); }
Here is the flow of control in a 'for' loop −
The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears.
Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and the flow of control jumps to the next statement just after the 'for' loop.
In your case, you set i = 0 entering the for loop; immediately after you test for i == 359, which obviously is false, so the loop does not execute.
That's all.
This is not CVI specific, is pure C syntax.
07-05-2016 05:10 AM
I red it but I didn't understand everything I confess. 😛 So, that means I have to write for (i=0;i==1,i++)?
Because I thought "for" function was "from i=0 to i=359 you have to do i++" so it works by doing :
i=0
i=1
i=2
...
i=359
it doesn't work like that?
07-05-2016 05:39 AM
A programming language is highly structured and you must understand how the convention works in order to exploit it at best.
While in Basic you would write
for i = 0 to 359
in C you must write
for (i = 0; i < 360; i++)
In both cases, the for loop is executed for each value of i starting from 0 and ending at 359 inclusive. The condition clause in C syntax must be true for each value of i in that interval, and i < 360 is the only one that guarantees that.
07-05-2016 06:30 AM
I tried befor with i<360 but someone told me to change by i==359 because i<360 it was a mix between a while loop and a for loop
07-05-2016 06:32 AM
I think the problem comes from DelayWithEventProcessing but I don't know what is this problem
07-05-2016 09:12 AM
I saw your thread in the french forum: don't trust a LabVIEW programmer as an advisor for CVI!
Let's start from scratch and see if we can proceed from a very simple structure to a more complex one.
First of all, do not consider acquisition from the external device, simply create the for loop that handle the motor adding a simple Delay (1.0) inside the loop insteaf of 5-sec pause. Work on this structure until it works well handling the motor.
When you are done with it, modifiy it with a Delay (5.0) so that the process can wait for the acquisition. Do not include yet communications with the acquisition device.
When you are done with it, replace the Delay with DelayWithEventProcessing, which as you can see by looking at the source code is simply a small loop that includes calls to ProcessSystemEvents (). Still do not process any other task. You should see the motor stepping with 5-sec pauses between steps.
Only at this moment you can consider to add other tasks like the communications with the other device. You will need to design how those two tasks interact with each other, but let's proceed step by step and complete the preceding steps before.
07-06-2016 01:45 AM
It's a good idea ! I will try this method to find where the problem comes from!
Anaël.