Producer Consumer Start Trigger

Short Explanation: I'm using a 3rd party device to send a TTL signal to use as my start trigger in my VI. My cDAQ and modules appear to have the ability to send a start trigger independantly but I have been unable to hunt down how to do this in a producer/consumer system.  I do have an idea at the bottom of the long explanation.
Long Explanation:
I'm running a test system that monitors the pressure wave from a hydrogen/oxygen ignition. Components are a cDAQ-9188 with modules 9222 (x3 high speed AI), 9481 (x2 relay), 9402  (x1 I/O Module), 9221 ("Low" Speed AI). 
Based upon recommendations in this forum I've placed my DAQ in a producer/consumer architecture. 
At this point the system mostly works, I still have a few more things to add for all the information I want to collect. However, it records at high speed and the 9221 and the 9222 modules are synchronized. It has successfully collected good data as of this writing.
When the system starts it will monitor, but not record. I need to fill the test structure with gas to a specific concentration before I ignite/record. When I press the record button I send a TTL signal from the 9402 to my high speed camera and I close a relay on a 9481 which engages a spark system. The spark system takes a variable amount of time to charge and fire so I have a timer that leaves the TTL and the relay active for a half second.
My problem, and it's a small one, comes in with the monitoring system and the synchronization. In order to get the system to synchronize properly I had to generate an external pulse into PFI0 to use as a trigger. I attempted to assign the various clocks available as a start trigger but I ended up with unsynchronized data.  
Is there a way to generate a pulse on my 9402 to use as a trigger? It feels silly to me to use an external device when I have something that can generate the signal I need.
In thinking about this post I might have solved my problem, at least in my head. I'm thinking I can move the TTL output VI (which I will eventually change to DAQmx) into the producer loop and move my true/false statements to the consumer loop as a 1D array within my queue to start the record. Probably more to it than that but I can only learn by experimentation right?
Thoughts? Recommendations?
VI attached. 
Solved!
Go to Solution.
Attachments:
HUCTA Controls.vi ‏186 KB

You can't generate a pulse with the 9402 itself. The pulse would actually be generated by the 9188. You should create a Counter Output task to generate a pulse train. Try the attached example as a start point to experiment with the counter.
This Vi is for LabVIEW 2013, if you have an older version let me know and I will try to convert it.
Camilo V.
Applications Engineer
National Instruments
www.ni.com/support
Attachments:
Pulse Train Generator.vi ‏18 KB

