01-26-2013 05:18 AM - edited 01-26-2013 05:22 AM
Hi,
I have a problem with synchronizing two sub VIs.
attached in here a main vi with two subvis.
I want to synchronize between the first subvi and the second subvi so when the first one is run the second will run.
I know that this example is simple and the semaphore can handle this synchronization before getting into the two subvi, But I intend to put the semaphore inside , because in my real program the semaphore releases only when passing through some steps in the first subvi - afterwards the second subvi must start working , then they will continue working together until a stop button is pressed.
So the problem in this example is that the second subvi start running only after the first one is done because only then the error from the semaphore passes through the semaphore on the second vi.
I have tried to create a reference to the error but It seems to me not working or even not possible.
FYI:
- I cannot use Global Variable.
-I don`t understand how Function Global Variable would help.
I will be grateful if you could help me with that.
Thanks,
Hanan
01-26-2013 06:50 AM
Hi Hanan,
- Why do you rename your subVIs before loading them up here?
- Why are we supposed to relink missing VIs in the MainVI?
- Is there a (good) reason not to use (F)GVs?
- Why don't you wire the semaphore to both subVIs?
- Why do you call the subVIs one after the other (due to error cluster wire) when you intend to run them in parallel?
- Why don't you use a notification instead of a semaphore to send information from one VI to the other?
- What do you want to express by "have tried to create a reference to the error"? What kind of reference to which error?
01-26-2013 07:23 AM
1.Sorry , I have sent you the wrong files, here are attached the right ones.
2. (see 1)
3. GV cannot be used due to project restrictions, FGV can be used.
4. because I have explained in my previous message that I don`t want subvi2 to run before we get to a specific step/point (let us say before we get into the loop) in subvi11.
5.I don`t want to run them in parallel right from the begining. (see 4)
6. by "have tried to create a reference to the error" I wanted to say that there is no possibility to get out the error from the semaphore before subvi11 have finished to run (due to its long loop)
Thanks
Hanan
01-26-2013 07:27 AM
Hi Hanan,
4) and 5) are contradictory!
You clearly want to run them in parallel with the additional condition of subVI2 waiting for a notification sent by subVI1!
Think about this and then set up two new subVIs using a simple notification (even an occurance may work)...
01-26-2013 07:53 AM
Another question :
If I have a simple vi containing a "OK button", and 2 subvis.
The first one turn it on or off arbitrary.
afterwards,The second subvi gets the button status and do the opposite on it (if it`s on the 2nd subvi turn it off and the opposite)
How can I do so?
01-26-2013 08:01 AM - edited 01-26-2013 08:01 AM
01-26-2013 08:17 AM
great.-thanks.
now- how should I solve a similar problem if each subvi of the mentioned above has one loop inside (the first subvi have a loop that turns the button on and off, the second one plots in each iteration 0 if it is turned on and 1 if it is turned off)- both subvis work in parallel.
Thanks
Hanan
01-26-2013 09:19 AM
Hi Hanan,
ok, so now you want to run those subVIs in parallel? Before you mentioned "Afterwards..."!
When they run in parallel and only one is writing to your "button" (the other one only reads the button state): use a global variable to store your state. Both subVIs can access that global - but remember: only one data source to avoid race conditions!
01-26-2013 09:42 AM
Thank you ...:womanhappy: