01-27-2021 04:14 PM
I built a simple case statement with an internally generated "next case". There are three cases that are intended to set the time of the 0th, 1st, and 2nd time periods, turning an LED indicator on and off. The output pattern would be an offset from the beginning of a "frame" (think motion picture film frame), then turning on an LED for a width in time, followed by the rest of the frame time. It would look something like this in voltage vs. time: _____--___. A sort of electronic shutter.
I've attached the vi. The inputs are the total frame time, the delay before the LED goes on, the on pulse width, both followed by the rest of the frame time.
Ok, so what's my grief? Well, I have read here about using "run continuously", and I certainly don't want that. If I use that mode, it seems to work, but I have a feeling that it's restarting every time the feedback node runs. And if I have an initialization value on the feedback node, the system never leaves that state. Not good.
When I just hit the "run once" I expect it to keep running until I crash it with the abort button. But that is not what happens. It simply runs one loop. A nice loop, but just the one.
Perhaps someone could tell me what my conceptual problem is here, since I also feel that this is pilot error. I have used LabVIEW for many years, but intermittently, and I am just starting out again since my last use in 2012.
Thanks in advance.
Solved! Go to Solution.
01-27-2021 04:24 PM
I can tell from your question that you must be new to LabVIEW. Have you taken the tutorials? How to Learn LV
You say "it simply runs one loop". But you don't have a loop in there at all!
If you want a loop, you need to put one in there. Wrap that code in a while loop. I'm really surprised you've discovered feedback nodes, but aren't familiar with a while loop.
01-28-2021 10:03 AM
Sir,
Thank you for taking your time for a reply, and looking at my vi.
If you run the vi in single-run mode, you will see it stop by itself. Using the debugger, I can see the feedback node operating just once.
Why does it stop? Why does it not run forever?
As far as my experience goes, it is rather varied. I have written instrument controls that allow me to control graphs, and overlay internally generated functions. You get real familiar with property nodes if you do that!
I'll try a while structure around what I've written, but I'm still curious as to why it should stop.
Thanks again.
Bob
01-28-2021 10:12 AM
It won't run forever because it doesn't have a loop around it. Note: the "Run Continuously" button is used strictly for debugging purposes, it is not meant for normal LabVIEW control. The Abort button is meant to abort runaway code, it is not meant to be a stop button for normal operation. The run button is meant to start execution of code while you are in the development environment.
Imagine you were writing code in Visual Basic and it looked like this
x$="Hello World"
Print x$
You hit the run button. How many Hello World 's would you expect it to print?
01-28-2021 10:21 AM
Yes, "Run Continuously" might be better called "Run and Restart" or "Run Repeatedly", since I understand that things are reset to initial conditions at each start. Useful for debugging, certainly. Ok, no problem.
The abort button also, agreed. Things come to a crashing halt.
But I am still having problems seeing why it stopped. I admit that I have a conceptual problem, and I'm going to work on it, now. But I then thought of writing this in procedural code, and guess what: you need some sort of loop.
When I'm straight, I'll drop in another reply.
First thing: a while loop.
Your patience is appreciated.
Bob
01-28-2021 10:31 AM
I'm glad you are working through it.
The reason it stops is because nothing in your code tells it to repeat. The code executes until there is nothing else for it to do. So in the text language, if you want it go go again, then you put a Do While ahead of it and End Loop after it to tell it to repeat. (In old BASIC days, you put a GOTO 10 as the last line. 🙂)
In LabVIEW, if you want the nodes to execute again, you put the While Loop around it.
01-28-2021 10:51 AM
Any chance you've been used to using something like node-red, simulink, or modelica? Those can "seem" similar to LabVIEW in that they're graphical codes, but they do NOT perform like LabVIEW. Those languages are more "descriptive" than programmatic, and looping is inherent in the language. You don't need to manually tell it to run repeatedly, as it's assumed from the start. Simulink code is describing a system, whereas LabVIEW is actually commanding a system. They may look similar but the coding concepts are NOT immediately transferrable.
LabVIEW is much, much more like C, Visual Basic, or Python. It runs one "flow" through the screen for each time you press Run. Data flows from inputs to outputs, one time, one time only. If you want it to run multiple times, you use a loop. To expand on the code analogy, your code is like this (for more of a C flavor):
myString = "Hello World";
print(myString);
What you want is more like this:
myString = "Hello World";
while(true)
print(myString);
end
Text code flows from top to bottom, exactly one time, just like LabVIEW. If you want it to loop, use While or For loops, just like you would in text based code.
01-29-2021 08:36 AM
Thanks for your assistance. Your observations are correct.
In fact, I first used MATLAB in 1985. Simulink when it was SimLab, or something like that. LabVIEW prior to 2009. It was clear to me that the "pictures" one drew in Simulink and those in LabVIEW were not of the same sort at all.
Over time, one becomes a bit rusty. I think I last used LabView for something non-trivial (an embedded ultrasonics controller) in 2011. A lot of bits under the bridge since then, and it has take you and the Knight of NI (clever, that) to remind me. Many thanks.
01-29-2021 09:34 AM
Well, I have come to see it your way. Darned computers don't do what you want, they do what you tell them to do. The two are not always equal.
After staring at the issue, and re-reading the material in the help files, I have begun to understand that the program stopped, as you say, because there was no where else to go. A simple "while" loop fixed that, of course.
I also "discovered" that the case statements tunnel outputs are not available until the specific case statement is finished. I used a case statement in the first place so that I could assign boolean values to a single tunnel out to my LED.
So basically, I had fun. For the heck of it, and so you can see that I am not a total newbie, I've attached the front panel of an ultrasonic device that determines the stress around fastener holes in sheet metal. It did a fair amount of calculation, including Hilbert transforms, peak detection, and extrapolations. This is where I discovered the power and utility of property nodes.
Many thanks, again, for your assistance.
01-29-2021 12:57 PM
@Bob_Lacovara wrote:
I also "discovered" that the case statements tunnel outputs are not available until the specific case statement is finished. I used a case statement in the first place so that I could assign boolean values to a single tunnel out to my LED.
So basically, I had fun. For the heck of it, and so you can see that I am not a total newbie, I've attached the front panel of an ultrasonic device that determines the stress around fastener holes in sheet metal. It did a fair amount of calculation, including Hilbert transforms, peak detection, and extrapolations. This is where I discovered the power and utility of property nodes.
Many thanks, again, for your assistance.
What you are seeing is the data flow rules of LabVIEW in action.
1. A node (whether a function, subVI, or a structure like a while loop) won't execute until all of its inputs are available to it.
2. The node won't exit and return its outputs until all of the code inside of it is done. So a case structure won't return data out of the tunnels until the code inside is done, or a while loop until it has stopped iterating.
That VI looks good. I'm glad I could help you.