LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to create a subvi

What does the whole system look like? Normally the Create Semaphore and Destroy Semaphore VIs would be in the top level VI and the Acquire and Release VIs in the subVIs where contention for the resource takes place. What you show does not prevent any other part of the program from grabbing the Press_commport. The semaphore will not exist outside the Lock_Read_Press.vi.

Lynn
Message 31 of 41
(1,802 Views)
oh...
then i could be doing it wrong.
can you show me how it would be done?
here is my subvi

Best regards,
Krispiekream
Download All
0 Kudos
Message 32 of 41
(1,799 Views)
how about like this

Best regards,
Krispiekream
0 Kudos
Message 33 of 41
(1,796 Views)

Closer, but still not there.  You've just moved the create semaphore out of the subVI.  You still have a new semaphore (and different) semaphore created at each location it is used.

Think of how queues are used.  You Obtain a queue at the beginning of the program.  Pass that reference to the location that does the dequeueing and all the locations the to the enqueueing.  Destroy the queue when the program ends.  You need the same situation for the semaphore.  Create a single semaphore at the beginning of the program.  Pass that location to each section of code where you want to prevent items from simultaneously do some action.  Destroy the reference at the end of the program.

Look back at my Reply 27.



Ravens Fan wrote:
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.


Message 34 of 41
(1,787 Views)
Those pictures are difficult to decipher since not everything can be seen.

From what I can see, it appears that your program currently looks like this:
While loop (Temperature cycling)
3-frame stacked sequence structure
while loop (Pressure cycling)
5-frame stacked sequence structure
Case structure (boolean selector)
flat sequence structure
Code requiring semaphore...

The Create Semaphore goes outside the While loop (temperature) and the reference is wired through all those structures to the Acquire and Release VIs inside. The Destroy Semaphore is also outside the loop, but after everything else has executed.

When you are done the program will look like this:

While loop (With shift registers to pass data rather than global and local variables)
Case structure (Typedef enum selector)

A state machine!

Create semaphore is in an Initialize state and Destroy Semaphore is in the Shutdown state.

Lynn
Message 35 of 41
(1,780 Views)

Closer, but still not there.  You've just moved the create semaphore out of the subVI.  You still have a new semaphore (and different) semaphore created at each location it is used.

Think of how queues are used.  You Obtain a queue at the beginning of the program.  Pass that reference to the location that does the dequeueing and all the locations the to the enqueueing.  Destroy the queue when the program ends.  You need the same situation for the semaphore.  Create a single semaphore at the beginning of the program.  Pass that location to each section of code where you want to prevent items from simultaneously do some action.  Destroy the reference at the end of the program.



hahaha, i think you are hitting right to my sensitive subject. i want to know how to use a queue because i see it used in more advance users and i always wanted to know how it is done.
Queue is also often used to get rid of local variables by transferring data through wires right?

right now, i have two while loop

so to start the program, i called create semaphore

and how do i get two while to end when the program ends?

there will be two wires (from two while loop) coming to 1 end program sequence?




Message Edited by krispiekream on 07-11-2008 12:38 PM


Also, johnsold, you are right about all your assumptions with the code.
there are too many stacked sequences, i want to reduce them in order to use shift registers to run the wires.



Message Edited by krispiekream on 07-11-2008 12:40 PM
Best regards,
Krispiekream
0 Kudos
Message 36 of 41
(1,777 Views)
Look at the producer/consumer design patterns. They show one way of passing data between two loops using queues and using the destruction of the queue error to stop the second loop.

Lynn
Message 37 of 41
(1,770 Views)

krispiekream wrote:


hahaha, i think you are hitting right to my sensitive subject. i want to know how to use a queue because i see it used in more advance users and i always wanted to know how it is done.
Queue is also often used to get rid of local variables by transferring data through wires right?



Go to File,  New ...., and search for the Producer/Consumer Architecture.  It will bring up a basic template using queues.  Yes, queues are a good way to pass data between parallel structures without using local variables.
 


krispiekream wrote:

right now, i have two while loop

so to start the program, i called create semaphore

and how do i get two while to end when the program ends?

there will be two wires (from two while loop) coming to 1 end program sequence?



That would be it.  Usually, you would use an error wire coming out of each while loop.  Use the Merge error function to join them to a single error wire.  Then pass that wire onto the Destroy queue.  This guarantees that both while loops have ended before the merge errors and destroy queue executes.  Now the examples for queue use the destruction of the queue from one loop to effectively end the other loop.  Once you destroy the queue, the other loop generates an error in the dequeue function because the queue no longer exists.  Then that error causes the other while loop to stop.  It works, but I personally don't like that.  In my opinion error wires should be used to carry data about true errors in the program.  In other words, something that happens because of abnormal operation of the program.  Not to use as a signalling device to shutdown a program which I would consider a normal and expected action in the program.
 
In my preferred architecture, if I want to shutdown, I let the producer loop put a message in the queue that is a shutdown command.  When the consumer queue reads that command, then it executes its case where it feeds a True to the stop terminal of its while loop.  This also gives an opportunity for the consumer loop to finish all of its tasks in the event that multiple items are still sitting in the queue waiting for processing.
Message 38 of 41
(1,768 Views)
wow, look like its going to be a while for me to learn how to use the producer/cosumer design patterns. i'lll give it a try.
thanks everyone

actually, my current structure  is not producer/consumer.
its more like a stacked sequence within a while loop.
producing data, consuming data is in the same loop.



Message Edited by krispiekream on 07-11-2008 12:59 PM
Best regards,
Krispiekream
0 Kudos
Message 39 of 41
(1,766 Views)
It may take a while to learn the new pattern. But look at how much time you have already spent just trying to eliminate sequence structures and local and global variables. Spend a little time learning about the producer/consumer architecture. And queues. Write some small test VIs to see how things work.

Then take what you know about how your system is supposed to work and generate a good software design document. Rewrite the software using one of the new architectures. This may not take much longer than it would take to "fix" your existing program. It will give you a robust, maintainable, modifiable and more easily understood program. Six months from now when you need to change something or fix a bug that someone found, you will thank yourself.

I agree with Ravens Fan. I do not use the destroy queue error to stop the loops. I also send a shutdown message via the queue.

Lynn
Message 40 of 41
(1,761 Views)