Producer/Consumer Help

I have created this labview code called '2D Fit.VI' without any DAQ hardware that will create a mutlidimensional fit, is it possible to put this VI in a Producer/Consumer format? If so how would I approach it?  The VI's are attached below. 
Thanks. 
Attachments:
Multidimensional Fit.zip ‏170 KB

ytran wrote:
I have created this labview code called '2D Fit.VI' without any DAQ hardware that will create a mutlidimensional fit, is it possible to put this VI in a Producer/Consumer format? If so how would I approach it?  The VI's are attached below. 
Thanks. 
I assume you have already read the white paper on Producer/Consumer.  I would start by turning the code inside of the event structure into a subVI.  I will be a lot easier to move around then.
Then you just make a queue that can hold new data and read the queue in the consumer loop.  Give it a try first and then post what you have.  We can help you a lot more from there.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines

Similar Messages

  • Still stuck with the same old producer consumer weight problem need help

    Hello All,
    This is the problem I am stuck with right now.
    I have two array lists one producer array list and one consumer array list denoted by a and b
    P1 P2 P3 P4 P5
    5 6 7 8 9
    C1 C2 C3 C4 C5
    2 3 4 5 6
    Now we find all those producer consumer pairs which satisfy the criteria Pi>=Ci
    We have the following sets
    (5,2)(6,2)(7,2),(8,2),(9,2)
    (5,3)(6,3)(7,3),(8,3),(9,3)
    (5,4)(6,4)(7,4),(8,4),(9,4)
    (5,5)(6,5)(7,5),(8,5),(9,5)
    (6,6)(7,6)(8,6),(9,6)
    Let us done each of them with Si
    so we have S1,S2,S3,S4,S5
    we assign a third parameter called weight to each element in Si which has satisfied the condition Pi>=Ci;
    so we we will have
    (5,2,ai),(6,2,bi),(7,2,ci)....etc for S1
    similarly for S2 and so on.
    We need to find in each set Si the the pair which has the smallest weight.
    if we have (5,2,3) and (6,2,4) then 5,2,3 should be chosen.We should make sure that there is only one pair in every set which is finally chosen on the basis of weight.
    Suppose we get a pair (5,2,3) in S1 and (5,2,3) in S2 we should see that (5,2,3) is not used to compare to compare with any other elements in the same set S2,
    Finally we should arrive at the best element pair in each set.They should be non repeating in other sets.
    Given a problem
    P0 P1 P2 P3 P4
    9 5 2 2 8
    6 5 4 5 3
    C0 C1 C2 C3 C4
    we have So as (P0,C0) and (P4,C0)
    assuming that the one with the smaller index has lesser weight PO is selected.In the program I have used random weights.from set S1 we select the pair PO,CO
    S1 =(P0,C1),(P1,C1) and (P4,C1)
    since P0 and P4 are already used in previous set we dont use them for checking in S1 so we have (P1,C1) as best.
    S2=(P0,C2),(P1,C2) and (P4,C2) so we dont use P0,C2 and P1 and C2 because PO and P1 are already used in S1.
    So we choose P4,C2
    in S3 and S4 ae have (P0,C3),(P1,C3),(P4,C3) so we dont choose anything
    and same in S4 also.
    So answer is
    (P0,C0),(P1,C1) and (P4,C2).
    My program is trying to assign weights and I am trying to print the weights along with the sets.It doesnt work fine.I need help to write this program to do this.
    Thanks.
    Regards.
    NP
    What I have tried till now.
    I have one more question could you help me with this.
    I have an array list of this form.
    package mypackage1;
    import java.util.*;
    public class DD
    private  int P;
    private  int C;
    private int weight;
    public void set_p(int P1)
    P=P1;
    public void set_c(int C1)
    C=C1;
    public void set_weight(int W1)
    weight=W1;
    public int get_p()
    return P;
    public int get_c()
    return C;
    public int get_x()
    return weight;
    public static void main(String args[])
    ArrayList a=new ArrayList();
    ArrayList min_weights_int=new ArrayList();
    ArrayList rows=new ArrayList();
    ArrayList temp=new ArrayList();
    Hashtable h=new Hashtable();
    String v;
    int o=0;
    DD[] d=new DD[5];
    for(int i=0;i<4;i++)
    d=new DD();
    for(int i=0;i<4;i++)
    d[i].set_p(((int)(StrictMath.random()*10 + 1)));
    d[i].set_c((int)(StrictMath.random()*10 + 1));
    d[i].set_weight(0);
    System.out.println("Producers");
    for(int i=0;i<4;i++)
    System.out.println(d[i].get_p());
    System.out.println("Consumers");
    for(int i=0;i<4;i++)
    System.out.println(d[i].get_c());
    System.out.println("Weights");
    for(int i=0;i<4;i++)
    System.out.println(d[i].get_x());
    for(int i=0;i<4;i++ )
    int bi =d[i].get_c();
    ArrayList row=new ArrayList();
    for(int j=0;j<4;j++)
    if( d[j].get_p() >=bi)
    d[j].set_weight((int)(StrictMath.random()*10 + 1));
    row.add("(" + bi + "," + d[j].get_p() + "," +d[j].get_x() + ")");
    else
    d[j].set_weight(0);
    row.add("null");
    rows.add(row);
    System.out.println(rows);
    int f=0;
    for(Iterator p=rows.iterator();p.hasNext();)
    temp=(ArrayList)p.next();
    String S="S" +f;
    h.put(S,temp);
    String tt=new String();
    for(int j=0;j<4;j++)
    if(temp.get(j).toString() !="null")
    // System.out.println("In if loop");
    //System.out.println(temp.get(j).toString());
    String l=temp.get(j).toString();
    System.out.println(l);
    //System.out.println("Comma matches" + l.lastIndexOf(","));
    //System.out.println(min_weights);
    f++;
    for(Enumeration e=h.keys();e.hasMoreElements();)
    //System.out.println("I am here");
    int ii=0;
    int smallest=0;
    String key=(String)e.nextElement();
    System.out.println("key=" + key);
    temp=(ArrayList)h.get(key);
    System.out.println("Array List" + temp);
    for( int j=0;j<4;j++)
    String l=(temp.get(j).toString());
    if(l!="null")
    System.out.println("l=" +l);
    [\code]

    In your example you selected the pair with the greatest
    distance from the first set, and the pair with the least
    distance from the second. I don't see how the distance
    function was used.
    Also it's not clear to me that there is always a solution,
    and, if there is, whether consistently choosing the
    furthest or the closest pairs will always work.
    The most obvious approach is to systematically try
    all possibilities until the answer is reached, or there
    are no possibilities left. This means backtracking whenever
    a point is reached where you cannot continue. In this case
    backtrack one step and try another possibility at this
    step. After all possible choices of the previous step,
    backtrack one more step and so on.
    This seems rather involved, and it probably is.
    Interestingly, if you know Prolog, it is ridiculously
    easy because Prolog does all the backtracking for you.
    In Java, you can implement the algorithm in much the same
    way as Prolog implementations do it--keep a list of all the
    choice points and work through them until success or there
    are none left.
    If you do know Prolog, you could generate lots of random
    problems and see if there is always a solution.

  • Help? Looking for better approaches to mutlithreading, parallelism (producer/consumer)

     Hi,
         So II would like to do some parallel processing of data using the multiple cores of my computer, and I'm trying to find a way to do this in labview.  I deally, I would liek to be able to take a given task, put the work into a work queue, have threads from each processor take a task from the work queue and process it in parallel until the work queue is empty, and put the result into a results queue where I could then write the results to a file. So in a text-based languange, the implmentation would be straightforward.. but I'm not sure how to go about this in Labview. 
           I've read about the different designs patterns, and was trying to use a Producer/Consumer approach with queues. What I wanted to do was read a list of files from a directory, stuff the paths into a queue (Work Producer), then have a second loop (Work consumer/Results Producer) dequeue each file, process it, and send the results to a second queue.  Then at the end, a final loop (Results consumer) would read all of the results.
     My question now is..  is there a way to do this more cleanly than what I have on the diagram?  Right now, I have to know in advance how many parallel tasks I want to use, then I have to wire up each task before executing the program.  If I move to a different computer, I need to change the wiring digram.  Is there a way to abstract this to avoid having to make huge changes to the block diagram?  I was considering trying to make the parallel portion fit into a subVI so that I could just copy and paste several sub-vi's to easily add and remove parallel threads..    but its not so simple to have to keep track of all the queue references, and etc..  
    Has anyone already done somoething like this? I feel like what i'm trying now is becomming a big mess
    Thanks

    You can run clones (instaciate from tempaltes) of the crunching code where each get a ref to the queue based on its name. When they see the queue is empty the terminate and close.
    Make sure your queue is full be fore you lauch them.
    There is supposed to be new property that tells you how many CPU you have but I can't find it at the moment.
    Have fun!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Progmatically stop vi with producer/consumer architecture

    I can't seem to get my VI to fully stop, so that I can go on to do some more things in the program.  I am trying to progmatically stop the vi (pictured below), so that I can return to my main gui (not pictured).  The main gui just consists of a login, exit test system, and run test.  Once the user presses run test, the vi pictured below opens.
    I am using a producer/consumer architecture with a state machine.  The problem I run into is that when I press the "Main Menu" button, it should close the pictured vi and return to the main gui.  I tried using the vi server, and when the user presses the Main Menu button, it fires an event and then it goes to the Stop state in the consumer loop, which opens a reference to the vi's (one for the strip chart vi and another for the gage vi), closes the front panel using an invoke node and then closing the reference.  I also tried adding in the abort vi method after the close front panel and it still gave me the same result.
    Here is the catch, it does close the vi's, but it does not stop the while loops (producer and consumer), or it stops only one of the loops.  I thought of putting in a constant in the event structure for when the Main Menu event is fired, but that will stop the producer loop before the consumer loop reveices the info to go to the stop state, so the consumer loop does not end.
    I also tried a "dummy" control that was connected to the comsumer loop Stop terminal (for the while loop), and then progmatically changed the value in the stop case to true and then read that value in the producer loop to, hopefully, stop both loops, but it did not work either.
    I am sure that it is something so stuipidly simple that I cant see it right now
    Kenny
    Kenny
    Attachments:
    test system.gif ‏252 KB

    Hi Kenny,
    I think of two solutions to your problem. First, use the message queue to pass the message "stop" or something from producer to consumer or second (and I think, better), use occurrences. I made a little draft how it could work.
       You have to pass the occurence- Refnum to both VIs, the producer and the consumer, when the producer finishes execution, then use "Set Occurence".
       In the consumer blockdiagram you react on the generated occurrence.
    If you set in the VI- properties "Open Frontpanel when called" and "Close if originally..." the VI Frontpanel should disappear itself when execution is stopped.
    Hope this helps,
    Dave
    Message Edited by daveTW on 08-14-2006 04:53 PM
    Greets, Dave
    Attachments:
    occurrence 1.png ‏1 KB
    occurrence 2.png ‏5 KB

  • First attempt at Producer Consumer Architectu​re: continuous read and dynamicall​y update parameters​.

    Hello,
    I am currently working with two instruments; an Agilent E3646A and an NI 6212 BNC. My objective is to have the 6212 to be continuously taking measurements according to predefined parameters while the E3646A's parameters can be continuously updated. This simple instrument combination is intended to help me learn the necessarry achitecture; continuous measurement, dynamic output control, and more instruments will be added in the future.
    I've previously posted on a similar, but more complicated, setup (http://forums.ni.com/t5/Instrument-Control-GPIB-Se​rial/Split-second-lag-when-controlling-two-instrum​... and was advised to try the Producer Consumer Architecture. I've found relevant literature on the site (http://www.ni.com/white-paper/3023/en/, https://decibel.ni.com/content/docs/DOC-2431), searched the forums and constructed my own VI. While my first attempt at a Producer Consumer Architecture has resolved some of the issues I was having when I first posted on the subject, however, new issues have arisen with regard to reading and stopping the VI.
    I am currently able to run the VI and update the device parameters. Previously, I would get a freeze while the instrument was being updated and could not toggle parameters until it was done. This has been resolved although the read only updates when a parameter has been updated although it is outside of the event structure. Furthermore the Stop button does not work in any context. I've also gotten occasional errors regarding the Deqeue Element but the bulk of the trouble is Error -200279 "Attempted to read samples that are no longer available" at DAQmx Read. I realize that there is a problem in my Producer Loop but haven't been able to figure out how to resolve it.
    This is my first attempt at a Producer Consumer Architecture and already I can see that it is a powerful tool. I read as much as I could and looked at the relevant examples but expected to have some issues in the beginning. Would really appreciate any advice so I can take full advantage of the architecture.
    Hope to hear from you,
    Yusif Nurizade
    Solved!
    Go to Solution.
    Attachments:
    DCe3646A_DAQ6212_Prod_Con_4_13a_2014.vi ‏89 KB

    Jon,
    Thank you for the response and the suggestions.
    I created the Local Variable for the Stop Button and moved the original into its own Event Case. It is now able to stop VI execution although I get Warning -1073676294 which I understand to be the buffer issue. The warning says that this was incurred on VISA Open for the E3646A's Initialize VI which is outside both loops, however, which I don't understand.
    I tried increasing buffer size by decreasing the Number of Samples as per suggestions I found on NI forum threads. I've brought it down as low as 1 but the graph still only updates when an Event occurs and I keep getting the same buffer error. You suggested that the problem could be that they are in the same loop; does this mean that the DAQmx read should be outside both Producer and Consumer Loops or moved into the Consumer Loop? I found a couple of links ( http://forums.ni.com/t5/LabVIEW/Producer-Consumer-​Design-Pattern-DAQmx-Event-Structure/td-p/2744450 ,  http://forums.ni.com/t5/LabVIEW/Producer-Consumer-​Architecture/td-p/494883 -first response) on dealing with an Event Structure that my own VI is based. Alternatively, I found another link ( http://forums.ni.com/t5/LabVIEW/Producer-Consumer-​Design-Pattern-DAQmx-Event-Structure/td-p/2744450 - first response) on a DAQmx Read with an Event Structure that places the graph in the Consumer Loop.
    The core of my purpose in setting up this Producer Consumer Architecture is so that I could read continuously while the instrument parameters are updated dynamically so it's very important that I understand how this works. I am particularly struggling with how the Event Structure is controlling the While Loop's Execution.
    Hope to hear form you,
    Yusif Nurizade
    Attachments:
    DCe3646A_DAQ6212_Prod_Con_4_14a_2014_Edit_I.vi ‏90 KB

  • Can anyone tell me what's wrong with my queue or producer consumer loop?

    A Labview engineer helped me with the overall structure of my program, necessitated by the fast data sample rate and post processing requirements. He recommended the producer/consumer loop and using one of the example files (Cont Acq graph voltage - int clk) to do the actual data acquistion. So I put together the loop and go my two channels of data acq going in the producer loop. However, nothing's getting picked up in the consumer loop and none of my data gets displayed over there.
    Anyone care to take a look at it and let me know what I'm doing wrong?
    Solved!
    Go to Solution.
    Attachments:
    P-C Yanmar Program.vi ‏296 KB

    Your Enque Element should be inside the while loop where you aquire the data.  As it is now, the data has to stop being aquired before you send the last set of aquired data.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Input and output on same device, producer/consumer structure

    Hello interested people,
    I have a question about using the same device for both digital inputs
    and outputs.  I have written a simple program of one while loop
    that continuously polls the device, processes, and requests.  I
    have addressed the device using two DAQmx Asst. and I have attached
    them with their error in/out cluster terminals to provide data flow and
    eliminate the chance of addressing the devices at the same time (which
    produces an error).  Now I want to change this program structure
    to a producer/consumer loop foundation with state machine.  
    In this design, I will have the DI in the producer loop and the DO in
    the consumer loop, under one of the states.  I can't simply
    connect the error in/out ports in this configuration, so my question is
    how to avoid the error caused by addressing the same device
    simultaneously with two different tasks (input and output)?  I
    have attached two VI's, the "One Loop" vi is the original configuration
    (simplified), and the Producer-Consumer vi is a NONSENSICAL program
    that simply represents the desired configuration.  (I don't need
    any comments on the programming of this vi, it is only an example for
    illustration of the problem). 
    I am thinking about bundling the input data and the error cluster, both
    from the PXI 6528 DI, into one cluster, queueing that up, and
    unbundling the de-queued elements for some kind of data flow between
    the producer loop and the "Request" state of the consumer loop. 
    Is this the right approach, or am I barking up the wrong tree?
    Thanks
    Attachments:
    One Loop DO DI.vi ‏102 KB
    Producer-Consumer DI-DO.vi ‏106 KB

    Hello,
    It sounds to me like you really have two modes:
    1. user interface actions determine execution
    2. user interface is locked, and execution is automated.
    I think it would make sense to use the producer consumer for an architecture.  Basically you would do the following:
    1. program the producer to handle the user interface as you normally would.
    2. provide one additional event case in the producer which would be your "automated handling" case.  In that case, you could put a state machine which could run until whatever conditions were met to put your program back in "user interface mode".
    Keep in mind that you can use custom USER EVENTS to programmatically generate events ie. you can trigger the start of your "automated handling" form anywhere in your code at virtually any time.
    I think this would allow you to take advantage of the producer consumer architecture in its intended spirit, while integrating an automated routine.
    I hope this helps!
    Best Regards,
    JLS
    Best,
    JLS
    Sixclear

  • Producer/Consumer Architecture

    Hello All,
                    I am currently working on an application using State Machine Architecture where I have to monitor various parameters (7 temperature values & 3 pressure values), along with this I have to On/Off a Clutch using a digital Output for set time (e.g. On for "X" seconds OFF for "Y" seconds), but as soon as the pressure and temperature values go beyond upper or lower limits or whenever the user presses the Emergency Stop (that means I have to monitor Digital Input as well) so I am moving to different error cases depending on which values go beyond limits or emregency pressed etc..
                But this realisation is not working fine as I have to monitor and control several other things in addition to acquiring data....till now I just have used State Machine Architecture, I have seen Producer/Consumer Template but not quite sure how to realise such kind of application which involves data acquisition along with user interaction and monitoring.
    Could someone please put some light on giving similar kind of example or what else I can try with this problem.
    Regards
    James

    Hello James,
    A Producer/Consumer architecture will certainly do the trick for you. I am sending you an example that has the Data Acquisition section in the producer loop. However, you can also put your User Interface in the Producer loop and have the Data Acquisition in the Consumer loop. The Queues are used for sending data from the Producer to the Consumer(s) loop(s) (you can have multiple comsumer loops).
    You will just have to design specific cases to react to different user inputs.
    By the way, this example is from LabVIEW Basics II training course. If you have never taken LabVIEW Basics I and II, I highly recommend them. You can self-pace the class or take it with an instructor.
    LabVIEW Courses
    Hope this helps!
    Message Edited by Kalin T on 03-23-2007 09:57 AM
    Kalin T.
    National Instruments
    Attachments:
    ImplementedProducerConsumer.zip ‏250 KB

  • Producer Consumer simultaneous operations at different frequencies

    My goal is to do two operations simultaneously.
    The desired end result is:
    1)      Produce an output signal which oscillates at a specified frequency (1 to 10 hz)(using DIO NI-9403). This signal will cause a solenoid to vibrate at different frequencies.
    2)      Monitor voltage on 3 lines in real-time (using analog input NI-9201). This will monitor system response to vibration.
    3)      Produce an output signal which oscillates at a different frequency from (1) – producing 1-second HI values 5 seconds apart. This will cause the system to “pulse”; system response will be monitored.
    4)      Have a front-panel user interface where: the signals in (2) can be monitored; frequency of (1) can be monitored and changed; and the output on (3) can be monitored and changed.
    My efforts so far have been to build a producer-consumer structure. This is my first time using this structure so I may be completely misunderstanding its use. Feel free to correct me if I’m way off target.
    The issue I have is the solenoid in the consumer loop (which handles item (1)) is not operating at the desired frequency. It is too slow. I used a 10ms timer for this loop, but instead it is operating about 1 cycle per second.
    There may be a much better way to approach this, or maybe my program only needs some minor tweaks. Either way, thanks in advance for your help.
    Attachments:
    ProdComsLoop Pulser 2-27-14.vi ‏65 KB

    Hi BradleyDDC,
    It seems from your program that you don't need a producer consumer loop. The only thing you are feeding from one loop to another can be put in one loop, I mean the simulator on button.
    The timer does not determine how fast the loop runs in real time. To get more precise timings, we recommend hardware timed operations as opposed to the software timed ones.
    Instead of using a digital output signal, you can use a counter output task, here is a knowledgebase, which has an example of what you may want.
    Paolo F.
    National Instruments
    Applications Engineer

  • Producer consumer error 200279

    Hello,
    So I’m about to go crazy and hoping someone can help me here. I’m writing a program that controls a motor and using a producer/consumer method to write the data at 10,000 intervals a second. I’ve read through multiple examples and I don’t see what I’m missing. I’m trying to record 18 different readings from a DAQ 9178, 3 readings for voltage module NI 9205, 1 reading for current module Ni 9203, 2 readings for accelerometer module Ni 9234 and 12 readings for temperature module 9213. Every time I run the program I keep getting the error message 200279 and it states that it’s trying to read samples that no longer exist. It advised me to increase the buffer rate. So I did as it suggested in multiple ways and the error messages keeps showing up. I’ve also shut down the computer, exited and restarted Labview several times and none of this worked. I have included the a picture file below.  Where the problem is, is in the producer loop and the error is shown coming out of the DAQ error indicator. One idea I had but I’m unsure how to approach it is to somehow mean the data coming out of the DAQ to reduce what’s getting to the buffer. If anyone knows how to fix this problem please explain it in detail (I mean talk to me like I’m stupid) cause I’ve been stuck on this problem for almost two weeks now. Thank you in advance to anyone who can help.
    SteelTiki  
    Solved!
    Go to Solution.

    The DAQ error isn't related to your choice of architecture, although your implementation of it might be hurting you.  It's almost impossible to follow what's going on in your diagram because you have wires running in many directions (try to keep data flowing from left to right), there are local variables all over the place (almost definitely not needed), and there's a lot of code that's not in the image or is hidden in another frame of the sequence.  Normally one would not have the event structure as the consumer loop (as you've done), and it's generally not a good idea to have multiple event structure in the same VI (with rare exceptions usually involving user events).  It might not solve your problem but it would be worth taking the time to clean up your diagram.  Eliminate sequence structures and local variables as much as possible, move some code into subVIs, and straighten out your wires.
    As for the DAQ error: the DAQ board is reading data into a circular buffer, and you're not reading it fast enough, so samples are being overwritten.  The reason you're not reading it fast enough is because you only read a single sample at a time (the DAQmx Read is configured for 1 sample on multiple channels) but you say you're acquiring 10,000 samples/second.  Since your loop won't run 10,000 times per second, you're not reading all the data, which causes the error.  Try configuring the DAQmx Read for multiple samples.

  • Producer consumer loop for serial comms

    I have an application where I am trying to read and write to a serial port using a producer consumer loop.  My producer consumer loop seems to work fine until I put the serial comm VIs in the consumer loop.  Prior to that my event structure in the producer loop seems to work fine and all the controls on the front panel send commands into the queue and the expected reaction happens in the consumer loop.  When I put serial comm VIs into the consumer loop the application will read the serial port but none of the other controls on the front panel ever get any reaction from the consumer loop.  I am not sure if I am using the producer consumer loops correctly when using comms at the same time.  Any help would be appreciated!!
    I have attached the VI for your inspection.
    Attachments:
    pinger comms.vi ‏65 KB

    You could probably continue with your original architecture as well.  Just put the check for bytes at port in the Read case of the consumer loop.  As you said, it takes 1-2 seconds for the device to send data.  So the original architecture didn't work because you were queueing up 20 reads per second in the timeout case, but the consumer loop was taking up to a second for a single byte to come in.
    If you check for bytes in the consumer loop, if none are there, the Read case will end quickly and won't wait for that byte to come in.
    You should also probably increase the timeout of the event structure to 100-200 mseconds or even more.  The event structure would still respond instantaneously to user interface events.  And you would only be generating the timeout case a few times per second.  Which means when a byte comes in, it would probably be sitting there only 100 mseconds or so before you read it.  Unless you go click happy and generate lots of other  events not allowing the timeout case to run.

  • Producer/consumer question

    Hi everyone
    I am stucked with a problem using the producer/consumer VI.
    My VI continuously acquires data from the DAQ using a producer/consumer VI.
    In the maintime, I would like to introduce and save some notes that can help me to identify the acquired data in a separate file without stopping the acquisition.... but  I don't know how to do it or modify the producer/consumer scheme.
    Any suggestion?
    Thanks for the reply
    matomato
    Solved!
    Go to Solution.
    Attachments:
    ProducerConsumerData_time_Y_Sim_Start_13.vi ‏70 KB

    matomato wrote:
    Hi Smercurio_fc
    The purpose of the code with the Write to Spreadsheet File on the left is to save some comments without stopping the acquisition.
    The problem with it is that it only runs once at the beginning of the program.
    ...The new one should be be to introduce and save his details without stopping the acquisition.
    Save where? In this secondary file, or in the measurement file as a comment?
    Technically, I don't know how to modify the producer/consumer scheme to introduce the new loop with the case structure maintaining the data acquisition as the main loop.
    Hope to have answered your question, if not let me know.
    I'm not sure I understand what you are asking. Are you saying you don't know how to add another loop to the code? Or are you saying you don't know how to use the event structure?

  • Producer Consumer Issues

    Hi all,
    I'm creating my first producer-consumer program, and I've run into a few problems.  I have two producer loops (one is a pressure controller and the other is power reading loop).  I've used queues to pass data into the consumer loop which records the data (at a much slower rate).  The problem is that the producer loop (the pressure controller) contains the stop signal for the program.  So I've had problems shutting down all 3 loops.
    My questions are......Do I have to shut down the consumer loop first, then the producers?  What is the best way to pass stop signals (local variables, booleans in a queue, etc)?   Also when I try to use the producer loop to stop the other loops I get the attached error.  Anyone have any recommendations for making an efficient stopping procedure?  The wait inside the consumer loop is quite long (5 min), so I'd like the minimize the stopping time, if possible.
    I've attached two versions that I've been working with.  They use version 8.5.
    Thanks in advance - Dan
    Attachments:
    Final Controller No Inputs.vi ‏274 KB
    Final Controller Other.vi ‏274 KB
    error.JPG ‏19 KB

    I like to stop the program in the producer loop, and wire the error output of the dequeue element function to the stop of the consumer loop (when the producer loop stops the dequeue element function will generate an error, the error out will cary this to the stop and the loop will stop).  Hope this helps!
    CLA, CLED, CTD,CPI, LabVIEW Champion
    Platinum Alliance Partner
    Senior Engineer
    Using LV 2013, 2012
    Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.

  • Producer Consumer with a state machine within the consumer

        Hi All,
    I have been trying to develop a data acquisition system with the producer consumer architecture.  To the left of the two main loops I initialize the serial port and any constants and variables im using.  I also have an obtain queue VI needed for enqueue and dequeue. Then in the producer loop i have a state machine.  The first state is where I wait for a button press on the front panel to write a GO signal on the serial line which will tell the device connected to the serial port to begin sampling data.  After this button press I go into the next state which is called my read state.
    In the read state I use a property node to read all of the available bytes at the serial port and then enqueue this collected data into a queue.  The state machine then is directed to continously go to the read state again and collect more data.
    Now this is where my dilemma is......  The consumer loop has the dequeue VI inside it and after this VI i have a state machine (while loop and case structure) which contains the following states
    1.  Build Array - build an array from the dequeue element and if there is any left over data from the parsing states it will build an array with the left over data and the dequeued data
    2.  Determine packet type - this state looks for the packet type byte(not necessarily the first byte in the message) and also check the next byte (packet length) to ensure that I am at the begininng of this chunk of data.  This state may be a little slow because there can be three different packet types and based on this byte and the packet length it may have to search the array several time to find the valid starting point.  This state also determine the next state to go to based on the packet type.
    3 packet type 1 parsing - parse data and store the remaining data it leftOver array.  Go to exit state.
    4 packet type 2 parsing - "" ""
    5 packet type 3 parsing - "" ""
    6 exit - leave this state machine and fall back to the consumer while loop.
    After it exit I think it should fall back to the consumer while loop and dequeue more data and enter the state machine again to build a new array with the dequeued data and leftover data.  It seems to work when I trace the execution using the Highlight execution feature, however when I run this all at full speed, it seems to go into the consumers 1st and 2nd states back and forth and not completely go through the state machine.
    I tried adding in a delay in the producer loop to give the consumer loop time, but I didnt notice any difference.  Is it possible that my dequeue element is retreiving more data while im still in the state machine, causing the execution to leave the state machine before it finished all states?
    Is there a better approach to take to solve this problem. Basically I need to read data at a 1,000,000 baudrate and parse it as quickly as possible so that I can break it up into 3 different packet types, write the data to a file, and graph the actual data (header info removed) in realtime.  I need to also ensure that I am not losing any of the collected data.  Data loss cannnot occur.

    A couple of things more to go along with Ben's pointers:
    You convert your data from a string, to a U8 array, to a Hex string array in the producer loop, then convert back to a integer to determine what to do with it.  In the process, you create two or three copies of your data, slowing yourself down quite a bit.  The code would be quite a bit more efficient if you left the data as a U8 array.  You can change the format of the controls and indicators to show hex values instead of integer by right clicking on them and selecting Format and Precision...
    Your search code is fairly inefficient.  I made a whack at making it a bit better.  See attachment below.
    If you continue to run into race conditions, you can debug them using a calls to the Windows debug write sprinkled liberally about your code.  Check out the post here for more information.
    Don't let your lack of format LabVIEW training stop you.  The biggest thing to get is the data flow paradigm (aka data is wires, not registers).  Once you get past that and learn how to pass data around using shift registers, queues, events, etc, you are most of the way to mastering LabVIEW.  The rest is just learning the plethora of functionality LabVIEW gives you (yes, I have reimplemented LabVIEW native code more than once in the process of learning).
    Let us know if you need more help.
    This account is no longer active. Contact ShadesOfGray for current posts and information.
    Attachments:
    serialUtil_V3_DFG.zip ‏137 KB

  • Producer/consumer architecture over network variables with Real-Time target.

    Hi all,
    I am maintaining a producer/consumer data acquisition program to be deployed on a real-time target. The main code is deployed to and run on the real-time target during experiments, but was having trouble because the program was originally designed to write all experimental data to disk on the real time during acquisition, which puts the whole experiment at the mercy of the hard drive. I am now trying to rework the code so that the host takes care of logging, so that my time-critical loops don't have to wait.
    I am currently using LabVIEW 8.5
    I have two questions:
    First, how can I programmatically call the data-logging subvi on the host so that it runs in parallel with the main vi which runs the experiment and collects data on the real-time? I have attached the test code that I have been working with to figure this out, but it does not run the logging vi continuously in the background. I am aware that there is better functionality for this in newer versions of LabVIEW, but I would prefer not to upgrade unless there is no other option. I would like to be able to run my data-generating vi and have it start the data logging remotely.
    Second, is there a way in the host VI to read values off the network variable using an event structure rather than polling it for updates?
    Any help would be sincerely appreciated!
    Attachments:
    testRemoteLogging.zip ‏124 KB

    VI server
    Mark the target VI as served on the machine on which it will execute and use VI server Call by reference to invoke the served VI.
    This used to be taught as THE way to communicate syncronously with an RT app.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

Maybe you are looking for

  • Itunes on Windows 8 not syncing with iphone5

    I have itunes installed on Windows 8 and need to sync Outlook with my iPhone5. When I connect to iTunes it lets me select sync with Outlook but doesn't show me any of my contacts or calendars to select which ones to sync.  How can I fix this?

  • Invoice Verification Form

    Hi, Is there any smart form for Invoice verification output. I have searched a lot but I did not find any smart form for invoice verification. Please advice if any one of you know any smart form for invoice verification. Thanks

  • URL represents a folder or a file?

    hi guys if i have a URL how can i determine whether it represents a folder or a file? thanks in advance

  • FDF problem: dictionary expected

    Hi, i have a PDF file with a form to be filled, and a FDF with the form data ( to get them download this .zip file and extract it: http://vm0869.cs01.seeweb.it/master/sites/default/files/pratica_561.zip ) When i double-click on the FDF, it should aut

  • I can't remove ZfD man Agent 4.0

    The only thing I get is a flash windows installer. I tried first removing the regkey HKLM/Novell/Zenworks reinstalling Windows Installer 3.1 v2 (latest fix) tried reinstalling the agent with the setup.exe before removing "setup.exe /s /f2"C:\ZfDAgent