LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

subVI inside event structure wont run a second time.

Solved!
Go to solution

I have a subVI inside a event structure, and it runs when i push a button, inside the subVI is code in a while loop, and when the last piece of code is executed, the while loop stops.  I am having trouble triggerring the event after I have already run it once.  Meaning that I have pressed the button and the code inside the event structure has executed, and while the main VI is still running, I press the same button again and everything works but the subVI.  How would I make that work?

0 Kudos
Message 1 of 24
(4,702 Views)

You should have just asked this in the last thread.

 

You're going to have to share your code at this point because this could be many different things. You probably did something strange inside that subVI.

Cheers


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

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


Message 2 of 24
(4,696 Views)

We can only guess unless you post your code.  Generally you do NOT put anything in an event structure that takes longer than milliseconds to run because it will block your UI.  Without seeing code it's hard to make further suggestions.

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
Message 3 of 24
(4,692 Views)

Sorry about not putting this into the other post.  I think I have an idea of where I went wrong.  Thanks for your help

0 Kudos
Message 4 of 24
(4,640 Views)

OK, let us know if you get stuck again.  Post your code if you're allowed to.  It really helps if we can actually see and test your code.  Smiley Wink

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
Message 5 of 24
(4,534 Views)

So I am stuck again.  the sub VI in the code doesnt stop even when it should have ended because anything that is left to execute is over, and it should move onto the next VI inside the case structure.  I am trying to not force the subVI to abort with the STOP button, because the whole point of creating this program is to make it an event driven program at the to level.  I have included my code.

0 Kudos
Message 6 of 24
(4,504 Views)

From what I can see, you only have the one While loop. You have a STOP node in your Stop Measurement event, but that node is preceded by an Initialize Measurements VI which you haven't included. Is this maybe the source of your problem?

 

Edit: I dived in deeper and see you have that subVI with yet another STOP node and some weird stopping input. How is that control in the subVI pressed if the user only sees the top level VI? You can't expect the application to be able to stop the whole VI if that subVI is running.

 

You need to go through and remove all STOP nodes because you're using them as a crutch and it's letting you have bad programming practices elsewhere. You currently have a While loop that is stopped using a STOP node and all of that is inside of a subVI, which is inside of another While loop, which is inside of an event structure inside of your main While loop. This is insane. My suggestion is to go back and redo your code with the understanding that you can't stop a While loop inside of a subVI without the subVI being in parallel in a queue architecture (or similar).

Cheers


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

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


Message 7 of 24
(4,493 Views)

I downloaded only the Hall Effect with While Loop Tester1.5.vi.

 

How do you expect that VI to work? Event structures are usually inside a loop so they can run repeatedly and the control terminal is usually inside the event case so latch mechanical action works.

 

Using the STOP function is just like using the abort button. 

 

Sequence structures run to conclusion once they have started.

 

It looks like you need a state machine. That would allow you to gracefully shutdown when the stop button is pressed.

 

Lynn

Message 8 of 24
(4,482 Views)

I assume that Hall Effect Real is the Top Level VI and that Hall Effect with While Loop Tester 1.5 is the sub-VI (it is called from Hall Effect Real).  I think you have been told that, in general, sub-VIs do not "show" their Front Panel, hence don't have Event Structures designed to detect Value Change properties of their Front Panel (if you can't "push the button", you can't change the value).  I think you have also been told to NOT (meaning "Do Not") put the Stop (= Abort Execution) function in a VI (unless allowing it to run will cause the Nuclear Power Plant to have a meltdown).  A Sub-VI, like everything else in LabVIEW, uses Data Flow, which means that the set of data passed in when it is called can't be changed from outside once it is called (that's not 100% true, but the exceptions are Advanced Topics for which you are not ready).

 

What do you want to accomplish in this sub-VI?  If it is something like "take a measurement", you can certainly do that, but have it take one measurement, pass it back up to the caller, and have the caller (your Main) control the While loop of taking multiple measurements.

 

If you really understood Data Flow, you would realize that the Sequence structure in your sub-VI is completely unnecessary (except to "take up space" and make it harder to understand your code).  You are also doing very strange (and probably wrong) things with the Error Lines, which usually run left-to-right without bends and never "going backwards" and span the entire VI (with Error In and Error Out for sub-VIs).

 

Do yourself a favor and learn about Clusters.  Use the 4-2-2-4 connector pattern "almost everywhere" for your sub-VIs, with Error In and Error Out in the lower corner connectors.  Cluster related inputs into a single wire, and don't be afraid to have a VI with "empty" connectors (having a common connector pattern for 95% of your VIs will benefit you in the long run).

 

Study "good LabVIEW code" and try to emulate it.  Find a local LabVIEW Guru and get some hands-on help.  

 

If you are really serious about developing a LabVIEW application, something that will (in the long run) be a tremendous time-saver, particularly if you need to bring someone else "up to speed", is to write as complete and detailed a description of your project, including the inputs, outputs, algorithms, decision points, etc. as you can, several printed pages, at least.  If nothing else, it will clarify your thinking.

 

Bob Schor

Message 9 of 24
(4,472 Views)

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>   ---'


0 Kudos
Message 10 of 24
(4,464 Views)