LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to create a subvi


Very nice.  Much improved!  In this situation, I think you can eliminate your outer while loop since it only runs once with the true constant wired to the stop terminal.  You won't need the shift registers because the get initialized on every call by way of the terminals wired in.
 
A single run while loop with uninitialized shift registers is a characteristic of a functional global variable, LV2 style global, or action engine.  With these, the shift registers are uninitialized.  There will be a case structure called initialize, (or set value, or something like that) which takes inputs and feeds them to the shift register where the values are stored for later calls of the subVI.
 
You can also move the multiplication all the way inside to the false case since that is the only location where they are used.  You can also use the compound arithmetic function set to multiply to do the math in 1 step rather than 2.  Not that you need to, just so you know that the other function exists.  Compound arithmetic is especially useful for multiple OR or AND functions.


sorry, i am kinda lost right now.
so i cannot use the while loop just to take out the local variables by using shift registers?
can you show me a picture of what you mean. i made this, i dont know if i am doing what you suggested.






Message Edited by krispiekream on 07-10-2008 04:23 PM
Best regards,
Krispiekream
Download All
0 Kudos
Message 21 of 41
(1,985 Views)
this code actually look nice, but the pressure is not displaying to the front panel.
i dont know if i am doing it wrong or the semaphore is not working?

Best regards,
Krispiekream
0 Kudos
Message 22 of 41
(1,978 Views)
maybe i did this wrong.





Message Edited by krispiekream on 07-10-2008 04:56 PM
Best regards,
Krispiekream
0 Kudos
Message 23 of 41
(1,973 Views)
The reason you have no pressure is that an error occurred while acquiring the semaphore.  So the Press Query subVI may not have executed based on that error.
 


krispiekream wrote:
sorry, i am kinda lost right now.
so i cannot use the while loop just to take out the local variables by using shift registers?
can you show me a picture of what you mean. i made this, i dont know if i am doing what you suggested.



You don't have any locals in the subVI anymore to worry about.  Remove that while loop and you'll see the subVI behaves the same.
 
Where you want your while loop and your shift registers is in your main VI wrapped around the snippet of code you posted.  By doing that, you can eliminate the Pressure local variables.  Just put an indicator, or a write local variable after the subVI so it updates the display.  But the wire will continue to the right, hit your master while loop into a shift register, and will be available at the left hand shift register.


Message Edited by Ravens Fan on 07-10-2008 06:21 PM
Message 24 of 41
(1,960 Views)
ok...
let me try to show you the advice i have taken and see if what you told me is what i did.






this program only go to the true case and never the false






Message Edited by krispiekream on 07-10-2008 05:46 PM
Best regards,
Krispiekream
Download All
0 Kudos
Message 25 of 41
(1,955 Views)
i went back to not using semaphore and i got this from it.
this one works.
the subvi that we created works too.

Best regards,
Krispiekream
Download All
0 Kudos
Message 26 of 41
(1,939 Views)
I see where your problem is!  You aren't using the semaphore properly.  Did you look up semaphores in the example finder?  If you haven't, make sure you take a look at the example "Semaphore with SubVI's." first.
 
In your subVI, you never wired up the control for the semaphore reference to the connector pane.  When the subVI runs, it has an empty semaphore reference which throws an  error when you try to acquire it.  It doesn't know what semaphore to acquire.
 
1.  Wire up your semaphore reference in and out to the connector pane in the subVI.
2.  In your main VI, make sure you use the Create Semaphore function in the initialization part of your code.  Use the green reference wire that comes out throughout your code.
3.  Wire that green reference wire to each of the Semaphore terminals in all the subVI's that use it.
4. When your code ends, use the Destroy Semaphore function in the cleanup part of your code.
 
One question I have is if it works without the semaphore, do you really need to use it?  Semaphores are designed to prevent 2 or more sections of code from simultaneously accessing the same resource.  Often that would be hardware, or a com port, or perhaps opening the same file on disk.  It is basically a lock that prevents a section of code from proceeding until another section of code releases that lock.  Do you need that functionality in your program?  What are you trying to protect and in what portions of code?
Message 27 of 41
(1,914 Views)
Thanks Ravens Fan. I introduced the semaphore to this thread but failed to explain the necessity of creating it in the main VI.

krispiekream, I think you want to put the Release Semaphore in the False case. A portion of the program which has not acquired the semaphore should not be releasing it!

Lynn
Message 28 of 41
(1,896 Views)
krispiekream,
 
You code has evolved well.  You should stick with the latest version that has the semaphores. 
You're close to the solution.
 
R
Message 29 of 41
(1,893 Views)
yup, that was the issue.
thank you everyone for your help.
i kinda like the semaphore style. looks good from my end now.


Best regards,
Krispiekream
0 Kudos
Message 30 of 41
(1,880 Views)