From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I use the same SubVIs in the different VIs? Those VIs have to run at the same time.

Hello,
If I have two VIs.And both of them has the same SubVIs.
For example
VI1 contains:
SubVI1: Initialize Instrument
......
Data acquisition
......
SubVI2: Close Instrument
 
VI2 contains:
SubVI1
......
Monitoring the Board and VI1
......
SubVI2

When I run those two VIs at the same time, why can't I use SubVI2(which is in the VI1) to close the Instrument?
The function has been run correctly, but it didn't work. The VI1 did closed, but the instrument didn't closed, neither did data acquisition.
In order to close instrument, I have to run SubVI2(which is in the VI2).
What I want to do is that when I run SubVI2(which is in the VI1), then, the instrument closed and data acquisition stopped.
Is there any problem between the thread? Or anything wrong with SubVI's VI property?
 
Thanks a lot!
 
0 Kudos
Message 1 of 10
(2,965 Views)
Hi WangX,

normally there's no problem to run the same vi in two different locations.
You only have to decide on concurrent operations:
- running subvi independently and really "at the same time" -> make them reentrant
- having them in more then one location, not running at the same time: use standard execution options

But:
Why do you want to initialize an instrument in 2 different places?
Why do you want to close an instrument in 2 different places?
Is it not sufficient to init & close the instrument in VI1 and let VI2 just monitor VI1?
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(2,952 Views)
Hi WangX
   Maybe I didn't understand correctly, but it seems to me that you say that VI1 and VI2 run toghether, right?

   If so, i guess the problem is that, running two times SubVI1 you initialize instrument two times (it is not desirable...), and, worst, running SubVi2 you close instrument twice!

   I suggest to put SubVI1 and SubVI2 outside VI1 and VI2, and you run them once, at the start and stop of your measurement.

   Anyway, to run two subVI at the same time you have to see about the "reentrancy" property, but this is a long issue to deal with in this thread, and I guess it is not your problem, since the problem is that you shouldn't run SubVI1 and SubVI2 toghether.

    let me know if I understood good... hope it can help! Have a nice day!

graziano
0 Kudos
Message 3 of 10
(2,951 Views)
Atch! At the same time, GerdW! Smiley Happy

really synchronized!
Message 4 of 10
(2,949 Views)
You should really show us some code.
 
What is done in these subVIs? What are the inputs? What are the outputs?
0 Kudos
Message 5 of 10
(2,925 Views)
Hi, everyoneSmiley Happy
Thanks!
It seems that I didn't solve this problem, but now I maybe understand why it happened.
 
--------------------------------------------------------------------------------
GerdW  said:
Why do you want to initialize an instrument in 2 different places?
Why do you want to close an instrument in 2 different places?
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Graziano  said:
i guess the problem is that, running two times SubVI1 you initialize instrument two times (it is not desirable...), and, worst, running SubVi2 you close instrument twice!

--------------------------------------------------------------------------------
 
That makes me think about the number of doing init & close. My project calls on that there must be a strict requirements about the number of calling those function in one process.
That is to say,when running them, if VI1 and VI2 are in different process but not in the same one, the program is going to run successfully. But now, VI1 and VI2 are threads which in the same process, so my project's strict requirements makes them run failue.I used SPY++ to analysis, and found those two threads are actually in one process.
 
--------------------------------------------------------------------------------
Graziano  said:
I suggest to put SubVI1 and SubVI2 outside VI1 and VI2, and you run them once, at the start and stop of your measurement.

--------------------------------------------------------------------------------
I believe that is a good idea, I can deal the problem in this way. Thank you!
But if anybody has the idea which can deal with the problem between the threads, I will be so glad......
What does that called, Synchronized between threads.....maybe......
 
To altenbach
I am afraid showing the code doesn't work, because all the VI SubVIs and code is base on the japanese system.and all of them must call the functions form DLL which is protected by my company. I am sorry about that......Smiley Sad
 
Thanks a lot!! Everyone. Smiley Happy
0 Kudos
Message 6 of 10
(2,895 Views)
I do not know whether Notification tech or Occurence tech can do the help.
It might be worth to try.Smiley Happy
0 Kudos
Message 7 of 10
(2,883 Views)
Hi WangX,
   I think I see a little better your problem....

   You have to make both VI1 and VI2 capable of initializing and closing instrument, as you say it.... so, in C programming language, I'd have used preprocessor directives, to do conditional compile: when VI1 and VI" are in the same program, you don't run initialize and close (say) in VI2, when tey're alone you do it.  Only, you should translate it into LabVIEW code...

   A raw way can be a global variable, that tells VI2 if the instrument has already been initialized, and if it has already closed...

   ...but, again, we should see the code, to understand better....... without it, my advices are poorer than usually..... Smiley Sad

   have a nice day!

graziano
0 Kudos
Message 8 of 10
(2,883 Views)
...in fact, maybe occurences can fit your needs..... but it depends....

anyway, try!
0 Kudos
Message 9 of 10
(2,881 Views)
Hi, Graziano
 
I have just get it done with two ways.
 
One of them is what you suggest me to do. That is using the global variable, that is a simple and fast way, but a little danger......
 
The other way is that I used LV8.0 to built those two VIs into EXEs. And then when the EXEs run, they are Of course in two different process but not threads.Smiley Happy
 
But I believe there must be some better solutions.
using CIN is a little bit difficult and complex for whole project, so, the next I am going to try the Occurences. Or maybe setting a index for the called functions is the key......
 
Thanks for your help!!!Smiley Wink

Best regards
0 Kudos
Message 10 of 10
(2,869 Views)