LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to write C++ with LabVIEW

hallo
I am trying to write this C++ prog.
for( step2=0, step2<3, step2++)
{
  Y=step2;
  for(step1=0, step1<11, step++)
   {
    X=step2;
    A=measure the Sensor;
    save X,Y,A in a table;
   }
}
with labVIEW (see attachment), the PROBLEM is  Y the first step Y=0 (O.K) the second step Y still =0 instead of 1 and the third Y=1 instead of 2 . where is the problem ?
 
P.S I am working with LV 8.5
 
 Thank you in advance
Toni
0 Kudos
Message 1 of 7
(3,611 Views)

Hey Toni,

Your C++ is slightly confusing, it looks like you're making BOTH X and Y = step2, which means they would both be the same whenever they are fed into the table! Do you mean X=step1 there?

I've attched a modified VI that should mimic the C++, what you will see is that Y=0 while X increases 0,1,2 then Y=1 when X increases again 0,1,2 then Y=2 etc... See screenshot. This is what happens with nested loops like the one you have attached.

If you need something else can you check through the C++ again and post back?

Best wishes,

Mark Lee

Certified LabVIEW Architect
Download All
0 Kudos
Message 2 of 7
(3,601 Views)
Hi Mark
Thank you  for your reply . First you are right  X=step1 and not X=step2.
That is exactly what I want, but  I have to use (stacked Sequence) , so do u have any idea how to use it .
 I am working on 3 axis (X,Y,Z) and every time the axis moves, the sensor must be measured, and all must be saved in one tabel .
At the End all the Axis move to the HOME position.( this is Sequence Nr.2)
 
Thanks again
 
TONI
 
0 Kudos
Message 3 of 7
(3,585 Views)

Hi dctoni,

you should use a state mashine instead of stacked sequences. Take a while loop and a case structure. Every case in the case structure is  a new sequence.

Mike

0 Kudos
Message 4 of 7
(3,569 Views)

Hey Toni,

Thanks for the reply! Using Sequences is OK - all you need to do is pass the value from one frame to the next.

You can do this with flat sequences by just wiring to the right hand border of the previous frame, this will create a tunnel from which you can pick up the data in the next frame.

If you're using stacked sequences (which you were in your original post), you need to right click on the top bar and select 'Create Sequence Local'. This will give you a tunnel with an arrow in it. You can wire into this tunnel the data you want to pass onto the next frame (or subsequent frames) of the sequence (I have done this in the example I've attached). You can drag this tunnel around the border of the frame of the sequence structure if you like.

Please bear in mind that using sequence structures is not a recommended way to program in LabVIEW, there are several limitations to them (discussed really well in LabVIEW Basics 2 last time I checked). If you'd like to try a recommended way, look up state machines on ni.com or around the forums, they're the best way to make your code flexible, scalable and maintainable (and they're really easy to learn to use!)

Good Luck with your project!

Mark

Certified LabVIEW Architect
0 Kudos
Message 5 of 7
(3,568 Views)
Thank you guys
 
0 Kudos
Message 6 of 7
(3,561 Views)
Hi it's me again
 
I have a question , I am trying to save all steps in one table and to make it good , I want to put for each step a number (e.g.1.....10) ,
 
I can put a Nr. just for the first 4 steps and not for all steps , I know why but i didn't find a solution .
so please help me to find another way.
 
Thanks
Toni 
0 Kudos
Message 7 of 7
(3,547 Views)