LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

transfer data between multiple vi

I have to run four independent vi’s to manage four serial ports at the same time. In my present setup they run independently so they can get data from the RS-422 port, use look-up table to choose response and answer to the same port in 3-4 msec.

Problems start when I tried to send data to and from them. If I use global variables everything slows down, if I try to put them into one vi they cannot run independently and I lose option to service each port separately from the others.

Any idea how to go around this?

Thanks,

Zoran
0 Kudos
Message 1 of 10
(3,979 Views)
Take a look at using queues to do this. There is an example file using the producer/consumer concept. Have one while loop that is setup to handle communication (reading and writing). Use queues between the four other loops.
0 Kudos
Message 2 of 10
(3,971 Views)

@zoran wrote:
if I try to put them into one vi they cannot run independently and I lose option to service each port separately from the others.

Hi Zoran,

This isn't necessarily true. You could have a single VI with 4 parallel while loops. Each of these parallel loops runs independently of the others. If you use this method, you can then use local variables within this single VI to communicate between the loops. You might also want to consider using queues to transfer information between the loops.

Hope this helps,
Travis H.
LabVIEW R&D
National Instruments
0 Kudos
Message 3 of 10
(3,948 Views)
Travis,

I did try this first. I have one subVI (with a while loop) inside those four while loops, and it is looking at the one serial port all the time. When something comes to it, will respond to this port. The problem is that LV never leaves this subVI, so other loops, where subVI’s are looking at other ports, never got executed.

Solution could be to get rid of subVI’s but then my diagram would be too large. Is there any other way to run more then one subVI at the same time?

Thanks,

Zoran
0 Kudos
Message 4 of 10
(3,934 Views)
Hi Zoran,

How does your subVI work? Are you using 4 different instances of the same subVI and just indicating which port to look at through an input to the subVI? If so, you will need to set the subVI as reentrant. Doing so will actually make a copy in memory of the subVI for each instance it is used on your top-level block diagram. This way, all 4 instances can be executing at the same time. To set your subVI as reentrant, open it, go to File->VI Properties->Execution and check Reentrant Execution.

Hope this helps,
Travis H.
LabVIEW R&D
National Instruments
Message 5 of 10
(3,903 Views)
Travis,

this works! I used reentrant option before but somewhow I overlooked it this time. Now I have a different problem with it. Four vi's are running independently and looking at four serial port. This is just fine. When I want to stop these vi's I use global variable to stop while loop execution inside those four vi's - but this doesn't work in this case. The main vi can't change global variable while those four vi's are running. Any idea how to get around it?

I can stop it by stop button on address bar but this stops everything and I don't want this.

Thanks,

Zoran
0 Kudos
Message 6 of 10
(3,885 Views)

@zoran wrote:
The main vi can't change global variable while those four vi's are running.

This doesn't make sense to me. The idea of a global variable is that you can change it from anywhere. Could you either explain in more detail what is going on, or create a *simple* VI to show it?

Thanks,
Travis H.
LabVIEW R&D
National Instruments
0 Kudos
Message 7 of 10
(3,848 Views)
Here is a simplyfied vi of my problem. It should look at one port all the time and when data comes it will response with other data. So in this case if data file looks like:
11:1234
22:2345
33:3456
and 22 arrives to the port it will response with 2345. Individualy vi RW works fine and it can be stopped by stop button. If I put it inside the while loop it will run forever, pressing stop on main vi will not change global variable stop. I used global variables before and they worked fine so I have no clue why this one doesn't work.

Any idea why?

Thanks,

Zoran
0 Kudos
Message 8 of 10
(3,834 Views)
Attached is a picture that shows parallel vi's and a while loop that stops the parallel vi's. This is an example that ships with labview. The stop button control needs to be inside the while loop.
0 Kudos
Message 9 of 10
(3,821 Views)
If a control is not inside a loop, it will only be read once when the application is first run. (turn on execution highlighting and watch the block diagram, you'll see what I mean)

So in order for your stop button to write to the Global variable, it needs to be in another While loop. Try putting a loop around just the stop button and the variable and place a 'Wait' function in there as well with a 100ms constant on it so it won't consume the entire CPU. You should also put a 'Wait' function in the other loop to keep it from taking over the CPU as well.

Now when you run your applicaiton, the Stop button will be constantly read and will update the global.

Ed

Message Edited by Ed Dickens on 04-08-2005 12:07 PM



Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 10 of 10
(3,819 Views)