From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sequence running correctly

Solved!
Go to solution

Hello.  Just a quick question: can case structures change while continually polled by a while loop?  For my experiment, I require the system to start in one configuration, turn off at the press of a button, and from this off state have a button that triggers another sequence once.  I tried to accomplish this by continually polling a case structure with a while loop, but when I run my program the signal appears as if it's locked in the state at the time of startup (I tried testing it with on startup, off startup and on secondary, and both startup and secondary off).  I suspect I may have to clear some sort of memory on pressing a button, but I'm not totally sure how I should approach this or what VIs I should use.  The fact that my codes within the case structure have while loops (I'm generating pulses) may also have something to do with it.  

 

If you have other suggestions, I would appreciate hearing them.  My goal is to make this program able to switch to all the states I need using only two buttons once it is running.  I may be making this more complicated for myself, but it seems like this would be the most straightforward way after watching the tutorials.

 

I've attached the VI if anyone wants to look precisely at what I've done.  It's a bit complicated, but just ignore anything that doesn't relate to while loops or case structures.  Like I said earlier, the issue isn't choosing between the states, it's switching between them while the program is running.  I am running Labview 2009 SP1.

0 Kudos
Message 1 of 7
(3,002 Views)

Is your VI set to run when opened? When I try to open it LabVIEW becomes totaling unresponsive which is similar behavior to a free running loop (one with no ability to allow a context switch (wait state, dequeue, or similar type of thing)). It will be very difficult to offer any assistance if no one can open your VI.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 7
(2,997 Views)

Sub vi's are your friend! 

Arrays/loops are your friend! 

Open and close DAQ-channels outside loop, so you dont  create/kill them every loop.

 

/Y 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 7
(2,977 Views)
Solution
Accepted by topic author RBeck

I was finally able to open your VI. It takes FOREVER to load. There are so many things wrong with your code it is hard to know where to begin. First, as suggested you need to use subVIs. Also, a general rule in LabVIEW programming is that your VI should fit on a single screen. It is very difficult to keep track of what is going on or see how things fit together when you have to scroll the block diagram in all directions. One major issue that pops out is the level of nesting you have with loops within loops with loops. You do realize that ALL code must complete its execution within a loop before it can advance to the next iteration. You have six parallel loops nested inside another lop. Each of these inner loops is set to terminate on front a front panel control. So, in order to complete an iteration of your loop th euser has to press six stop buttons. To make matters worse you have different stop buttons depending on which case you are in.

 

The best advice I can give you is to throw this code away and start over.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 7
(2,955 Views)

Wow.  I guess it's pretty terrible.  I was having trouble with sub panels so I thought I could just copy and paste all my programming into a single VI. 

 

I'm sorry, I'm still very new and am learning this as I go along.  I guess the only way I can do better is through experience.

0 Kudos
Message 5 of 7
(2,941 Views)

@RBeck wrote:

Wow.  I guess it's pretty terrible.  I was having trouble with sub panels so I thought I could just copy and paste all my programming into a single VI. 

 

I'm sorry, I'm still very new and am learning this as I go along.  I guess the only way I can do better is through experience.


No need to apologize. Everybody starts somewhere. I cringe when I look back at some of the code I wrote when I first started using LabVIEW. Dataflow programming is quite different from traditional text based sequential programming and all the parallalism can be hard to fully appreciate and understand. I recommend going through the online tutorials. Also, start thinking about the overall "what you want to do" and try a few things. Come back here and post what you have done and ask more questions. This is a great forum.

 

I apologize if I came off too hard. I was just being brutually honest.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 7
(2,934 Views)

@RBeck wrote:

Wow.  I guess it's pretty terrible.  I was having trouble with sub panels so I thought I could just copy and paste all my programming into a single VI. 

 

I'm sorry, I'm still very new and am learning this as I go along.  I guess the only way I can do better is through experience.

 


It's not unsaveable. 🙂 Just like with traditional languages, you dont want duplicate code and if you repeat a task it should be a function. The end while loop should ofc be a sub-vi as it's the same in 6 instances. You shouldn't need 6 separate instances, you use a loop, just like you (probably) wouldn't place 6 functions in a C program when you can use a small for loop and place it once. 🙂

 

Sub panels isn't usually needed, you usually only need 1 GUI and then hidden functions/sub vi's to calculate things. Controls/indicators are not storage containers, they are just for input from user (incl calling functions) and returning results, thus you can probably remove many of the lower controls/indicators, and if not, place 1 set in a cluster and place that cluster in an array and you can easily expand and handle them.

 

Start there, and try the feeling out, i think you'll like it. 🙂

 

/Y 

 

 

 

/Y 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 7
(2,929 Views)