Similar Messages

  • Using the same wire for positive edge start trigger and negative edge stop trigger for 6533

    I would produce a start trigger for an external data source to start them.
    Emediatly after this starttrigger this source produces a trigger Signal.
    I would like to use this trigger Signal as an extern trigger which should provide some functions:
    1. on the positive edge of the Signal some pattern should read in with an external clock.
    2. on the negative edge of the trigger signal this process should stop.
    I would do this with CVI

    Hey Schicki,
    I have included two links below that should help you with your application. The first one is setup to perform digital pattern I/O with an external clock in CVI. The second shows how to incorporate start/stop triggers in digital pattern I/O operations. You should be able to combine parts of these two programs to complete your application.
    NI 6534 Double-Buffered Pattern Generation, External Clock -- CVI
    http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3E7FD56A4E034080020E74861&p_node=DZ52321&p_source=External
    Output Digital Data from a Buffer to a Group of Two Digital Ports Upon a Digital Start Trigger
    http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3EA4556A4E034080020E74861&p_node=DZ52321&p_s
    ource=External
    I hope this helps.
    Regards,
    Todd D.
    NI Applications Engineer

  • 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 Subpanels, User events and DAQ

    Hello All,
    I am working on a Producer Consumer application and have beed looking at subpanels for user navigation. The application needs to be capable of responding to user generated events but also manage data received from attached data acquisition and control hardware. This is a 2 part question.
    I need to implement about 15 screens in this application and have started integrating subpanels. I need to be able to navigate from one subpanel vi to another using subvi buttons but dont understand how to build this functionality. Can I build functionlaity so that when I click on a subpanel loaded vi's button it will load the vi referenced by that button and the original dissappears.
    I have a 3 loop producer event template consisting of (1)data acquisition producer, (2) user event producer and (3) consumer loop but theres not much detail, are there any reasonable templates out there? I have seen the data- consumer and user-consumer but no mix of all 3.
    Advice appreciated
    Chris

    I use subpanels to host my display vi's and control them dynamically.  I would have a loop or vi process that manages your subpanel.  You could use user events, queues or notifiers to send messages to this subpanel manager to perform the basic functions such as loading a vi into a subpanel, removing a vi from subpanel (you can remove and stop the vi or keep the vi running in the background or even make it a floating vi.)  A subpanel button can create a local event which in turn could trigger a user event or message to the subpanel manager.  I have attached my subpanel manager to give you some ideas...
    Attachments:
    Subpanel Manager.vi ‏39 KB

  • Synchronizing 2 graphs / producer-consumer loop stuck

    I have a pretty huge VI here, so I created a smaller one, which shows my problem.
    First thing is, the user has to set some parameters, before the VI is running. So, I created a sequence with a while loop. If the user hits the button, the loop ends. That works pretty well.
    In my huge VI I am doing data acquisition. The user hits the button in order to acquire data, checks the data and the data is saved when he hits the acquire button the next time.
    Next thing is, I have two graphs. When the user zooms one graph the scale of the other should be updated automaticaly. Therefor I created a loop with a event structure in it. If the user hits the button in order to acquire the next set of date, the loop ends. So far so good, this works pretty good as well.
    But now - if I zoom the graph before I hit the button in order to end the while loop, everything gets stuck. I don't know how to get rid of that behaviour.
    Please do not suggest anything like getting rid of the producer/consumer loop, since I specifficaly need everything that is in the VI for a certain purpose.
    If you need any additional information, please just ask. I hope my problem is described well enough so far.
    Attachments:
    zoomprob.vi ‏41 KB

    thanks for the response,
    the upper event structure will trigger the data acquisition process, so I don't want to have any time out value unless the user wants to start the acquisition process.
    the lower event structure will take care of the state when the acquisition is done, but the user wants to examine the aquired data. Using a longer time out will not be a disadvantage, but I think it will not solve the problem alone.
    At the moment everything works fine, if you use it how it is ment to be used. If you aquire data and then mess up with the graphs scale, everything is good. But if you try to manipulate the graph and then acquire data, it gets stuck. Apperently, that is not how it's ment to be used - but you know what users often do...
    Unfortunately the highlight execution is of no particular use. If I turn it on and manipulate the graphs scale, the vi gets stuck, but no specific process is shown in the code. Apperently it is waiting for a event, but it isn't triggered. So, beeing able to disable an event structure and enabling it later would solve the problem, for example.... I haven't found any solution for dealing with that, unfortunately...

  • How to change the transmissi​on rate of data flow in producer/ consumer pattern

    Hi All
    I am new to labview and trying to design a application to transfer image data in different rates, that means I can change the transfer rate in the transmission process. In fact,I refer to the the Queue Basic.vi to achieve this function by Changing the delay value of dequeue and enqueue.The program is divided into three parts:
    The first part is the sender in vc used to split and send image data.Data size is 226kb and each time we send a 1kb packet;
    The second is labview rate-change part,use producer/ consumer pattern and queue to transfer data;
    The third one is the receiver in vc,receive data in sequence and synthetic images.
    The entire transfer process is: image data was sent from the sender to producer loop through DLL, then enqueue--dequeue in consumer loop--DLL--receiver.The sleep time in vc sender is equal to the delay value in producer loop and this makes it look like the data generated as in the loop.
    Now this is where my dilemma is:
    When transferring data, if the producer loop and consumer loop delay value are equal(both 20ms), I can see image synthesis at a constant speed and no data lose; if I change the consumer loop delay value and make it greater than the producer delay(one is still 20ms and another is 50ms),that means receive in a lower rate and store data in queue. I can see Elements in Queue
    increase but the image data randomly lost, and the image synthesis speed is not reduced.
    My question is why image data loss and I can't see the image synthesis speed reduced when change the delay value in consumer loop?
    Do anyone know how to solve the problem? Are there any examples I can refer to? Any suggestions are greatly appreciated!
    Attachments:
    image1.JPG ‏56 KB

    thisoldman,
    I don't have '/usr/lib/modules/3.17.3-1-ARCH/build/Documentation/VGA-softcursor.txt' on my file system. Does it contain the info about changing the blinking speed?
    P.S. The other two links I found yet before starting this thread. I only found in them the recommendations about changing "the color and shape of the cursor and turning blinking on/off" (as I mentioned in the original question). Did I miss the info about the blinking speed?
    PPS: I found the vga-softcursor.txt here: https://www.kernel.org/doc/Documentatio … cursor.txt
    But that file doesn't tell about changing the blink rate either.
    Last edited by nbd (2014-11-23 20:55:41)

  • Producer consumer timing

    Back again
    Thought I was getting somewhere now I am at another brick wall.
    Bit of background:
    I have a producer consumer set up. In the producer loop there are 2 DAQmx read VI's reading from a Pressure task and a Temperature task. These are multiple channels, 1 sample, outputtng a 1D wave form. This loop is set to run every 20ms. The two tasks were created using DAQmx Create Channel VI's and DAQmx Start Task VI's. The producer loop feeds a display on the front panel with the sensor values and this hopefully is refreshed at the 50Hz I have asked for. Secondly the loop bundles up the waveforms and puts them in a queue where they are picked up for logging by the consumer loop. In the consumer loop I have a wait 1000ms timer and a Write to Measurment File Express VI to do the logging. This is supposed to log at 1 per second.
    The queue is set to enqueue at opposite end, and the max queue length is set to 1. I.E. I only want to log the value at that specific second, but I want to show the data on the front panel at 50 times a second.
    Now heres my problems:
    1) I replaced the DAQmx Create channel's with a MAX project task wired into my DAQmx Start Task VI. As expected the thing picks up and displays the sensor values as it did before. However there is now a problem logging. Before when I had the DAQmx Create Channel, the logging recorded my values correctly at 1 second intervals. The time stamp in the X column went up by 1 second for each set of results. But now, with the MAX project task (needed because of custom scales and differing min/max values for different sensors), The logging still seems to happen at 1 per second, but the time stamp intervals are the same as the sampling rate set in the task!!! (ie at 50Hz the time stamp goes up 20ms for each result even though the results are being recorded at 1 per second)
    2) The timing just seems out of whack.
    I keep getting errors that the requested data no longer exists, that it was there but then was over written. Increasing the buffer size or sampling rate is supposed to remedy this... but what sampling rate? the rate set in the task? or the loop iteration speed? I dont understand.
    Secondly, despite telling my consumer loop to wait one second between picking up stuff out of the queue to log, it seems to be going round nearly the same pace as the producer loop. To top this off the producer isnt going round at the speed I asked it too either! I put indicators on the loop counters to see this. they are going round at maybe 2Hz.
    I have included my VI's
    What am I doing wrong, its really bugging the crap out of me!
    Attachments:
    EngineMon.zip ‏90 KB

    The reason you would use get time and date in seconds to to ensure that you log every second. If you use the 1 second wait then you do not take into account the exicution time of your loop. If you add more to the loop in the future than you will see that you do not log every second as you thought. If you loop took 500ms to exicute and you have the 1000ms wait then the actual excution time for recoding to file is 1.5 seconds not 1000ms as you desired. The way I did it will always give you one second unless you exicution time for your loop exceeds one second.''
    I did make one change to the vi. I shoulod have put the write in the true false case so that the write only happens when the 1 second has expired.
    Tim
    Johnson Controls
    Holland Michigan
    Attachments:
    VDU3.vi ‏59 KB

  • Producer/Consumer Design Pattern with Classes

    I'm starting a new project which involves acquiring data from various pieces of equipment using a GPIB port.  I thought this would be a good time to start using Classes.  I created a GPIB class which contains member data of:  Address, Open State, Error; with member vis such as Set Address, Get Address, Open, Close...general actions that all GPIB devices need to do.  I then created a child class for a specific instrument (Agilent N1912 Power Meter for this example) which inherits from the GPIB class but also adds member data such as Channel A power and Channel B power and the associated Member Functions to obtain the data from the hardware.  This went fine and I created a Test vi for verfication utilizing a typical Event Structure architecture. 
    However, in other applications (without classes) I  typically use the Producer/Consumer Design Pattern with Event Structure so that the main loop is not delayed by any hardware interaction.  My queue data is a cluster of an "action" enum and a variant to pass data.  Is it OK to use this pattern with classes?  I created a vi and it works fine and attached is a png (of 1 case) of it.
    Are there any problems doing it this way?
    Jason

    JTerosky wrote:
    I'm starting a new project which involves acquiring data from various pieces of equipment using a GPIB port.  I thought this would be a good time to start using Classes.  I created a GPIB class which contains member data of:  Address, Open State, Error; with member vis such as Set Address, Get Address, Open, Close...general actions that all GPIB devices need to do.  I then created a child class for a specific instrument (Agilent N1912 Power Meter for this example) which inherits from the GPIB class but also adds member data such as Channel A power and Channel B power and the associated Member Functions to obtain the data from the hardware.  This went fine and I created a Test vi for verfication utilizing a typical Event Structure architecture. 
    However, in other applications (without classes) I  typically use the Producer/Consumer Design Pattern with Event Structure so that the main loop is not delayed by any hardware interaction.  My queue data is a cluster of an "action" enum and a variant to pass data.  Is it OK to use this pattern with classes?  I created a vi and it works fine and attached is a png (of 1 case) of it.
    Are there any problems doing it this way?
    Including the error cluster as part of the  private data is something I have never seen done and ... well I'll have to think about that one.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Producer consumer vs state machine

    Hi there,
    I have been on and around for quite a while to understand how can I re-design an application, which was originally built using a mix of sequence structure, while loops and event structures. And now I am making a newer version of the same application, for research purposes, while learning the LabVIEW techniques. Earlier I used LabVIEW versions 5 and 6 to make simple programs for fuzzy logic and neural networks. And that's not a good reference.
    Ok, after learning that Producer Consumer (PC) and Standard State Machines (SSM or SM) are two new approaches for a better (scalable, flexible and efficient) coding as suggest by veterans, in one thread where I asked about another issue, I have started digging into this topic and now I am on a point where I have to implement it finally (spent pretty much time in the learning phase).
    I have several questions.
    To start the discussion, I would give a brief description of my application.
    It's a networked application, where the network communication happens using DataSocket (one reason to use LabVIEW as the environment).
    We are talking about the client application, which communicates with other applications on remote computer, via Internet.
    User interface involves a tab control, with several pages-
    On startup, the controls/indicators (now onwards referred as controls only), are initialized, datasocket connection is checked (rather internet is checked, and a connection established with the remote datasocket server) (page 1)
    If connected to the datasocket server, the user selects Login/Registration (page 2)
    Login and/or Registration happen on page 3/4
    Then the user sees a table of remote users to connect to (page 5)
    Upon selection of a remote user, and after clicking on "connect", the user will see a video indicator, with a lot of other controls. (page 6)
    On this page with video indicator and controls, the user has a lot of activities, in which many messages are sent and received to/from the remote machine.
    the user may disconnect and go back to page 5, and log out and go back to page 2 and so on.
    I hope this is clear.
    I have thought about two different ways to do this application. Using PS or by SSM.
    In the attachments, I have given a diagram (with errors, of course, because of unlinked controls), for each of the approach, plus the original application's diagram.
    I hope this is sufficient for anybody to understand my case and give suggestions.
    I am looking for suggestions about which is a better model for my type of case. I have been to discussions like this one and saw that there are many issues regarding dequeue in PC model. So I am curious to know if SSM is a better and latest model or it's more primitive? Which looks better for my application's performance?
    Thanks ahead!
    Vaibhav
    Attachments:
    OldDesign.vi ‏41 KB
    PCDesign.vi ‏42 KB
    SSMDesign.vi ‏46 KB

    Vaibhav wrote:
    @ Harold
    Thanks. Any suggestion how can I start and stop that loop in parallel with other loops? Like, if some event occurs, the loop should start execution, and keep on moving, while other events are being traced and executed.
    In those examples where you had a while loop inside a case structure, that bit of code will only execute one time.  It will immediately read the boolean at the start of the program, if the value was true before the porgram started, then the while loop will run.  Once that while loop stops, the case structure will end.  It will never execute again unless you completely stop and restart your program.  If the boolean is false before the program starts, the false case will execute immediately.  Nothing happens since it is empty and it is done, never to run again (unless you stop and restart your VI)  You should turn the structure around.  Put the case structure in the while loop.  Make sure you put a small wait statement in the loop so that it doesn't run full speed eating up CPU cycles just polling the status of the boolean.
    @ Ravens
    Thanks for the detailed comment.
    One thing I would clarify. The user will not be able to switch between the pages using the tab control. The program will direct appropriate page to the user. I kept the tabs visible just for your idea of the pages. Sorry, I didn't mention that.
    Do you think it's still a bad design?
    If the tabs will be hidden or disabled, you will probably be okay.  I wouldn't call it a bad design.  I wouldn't do it that way.  But as long as you understand the possibility of problems and prevent that.  Especially some time down the road when you modify the program in some other way that could lead to a problem because you forgot about the dependencies of the event structures on the state of the state machine. 
    Yes, I agree about only one event structure to handle all the events. But since the user will not be able to click somewhere else, other than those possible controls, I thought to keep it like this.
    I thought the events are captured only if we are in that case. I think I am wrong, right? Events are captured at any time, even if the case has never executed before, or will never execute.  Ok, The events will be captured, but will not be executed until in that case.
    And that's the reason why I have two separate event structures, in two separate phases of the program.
    Because, prior to page 6, the events will occur sequencially. The user will click somewhere, then some message will be transmitted over DataSocket, then some message may come , then again some user action and so on. But, when the user starts using page 6, there will be parallel process of user controls events and actions, and incoming messages and corresponding actions. For this, in the page 6, I need a different kind of execution. So I separated the two event structures.
    At first I thought to have SSM, and then I thought to PC, just because I can have two separate parallel processes - one for user events, and another for messages (because that way I can take maximum advantage of message tracking). But looking at other complexities, I find SSM more appropriate. Can you please tell me how can I have my message loop and events loop parallel to each other and just one event structure?
    You can have a dequeue function in your state machine loop and have it be a consumer loop.  Use a timeout on the Dequeue.  If there is a timeout, have the statemachine execute normally after that perhaps just passing the enum wire straight into the case structure of the state machine.  If it doesn't timeout meaning you got a message, then look at the message that is dequeued and act on it.  Perhaps it means ignoring the enum coming in from the shift register and changing the enum to something else to feed into the case structure of the state machine.  Attached is an example
    Attachments:
    PCDesign[1]_BD.png ‏6 KB

  • Producer consumer waveform x axis

    I've run into a problem and I'm not sure of the source.  I'm developing a program that reads, displays, and writes thermocouple readings at different rates.  I'm using the producer-consumer architecture and while the sample rate will not be an option, the refresh rate of the chart that displays some of the temperatures will be controlled by the user.  I've been working with the attached example trying to understand where the problem lies with no luck.  The consumer loop is set to wait 2 seconds which I can tell it does but the x-axis still counts every second.  How do I sample from the producer loop and have the correct time and temperature displayed by the chart in the consumer loop?
    Thanks.
    LabVIEW 2012 - Windows 7
    CLAD
    Attachments:
    Plot Starting at Zero Seconds-2.vi ‏31 KB

    Sorry I can't look at your code right now as I am still waiting for my beta copy of LV for Android to arrive -- but seriously the x axis of a graph increments by 1 unless you set the multiplier property to something else.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Producer/Consumer Design Pattern + DAQmx + Event Structure

    Dear community users,
    at the moment I try to implement the Producer/Consumer Design Pattern into my current project. For this purpose I am trying to make a "minimal-example" in which I use the Producer/Consumer Design Pattern for the data acquisition and analysis (display in GraphXY, calculation etc..) process. In the Producer Loop I perform the data readings via DAQmxRead.VI and in the Consumer Loop, in this example only, I display the data in a GraphXY. At the same time I want to control the data acquisition via an Event Structure, for example Start Measurement/Stop Measurement Buttons. To configure the measurement time, for example if the user only wants to measure 150 sec, I use the Time Out Event of the Event Structure. This is a technique which is often used, when data acquisition and Event Structures are used at the same time (Excuse me if this is wrong!). Due to understand the Producer/Consumer Design Pattern I looked up in the Template\Framework of LabVIEW.
    In the attachment you will find my "minimal-example", which -sadly-, not working. What should I do ? 
    Thank you.
    Best regards,
    tugrul öztürk
    Attachments:
    daqEngine_PCP.vi ‏35 KB

    Your VI will never stop due to the Ok Button that stops the producer loop is read OUTSIDE of the loop.  Add an event case for it.
    Move the Start and the Ok Button inside of their respective event cases.  This will allow the latch to reset when they are read.
    Change the Ok Button to a stop button.
    Use a Greater Or Equal instead of Equal for the measurement time comparison.  What if somebody randomly changes it to 0 on you?  Again, you will never stop.
    Is the DAQ only supposed to read for "Measurement Time".  Right now, it constantly reads.  So if you don't use the DAQmx Read, you will get a buffer overflow error.  You need to put the DAQmx Start Task inside of the Start event case and then the Stop DAQmx Task inside of the Timeout event case when the measurement time is exceeded.  You should also perform the read regardless inside of the Timeout event case.
    I HATE telling the consumer loop to stop by destroying the queue.  You can look data that way.  Instead, send something an empty array.  In the consumer, check for an empty array.  If it is empty, stop.  Destroy the queue only AFTER BOTH LOOPS HAVE COMPLETED.
    You should also report your errors in some way.  Simple Error Handler at the minimum.
    Since you are using Continous Samples, don't limit the buffer.  Leave the Samples per Channel unwired on the DAQmx Timing VI.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • 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: optimize data acquistion rate

    I have a producer-consumer type of application in which one loop continuously reads data from the card and queues it and another loops reads/saves data. Additionaly one more loop plots the data. The number of channels and real-time analysis is defined by the user so the time it would take to save, display, and analyze each block (one iteration of Analog/Digital Read) of data may vary for different settings.
    Currently I am setting the "number of samples to get" large enough on the Analog/Digital Read at the start so I don't get queue overflow. Now I would like to adjust it automatically while the program is running so I don't get any queue overflow and at the same time the data is not display in huge chunks at a time. Has anyone done this sort of thing before? Right now the only idea I have is to read the # of elements in the queue continuously and use some mathematical formula to increase or decrease # of samples.
    Solved!
    Go to Solution.

    Abdel2,
    Reading the number of elements in the queue continuously and using a mathematical formula to increase or decrease the number of samples would be a great method. You could also use the Decimate 1D Array Function to display a smaller grouping of your data if your issue is that you don't want to display huge chunks of data at time.
    Ben Sisney
    FlexRIO V&V Engineer
    National Instruments

  • 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

  • Releasing Queue in Producer Consumer model

    I am having a VI which reads data from ethernet,writes to disk,processes and displays. Since lot of processing and displays are there, I am converting it to a Producer- Consumer model so that no data is lost.
    I am using 2 loops. IN the Producer I am doing the UDP read and Write to disk functions.and use the enqueing also.In the Consumer loop I am dequeing it and do all the processing and displays.My idea is to avoid any data loss in UDP reception and file writing.
    My confusion- where to use the release queue?from the Producer or Consumer ? In a third loop ? Should it be in a sequence structure ?
    How to set the loops stop conditions ?
    My requirements for stopping - when I press the stop button the program should stop completely(the Consumer loop should stop only after dequeing and processing all the data in the queue).  If i don't press the stop button the whole program should run continuously (if data does not arrive for some time it should wait without time out-i am using -1 for the time out condition in UDP read.)

    Here is the ultimate Producer-Consumer loop.  It queues a stop command when the stop button is pressed.  This ensures that every element is dequeued and processed before the bottom loop stops.  The last queue data to get processed is the stop command because after you press the stop button, the top loop stops enqueueing more elements. 
    If your data type is other than a string, you can create something to represent stop, like NaN for a numeric. 
    Notice the shift registers.  This is good practice.  Every loop starts with an error out of the previous loop.  If an error occurs, it is passed on to the next loop iteration.  Also, if an error occurs in the consumer loop, the loop stops.  It is good practice to put shift registers on the queue reference also, but not necessary in this case.  If you use a For loop, and the loop iterates 0 times, the output of the queue reference would be a null reference, and the Release Queue would not release the queue.  With While loops, they always iterate at least once, so it isn't necessary.  Its just good practice to make a habit of using shift registers so you don't forget when using For loops. 
    Notice also that the error in to the Release Queue is not wired.  If there were an error, the Release would not take place.  All errors are merged at the end to report exactly where an error occured.  A timeout is included in case an error prevents the stop command from being enqueued or dequeued.
    - tbob
    Inventor of the WORM Global
    Attachments:
    ProducerConsumer.vi ‏53 KB

Maybe you are looking for

  • After Effects are not visible when exporting in Adobe PP CS4

    Hi all of you experts! I have made a simple name/title bar for an interview video, using Adobe After Effects. When i import the composition to Premiere Pro it's visible in the preview window BUT; when I render the video in Premiere Pro the After Effe

  • Extract XML from an XML File

    Hi All, I have an xml file from which data has to be extracted and inserted into table. XML file looks like this.. <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE labels SYSTEM "label.dtd"> <labels FORMAT="Harvest Label for Lot Proje

  • SD Invoice Cancellation without Reversal of FI document

    Hi Gurus, I want to cancel SD Invoice (open in FI) but at the same time do not want to reverse the original FI invoice. Instead, I would like to have offsetting entries document posted. Best Regards, UR

  • PHP echo and setcookie conflict

    I am running this code on a 1and1 Apache server which I believe runs Apache 1.3, the first code example [code1] works fine but as soon as I include an echo before the setcookie function the php script stops creating cookies. Code3, where the echo is

  • HT1339 ipod is in windows format how can it be changed to apple format

    when i look in 'about' on ipod the format is windows.  is there an apple format? how can it be changed back to this?