LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

why the push button and stop button does not work in the case structure and while loop of my VI? (code is attached)

Solved!
Go to solution

I am a beginner. I am trying to create a simple VI that switches beetween two types of signals like sine and triangular when someone presses the push button and at the same time record the data in the file on my desktop. Also I have a stop button that stops recording the data.  Here are my dproblems and questions:

 

1.When I press the push button, it does not switch the true and false in the case structure so that I can see the triagular wave stops and the sine starts in the wave form chart. 

 

2.When I press the stop button I want the program still running but the process of writing data in the while loop stops. I do not mind if the wave chart stops too but it would be better for the user to see the waveform is running but the data stops recording.

 

3. The while loop condition did not accept the local variable for stop button inside the loop or inside the case structure so I put the stop button outside of all loops and structure.  (which I know this causes a problem, I do not know how to use a single button many times in one code. The local variable did not work how to create global? do I need to?)

 

4.The data file that it creates hase many rows and columns. I was expecting a column of Time and a column of amplititude of mixed signal based on the pushbutton that user press each time.  I have done that with DAQ and a sensor, It automatically gives me the voltage and time in one column. I tried 2D and 1D and it did not change anything. 

 

Thank you for your help

frontpanel.png

code.png

 



0 Kudos
Message 1 of 14
(6,314 Views)

Your buttons need to be inside the While Loop.

 

The way you have it the buttons will only be read once when the loop starts.

========================
=== Engineer Ambiguously ===
========================
Message 2 of 14
(6,308 Views)
Solution
Accepted by topic author SilasIII

Like you've been told, you are only reading from your inputs at the very beginning and then whatever value they had before you hit run is the value being seen by the rest of the code. LabVIEW programming is based entirely on dataflow and parallelism. This is incredibly powerful and has lead to its success over the years (coupled with the graphical programming), but is usually one of the first things that new developers stumble over. Here's a simple resource to become more familiar with how it works. The Highlight Execution feature is a great way to watch how your application utilizes dataflow.

 

Sine.png

 

Simple code goes like this:

  • While loop containing main code
    • Inside Whle loop is all of the user interaction code or changing input code
    • Stop terminal on While loop is set to stop at certain criteria or user selection of a Stop button
  • Initialization before While loop if needed
  • Closing of references and communications, etc after the While loop

 

This is very simple code. If you want to look in to more advanced architectures that are scaleable, google "LabVIEW State Machine" or "LabVIEW Producer Consumer".

 

If you're just beginning, you should do some free training to get the feel for LabVIEW's capabilities.

"Give me six hours to chop down a tree and I will spend the first four sharpening the axe."  - Abraham Lincoln

 

Here are some free training tools primarily focused on LabVIEW and NI hardware to help get started.

NI Learning Center

NI Getting Started

-Hardware Basics

-MyRIO Project Essentials Guide (lots of good simple circuits with links to youtube demonstrations)

-LabVEW Basics

-DAQ Application Tutorials

-cRIO Developer's Guide

Learn NI Training Resource Videos

3 Hour LabVIEW Introduction

6 Hour LabVIEW Introduction
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
LabVIEW Wiki on Training

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 3 of 14
(6,296 Views)

If I put the stop button inside the while loop of true case structure it accept it. However I have another while loop for the False structure. How can I assign the same stop button twice? I tried to create local variable from it but It gave me error. 

 

For the push button, do you mean I should put it inside the while loop or inside the case structure but outside the while loop?

0 Kudos
Message 4 of 14
(6,288 Views)

@SilasIII wrote:

I am a beginner. I am trying to create a simple VI that switches beetween two types of signals like sine and triangular when someone presses the push button and at the same time record the data in the file on my desktop. Also I have a stop button that stops recording the data.  Here are my dproblems and questions:

 

1.When I press the push button, it does not switch the true and false in the case structure so that I can see the triagular wave stops and the sine starts in the wave form chart. 

 

2.When I press the stop button I want the program still running but the process of writing data in the while loop stops. I do not mind if the wave chart stops too but it would be better for the user to see the waveform is running but the data stops recording.

 

3. The while loop condition did not accept the local variable for stop button inside the loop or inside the case structure so I put the stop button outside of all loops and structure.  (which I know this causes a problem, I do not know how to use a single button many times in one code. The local variable did not work how to create global? do I need to?)

 

4.The data file that it creates hase many rows and columns. I was expecting a column of Time and a column of amplititude of mixed signal based on the pushbutton that user press each time.  I have done that with DAQ and a sensor, It automatically gives me the voltage and time in one column. I tried 2D and 1D and it did not change anything. 

 

Thank you for your help 


Hi Silaslll,

 

You are finding out about something that many beginners struggle with in LabVIEW, so don't let it deter you. The concept of data flow might seem like an annoyance now, but you will get the hang of it and use it to your benefit!

 

1. As RTSLVU stated, as soon as you start the program it reads the values from those buttons, and that is the only time during execution that it reads those buttons! If you want "stuff" to happen at the press of a button, a common method is to use an event structure nested inside a while loop.

 

2. You will need another condition for when to save data to disk and when not to.

 

3. That is probably because you have it set to the "latch" mechanism which doesn't support local variables. Change it to "switch when released" and it should work, but it is good to avoid too much usage of local variables. Everyone has a different definition of "too much", but if you can do things with a shift register (which you can here) then that is preferred by most developers.

 

4. The dynamic data (the thick blue wires from the express VI) are absent from most developer's block diagrams, because they hide the nature of the data inside them. Try switching to a more typical data, like an array of dbl, and it will be much easier to troubleshoot.

Message 5 of 14
(6,283 Views)

@SilasIII wrote:

If I put the stop button inside the while loop of true case structure it accept it. However I have another while loop for the False structure. How can I assign the same stop button twice? I tried to create local variable from it but It gave me error. 

 

For the push button, do you mean I should put it inside the while loop or inside the case structure but outside the while loop?


Every time you run the program, it is only going to run one case or the other, never both. You typically do not want multiple loops in your programs that are not in parallel, unless you know they will execute very quickly (like reading all the data from a serial port). 

 

Try changing your program so that it has one while loop, and inside the while loop you have a case structure containing in one case the sine function and sine graph, and in the other case the tri function and tri graph.

Message 6 of 14
(6,277 Views)
Solution
Accepted by topic author SilasIII

I edited my reply above before realizing you replied. See a basic version of what you can do. As mentioned, you should set up when you actually want to log to file. I don't know how your simulate signal express Vi is set up, but you need to keep an eye on your loop timing. If you acquisition takes care of this timing, then you don't need the Wait function like I put.

Sine.png

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 7 of 14
(6,276 Views)

You should really view some of the training materials listed above first.

 

Then rethink your program architecture while it is still simple, as building on a bad foundation makes the entire structure unstable.

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 14
(6,273 Views)

Hatef, you have posted a VI which never stops. What issue were you trying to address?

0 Kudos
Message 10 of 14
(6,262 Views)