Discussion:
Subvi help serial communication
(too old to reply)
jesus.rp
2008-08-07 00:10:05 UTC
Permalink
So here's my problem:  I have a .vi that works fine, and would like to make it into a subvi for another program.  The problem comes when I incorporate it into another .vi as a subvi the main.vi doesn't update the values being passed.  The main .vi does start the subvi, but on the main.vi the values I would like to monitor aren't updating.  Any suggestions?Hart1529.vi is the subvi, and test.vi is the main.vi i'm using as a stripped down example (that I was hoping would work).


Hart1529.vi:
http://forums.ni.com/attachments/ni/170/347319/1/Hart1529.vi


testsubvi.vi:
http://forums.ni.com/attachments/ni/170/347319/2/testsubvi.vi
Dennis Knutson
2008-08-07 00:10:05 UTC
Permalink
Of course you don't get any updates in the main. Your subVI has a while loop that needs a button press to stop and a subVI will not return any data until it finishes. This is pretty basic to LabVIEW and most other programming languages. Since you do not display the front panel of the subVI, you have no way at all to stop it. While there are ways to get data back from a subVI while it is running, you will have to decide how to stop the subVI. The easiest thing to do is to just display the front panel of the subVI when you call it. That way, you can see the data as it is acquired and also stop it. You could also remove the outer loop in the subVI and not depend on the stop button in that inner loop.
jesus.rp
2008-08-07 00:40:05 UTC
Permalink
Ok thanks for the advice, I'll go with your first suggestion since I was doing that before.  Also Dennis, can you clarify or point me to where I can read this somewhere?  "Your subVI has a while loop that needs a button press to stop and a subVI will not return any data until it finishes."  I don't see any values output whether it's done or not.  Even if I hit stop, there is never any values sent to the main.vi.  By your explanation shouldn't the final value be sent to the main.vi?  Thanks.
Dennis Knutson
2008-08-07 01:10:08 UTC
Permalink
You should see the very last thing acquired when you click the stop button on the subVI. This does not mean the 'Abort' button on the toolbar or the stop button on the main VI. I don't have any equipment to connect to a serial port here but by doing some editing and using constants, when I modify the subVI, that seems to work for me.
As far as LabVIEW training, I would recomend you start at <a href="http://www.ni.com/academic/lv_training/how_learn_lv.htm" target="_blank">http://www.ni.com/academic/lv_training/how_learn_lv.htm</a>
mikeporter
2008-08-07 03:10:05 UTC
Permalink
Your question concerns an issue that I lean on pretty heavily when teaching a LV Basics course. It has to do with the way LV executes code. The thing to remember is that ther are only two rules that define how LV executes code and when it generates results: Rule 1: Any node (and a "node" can be about anything on your block diagram - programming structures, functions, subVIs, etc) will begin executing as soon as all its inputs are satisfied. Basically, this means LV is an inherently parallel programming language, This is one of the big differences between LV and privative text-based languages such as C++.Rule 2: A node will only output data when it finishes executing. This is the one that you are running into. An indicator that has its terminal located inside a loop will update each time the loop iterates, but move the terminal outside the loop and it will only update when the loop finishes. Nodes that are subVIs behave the same way. They only generate outputs when they finish executing. Hope this helps...Mike...PS: getting into a LV Basics course would probably be money well spent.
Loading...