LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Data out of running SubVI

Hi all,

I have to build some VI representing different instruments connected via GPIB.
These VI should run as main application if no other instrument data are needed. Otherwise, they should interact with the other instrument´s VIs if used within a toplevel application. In this case, I have to use semaphors to avoid GPIB access problems.

It is characteristic for each instrument´s vi that the read-operation is within a while loop to read repeatedly.
No problem so far if running as a "stand alone" VI. But if I have to access the read values within the while loop of the running subVI, no data are passed out. One the one hand it's understandable, because the subVI didn't finish yet and therefore can't pass data out. But on t
he other hand the data sinks are defined as outputs and should output whenever data arrive.

I did some workaround with control references, but I wonder if there's a better solution.

I'd be glad if someone could have a look at the example I created.
Please feel free to ask for details if they're needed.

Thanks,

Andreas
0 Kudos
Message 1 of 12
(3,824 Views)
Hi Andreas,

the better solution in my opinion is to use queues or notifiers.

We usually create named queues so we do not have the need to pass queue references to subVIs. Both VIs will call "Obtain Queue" with the same queue name. Use a strict typedef for the element data type. One of the VIs will enqueue the elements the other will dequeue the elements.
Mostly we even load one of the VIs with Open VI Reference and start it with the RunVi method and "wait until finished" set to FALSE. In your case this would be the instrument VI.

Look into help and examples to learn about queues.

Waldemar
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
Message 2 of 12
(3,824 Views)
try creating an action engine with two actions (read, and write) and us an unitialized shift register to store the information. (LV2 style Global). In your subvi you can call the write actions and place a value into the shift register and then in your top level you can call the read action to retrieve the value. Hope this helps.
BJD1613

Lead Test Tools Development Engineer

Philips Respironics

Certified LV Architect / Instructor
Message 3 of 12
(3,825 Views)
Thank you both,
I'll try to modify the example to examine the use of notifiers, queues or functional globals. Will take a bit time...


Andreas
0 Kudos
Message 4 of 12
(3,825 Views)
OK, I had a look on your advised topics.
And I have to apologize for asking questions about a topic already well discussed in other threads, sorry.

As in this case I only have to visualize data on the frontpanel I think queues are not necessary unless data acquisition and saving is needed.
Notifiers could be a solution because "old" notifiers are ignored when newer data is available. This could be usefull for "quite-synchonous" visualization.

Now to the functional globals:
I read about selecting the Skip Subroutine Call if Busy option for the globals' subVIs.
Where should I select this option?
With every functional global VI to avoid race condition, or just with the functional global VI in time-critical environment?

Andreas
0 Kudos
Message 5 of 12
(3,825 Views)
You can select this option in VI popup menu (over right-mouse click on your VI). Remember, that this option available only if your VI working with subroutine priority.
Normally you have no any race conditions with functional globals, and this option - for functional global, which placed in time critical loop.
0 Kudos
Message 6 of 12
(3,825 Views)
Thank you for anwering my questions.

Now I have at least 5 possibilities to pass out data:

- notifiers
- control references
- functional globals
- VI Server, call by reference, invoke node
(- queues, just not suitable for my application)

Now I have to decide which one to take.
The most important criteria for me are speed of execution and memory usage, not wireing effort or blockdiagramm complexity.

Has anyone information about these aspects of the mentioned possible solutions?

Thanks again, this is a great knowledgebase, isn't it?

Andreas
0 Kudos
Message 7 of 12
(3,825 Views)
Hi Andreas,

I have made a roundtrip measurement with queues.

I did the follwing: I started two VIs both creating two named queues. VI 1 was then getting the time with the Tick Count function and entered then a for loop. In the for loop it sends data over queue 1 and then waited for an answer on queue 2. After the for loop it got the new time. VI 2 runs in a while loop waiting for data on queue 1 and sending data back on queue 2.
I measured a time of appr. 50 microseconds for the for loop on a P II, 400 Mhz system. I used a enum for the data to send over the queues. I have no experience how this timing will change with CPU clock and data size.

I don't know what happens if you fill notifiers faster than you read it. I think you will see an
increase in memory usage which will stabalize after a while when LV is reusing the memory blocks of the overwritten elements. Functional globals will be slower than notifiers because they always will copy the data into/from the shift register. But the amount of the memory will always be the same.
I have no experience with control references because I avoid them and have them never used.

Waldemar
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 8 of 12
(3,825 Views)
Using the LV2 Style Global theory will prevent any kind of race condition because you will only be executing one action at a time. So if you use the write case it will take any information that is there. When you read it will read the information that you wrote. You can also use a queue inside the action engine if you are worried about losing data.
BJD1613

Lead Test Tools Development Engineer

Philips Respironics

Certified LV Architect / Instructor
0 Kudos
Message 9 of 12
(3,585 Views)
Hi Andreas,

my roundtrip measurement was a little bit different. I have attached a zip archive with the VIs.

Waldemar
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 10 of 12
(3,825 Views)