LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

confused in producer-consumer structure

I am consufed about the structure for the code I am studying on. Basicly, my code is comprised of 4 processes: acquisition, control, analysis, and monitor. I was advised to use producer consumer structure. I prepared two- still preparing not completed yet- but I am not quite sure which one is more efficient and suitable the code. I attached both of them in zip files: v2 is prepared by pro/con and state machine, in v4 each processes are separated instead of using state machine.

 

Besides, I have some questions to be quite sure that I can implement on the program:

1-Can I transfer daqmx channels task outs via clusters? Is it convenient?

2-Can I transfer refnums via clusters?

3-I have used so many types of and number of elements in a cluster. Can this be problematic?

 

I am all open your suggestions. Thanks in advance.

Egemen
Download All
0 Kudos
Message 1 of 2
(1,932 Views)

Egemon,

 

I have looked only briefly at your VIs, so I may have overlooked some points.

 

Regarding V2:

1. Your Consumer loop has data depedencies on the Producer loop. This means that the Consumer will not start running until the Prodcuer stops. This defeats the whole purpose of the parallel loop architecture.

To transfer the time information between loops, that data needs to be in a queue just as the array from the DAQmx Read is in a queue. Either use multiple queues or create a cluster of the data and feed it through one queue.

2. Your timing formula probably does not work the way you want. 60/(sample rate per minute) gives the time in seconds between samples. The Wait function is called Wait (ms) because its input is in milliseconds. You need to multiply the seconds by 1000 to get milliseconds.

3. You do not need a Wait (ms) function in the consumer loop. The Deqeue function will wait until data is present.

4. The state machine loop will run forever unless there is a file error. Nothing else in there will generate the stop logic. So as soono as one data set is dequeued, the Consumer loop will be locked in the state machine loop. 

5. When I put a state machine in a Consumer loop (which is most of the time), I use the Consumer while loop as the state machine while loop. It may be necessary to move the Dequeue to a Wait for Data state so that several states can execute before the next data set arrives.

6. This is personal preference but I do not like stopping the Consumer loop on the error generated by releasing the queue. And, yes, I know that is the way NI does it in the examples. One reason is that you will most likely lose the last data set and possibly more because there is no way to recover that data if it has not been dequeued before the queue is released.  I prefer to send a "Shutdown" command via the queue and let the Consumer process all the data before releasing the queue.

 

Re: V4:

1. Consumer 4 and 5 both attempt to dequeue the same data. This will not work because once the data is dequeued in one place it is no longer in the queue to be removed elsewhere.

 

I often use multiple loop systems, but my initial impression of this is that it is too complicated.

 

There should be no problems using clusters for Task IDs or refnums.

 

The problems with large clusters are:

1. The space they take on the diagram. Recent versions of LV allow viewing cluster constants as an icon. I am not sure whether that was available on your version.

2. Documentation: Six months from now will you know what the 17th numeric element in that cluster represents? Since you are using Bundle by Name and Unbundle by Name, apparently you have done so. Make the cluster a type def so that when you need to make a change (which will certainly happen on a cluster that big), you only need to change it at the typedef definition and the change will propagate through to all palces where it is used.

3. It is often better if the items in the cluster have a logical relation or reason for being grouped. One option might be to have several smaller clusters (also typedefed) with such groupings and then a large cluster of clusters. The Channels cluster is a good example. Rather than bundling the data from Channels into Main Cluster, just include the Channels cluster as an element of Main. One disadvantage of this method is that the Bundle by Name names get long.

 

Lynn

0 Kudos
Message 2 of 2
(1,892 Views)