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: 

Requesting single value from DAQ input on button press

I'd imagine this problem has a very simple solution, but I don't seem to be able to find one. I've searched around the forums quite a bit but nothing has answered my question.

 

I have code to calculate a pressure ramp rate inside a case structure, where the 'True' case runs the code and the 'False' case sets flow rate to zero.

 

However, for the calculation to be correct, the software needs to know the starting pressure in order to calculate the incremental set points. Currently I have the "starting pressure" as a manual input. I'm trying to find a way to request the pressure value from the DAQ input on the Boolean button press that changes the case structure to 'True'. I know that a Local Variable will pass the information over, however it will do this once per loop iteration and I don't want to cause any race situations with LVs. Is there a way that the code in the case structure can request a single data value from the DAQ pressure input on the Boolean button press?

 

Apologies if this is very basic. I've been trying to teach myself LabVIEW for the past couple of months and I'm struggling a little!

0 Kudos
Message 1 of 21
(3,304 Views)

You should post what you have done so far.

It is easier for us to give hints if we know where you are....

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 21
(3,300 Views)

I'll post the VI in it's current state when I can get on my work PC. It will probably help if I annotate it before I post it. It's all been developed through trial and error and lots of reading on this forum so I'd imagine that the code is very inefficient.

 

You're all going to rip me to shreds, but I want to learn to get better!

0 Kudos
Message 3 of 21
(3,291 Views)

@MattEff wrote:
[...]

You're all going to rip me to shreds, but I want to learn to get better!


That's the spirit! 🙂

And, btw.: posters get rip only if they prove to be resistant to learning and improving themselves. The worst case to happen normally is to get a honorable mention in the Rube Goldberg thread....

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 4 of 21
(3,284 Views)

Just thinking about it (still don't have access to my work PC). If I put a for loop with a local variable inside the 'True' case structure and set it to run for only one iteration will that just grab the value from the pressure input?

0 Kudos
Message 5 of 21
(3,276 Views)

Have you taken advantage of the LabVIEW Tutorials (such as the ones listed in the upper right of the Forum's Home Page)?  If so, then I suggest you study two more things:  Simple State Machines and the Producer-Consumer Design Pattern, particularly as they relate to Events.

 

Here's how to do this (NI has made it very easy for you).  For the Simple State Machine,

  1. Open LabVIEW.
  2. On the Getting Started screen, click Create Project.
  3. Choose Simple State Machine, and follow the prompts.
  4. When the Project builds, read (and study) the Documentation.  Think about how this "maps" into your current project.
  5. Modify this Project by defining States and Data that apply to your current project.  Don't fret that you are effectively "starting over" -- the benefits you will gain from starting with a Good Design (and a neat Block Diagram and Front Panel) will more than pay for the time it takes to "redo" your current efforts.

Now, to figure out how to handle "Do something when I push this button on my Front Panel", you need to learn about the Producer-Consumer Design Pattern.  Here's how to do that --

  1. Inside a Project (it could be the Project you built for the Simple State Machine), click on File, New ... (those three dots are important).
  2. From VI, From Template, Frameworks, Design Patterns, choose Producer/Consumer Design Pattern (Events).
  3. Study the code that it produces.  The documentation here is sparser than for the Simple State Machine, but you can look at the VI Documentation for the Template, and get Help on any of the VIs and functions that are shown on the Block Diagram.

Give this a try.  Feel free to come back here and ask more questions (though it would help us to help you if you post your code).  When posting more "complete" code that (necessarily) involves several VIs, controls, and a Project, the best way to do this is to compress the folder holding the Project (such as "Simple State Machine", the default folder created for the Simple State Machine project) and attach the resulting .ZIP file.

 

Bob Schor

 

Message 6 of 21
(3,261 Views)

Right - here are a couple of VIs for you guys to have a chuckle at.

 

The first one I've attached is an earlier, simpler version that I've annotated. 

 

The second is the VI in its current state. 

 

What I'm trying to achieve:

When the boolean switch for any of the processes is pressed - take the current pressure value and apply it as the starting pressure for the ramp rate calculation. I only want it to take the current pressure value once for each time the boolean is switched to 'True'. This stops the user having to input the starting pressure manually, negating the risk that the wrong starting pressure is used in the calculations.

 

 

Please go easy on me. This is my first time ever using LabVIEW and I'm really enjoying it so far. However, with zero experience in any sort of coding I am struggling quite a bit. I expect to see some of this code in the Rube Goldberg thread Smiley Embarassed

Download All
0 Kudos
Message 7 of 21
(3,242 Views)

You really, really need to view the tutorials.  Look at your Logging loop in Current Version.  Besides using a Local Variable (which should be avoided, if at all possible -- learn about Shift Registers, for example), ask yourself what you want to do.  I'm assuming that you want the While loop to start running if Logging is true.  When do you want the While loop to stop?  Note that you have wired the local Logging variable to the Stop indicator, so if it is true when you enter, it will (probably) be true when the Local Variable is evaluated, which will stop the loop.  That is, the Loop will (almost always) run exactly once!  Can you see how to fix this?

 

A slightly harder exercise is to figure out how to get rid of the Logging local variable.  There are some simple ways to do this (and some more sophisticated ways, but learn to walk before learning to run), but first try to get a better understanding about how you want to control your entire program, i.e. how the Logging and Stop buttons work and what else is going on in your code.

 

Bob Schor

Message 8 of 21
(3,227 Views)

Thanks for your reply. Unless I've attached the wrong VI, I'm pretty sure the logging code works on my end. The file is created when the VI is started, then logging starts when the button is pressed and continues until the button is switched off. How would shift registers be implemented for the logging loop? 

 

Again, I apologise for my terrible code.

 

I'll have a look at the tutorials.

0 Kudos
Message 9 of 21
(3,221 Views)

Hi Bob, 

 

I've had a go at updating the VI to include a state machine for the logging part. Everything seems to be working ok other than the 'Stop logging' button. When pressed, the state machine should switch back to "File created - Ready to start logging", however the VI just keeps logging. Would you be able to have a quick look to see if I'm on the right track? Thanks for being patient with me - it's taking me a while to get my head around the whole concept.

 

I've attached a .zip containing the VI and the control for the state machine. 

 

 

0 Kudos
Message 10 of 21
(3,130 Views)