Forum Italiano sui Prodotti NI

annulla
Visualizzazione dei risultati per 
Cerca invece 
Intendevi dire: 

case structure con tunnel di build array

Salve ho un problema apparentemente semplice ma che non sono riuscito a risolvere durante tutta la giornata.

 

Devo fare una cosa semplice: devo riempire un array durante un ciclo while solo quando una condizione e' vera. Se la condizione invece e' falsa devo smettere di riempirlo.

Fatto questo alla fine del ciclo while porto l'array fuori con il tunnel e lo scrivo in un file di testo.

 

Ho scritto il codice che segue, ma quando la condizione e' falsa invece di non scrivere niente, l'array continua ad essere riempito con tutti 0...

 

Come dovrei fare? potete mostrarmi un esempio per capire dove sbaglio?

 

grazie a tutti

 

true.PNG

false.PNG

0 Kudos
Messaggio 1 di 9
5.430Visualizzazioni
  • Your loop stops when you have ~100 iterations, not when the boolean is false.
  • You need a shift regsiter in the outer while loop and append data to it whenever the case is true. Wire it across unchanged in the false case.
0 Kudos
Messaggio 2 di 9
5.420Visualizzazioni

ty altenbach,

I didnt say that my loop stop when the boolean is false. I said the array filling, have to stop when the case is false.With this code it is filling up with 0 when the case is false.

 

can you show me an example about use of shift register in this case pls?

0 Kudos
Messaggio 3 di 9
5.416Visualizzazioni

(Sorry, I guess google translate did not do a very good job :D)

 

 

 

Note the word "stop" and "instead continue", etc. Can be confusing....

 

 Anyway!

 

I don't want to constantly waste time and build VIs from scratch for everybody. Attach your VI and I will modify it for you.

Also make sure the boolean is set to latch action.

Since you know the number of iterations before the loop starts, you should use a FOR loop. Do you instead want to stop once the array has a certain size?

 

0 Kudos
Messaggio 4 di 9
5.409Visualizzazioni

tyvm,

 

I attach here the testVI that I used to expose here my problem (it is a simplified vi to focus the problem) and the real VI where I have to use the correction.

 

Scarica tutti
0 Kudos
Messaggio 5 di 9
5.403Visualizzazioni

Do you want to stop the loop after 100 points have been added or after 100 iterations?

 

Your RealVI code does not make a lot of sense and seems dangerous. You should do a proper state machine instead, one state could be the saving to file. Right now you would lose all data if the file name is invalid or the operator cancels the file dialog.

You also have way too many local variables. None are needed.

 

 

Here's a very quick draft (note the mechanical action of the boolean).

0 Kudos
Messaggio 6 di 9
5.400Visualizzazioni

Hello, ty vm for you correction, finally I understand what it needed.

 

Concerning my realVI, it is still a prototype and I am not expert so that was the best that I can atm.

 

It is a program to control a "signal generator" which change frequency very quickly and I want to save data only when the signal generator change frequency and I want discard all the others.

 

concerning the loca variables: I used the "stop frequency" one, only to avoid a long and unreadable wire.

About the "FreqPrecedente" local variabile, that is the way that I find to do the equivalent of c/c++ language:

 

if( freq_current  !=  freq_previous)

{

  freq_previos = freq_current; 

 

I read again my vi but for me it's not easy to understand where is exactly the "dangerous" part.

btw, ty again for your support 

 

I attach here the realvi Modded with your correction (I killed a local variable too 🙂 )

 

if you have an alternative way to do some istruction in my real vi, any modding is appreciated 🙂

0 Kudos
Messaggio 7 di 9
5.396Visualizzazioni

hi altenbach

 

I am not able to reproduce your mechanical action of the boolean

 

your button switch off as default state everytime u get a True condition

 

how can i do that?

 

in my real progam I should to stop to write in the file after n iterations (when final frequency is reached) 

0 Kudos
Messaggio 8 di 9
5.368Visualizzazioni
Right-click..mechanical action..latch when released.
0 Kudos
Messaggio 9 di 9
5.362Visualizzazioni