11-14-2015 04:41 PM
Hi
I'm making a labview project with producer/consumer architecture. But I can't use an event structure, because the inputs come from three different VI's, and one is also an input of a CRIO. So I used network published shared variables and a case structure in the producer loop.
In the consumer loop I have different levels of subVI's. I only programmed one input to test the architecture.
But it's not working like it should be.The VI of the input is freezing, sometimes it responds, but most of the time the button is not reacting.
In the subVI's I make use of a database, but I think the problem is in the producer consumer loop.
I hope someone can give me tips.
thanks
11-14-2015 08:51 PM
I don't see a Producer/Consumer design anywhere -- maybe I missed it. Note that you can easily have multiple "Producers" sending data to a (single) Consumer, and can also have multiple Producer/Consumer designs in the same VI.
Bob Schor
11-15-2015 04:28 AM
The producer/consumer design patters is in the main.vi
The inputs for the producer loop come from 3 different VI's, so I cant use an event structure, so I used network published shared variables in the producer loop.
But i'm not sure if this is causing problems.
11-15-2015 04:52 AM
One problem with your setup, your producer is running as fast as it can, adding new elements to the queue.
But your consumer has a wait in it, and is only able to dequeue every 250ms.
In that timeperiode, your producer could have queued multiple elements.
A consumer should be able to dequeue as fast as possible, and a producer only queues elements when it needs to.
Remove your wait in the consumer loop.
11-15-2015 10:17 AM
In addition to not slowing down the Consumer loop (as dkfire points out), you should think about what and how you are "producing". I'm a little worried about your using Network Shared Variables, whose timing is (at best) "uncertain". I understand that you probably generate the data from different (independent) VIs, but each VI can have its own Producer loop that all feed the same Consumer.
The key to doing this is to use named Queues. Give your Queue a name (say, P-C Queue, for Producer-Consumer) and wire it to the first input of Obtain Queue. If you have another VI that wants to have a Producer loop for this Queue, simply create the Queue with the same name. Did you notice the third input to Obtain Queue, "Create if not found (T)"? By default, this will only create the Queue if this is the first time you are calling Obtain Queue with that particular name, just what you want. Now all of your various sub-VIs can Obtain and use exactly the same Named Queue, and can thereby all "feed" the same (single) Consumer. You no longer need to try to pass the data back and forth between sub-VIs using Network Shared Variables -- you can directly input them into the Queue as they are being generated. This will probably "fix" the problem you are having.
Bob Schor
11-15-2015 11:26 AM - edited 11-15-2015 11:27 AM
I deleted the wait function, but this did'nt solve the problem.
I also changed the mechanical actions of the buttons to "latch when released" instead of "latch when pressed". This seems to help a little bit, but it's still not reacting as it should be.
But I will try with different producerer loops and one consumer loop.
The problem is that 2 of the 3 VI's that are providing input are on another target(CRIO),that's why I used NPSV's, as far as I know queues can only be used for VI's on the same network.
Maybe I should think about using "network streams"? Or do I miss something?
thanks!
11-15-2015 12:37 PM
If I understand correctly, you have 3 different places writing to this NPSV. That's the definition of a race condition.
If you're looking to have three different places send data you want the consumer to work with, you'll need something more along the lines of a message handler than you do a producer/consumer. The point of a producer/consumer is to split the two tasks so you can run them in parallel. This allows you to acquire data at a faster rate and send it to another loop to process the data without interfering with your collection.
Here, you're having three sections of code race to write to that NPSV and then pass it off to a secondary loop that doesn't provide the same benefit. You'd be better off having the acquisition loop accepte messages from your three writers in a more lossless way and use that to maintain the data. Network streams are one example of a lossless communication path.
11-15-2015 01:43 PM
I completely agree with natasftw. If you are using multiple targets, network streams are a good way to go to get the data to your Host.
Suppose you have 3 Targets sending to the Host. You'll need 3 Network Streams, Target-to-Host (and maybe more). On the Host, the three receivers can use a Producer/Consumer Design to send the data from the three streams to a single Consumer just by sharing the same Queue -- as each gets data from the Target, it is put on the Queue for the Consumer to "consume".
Bob Schor
11-15-2015 02:24 PM
Ok actually I have 3 VI, 2 of them on a 2 CRIO's and one VI on the host where I also have the main VI, where I want the consumer loop.
So I will try with 2 network streams and put the data on a queu to consume it in a consumer loop.
I'll let you know if it works
thanks
11-16-2015 03:13 AM
gihlutax wrote:I'm making a labview project with producer/consumer architecture. But I can't use an event structure, because the inputs come from three different VI's, and one is also an input of a CRIO. So I used network published shared variables and a case structure in the producer loop.
Maybe i'm misunderstanding, but i don't see the problem here. You can wire User events or Queues so all VI's can access and generate events/queue items.
/Y