08-10-2015 03:03 PM
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?
Solved! Go to Solution.
08-10-2015 03:05 PM - edited 08-10-2015 03:06 PM
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> ---'
08-10-2015 03:06 PM
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.
08-10-2015 04:29 PM
Sorry about not putting this into the other post. I think I have an idea of where I went wrong. Thanks for your help
08-11-2015 09:09 AM
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.
08-11-2015 12:15 PM
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.
08-11-2015 12:29 PM - edited 08-11-2015 12:35 PM
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> ---'
08-11-2015 12:34 PM
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
08-11-2015 12:40 PM
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
08-11-2015 12:44 PM
Here are some free training tools primarily focused on LabVIEW and NI hardware to help get started.
-MyRIO Project Essentials Guide (lots of good simple circuits with links to youtube demonstrations)
Learn NI Training Resource Videos
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> ---'