LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data stream exercise

Hey,

 

imagine you have a data-stream incoming from somewhere. You can interpret it as ASCII signs. Let's say you want to work with some signs they are coming in, but not of all them. E.g. let's say I have to find certain signs and write them in a file.

 

But my problem is that the data stream won't stop and is just giving me data. So I need a buffer, where I store the rest of the data, which I haven't touched yet. But how can I do this, when always data is coming in?

 

Do you have any tips for that?

 

-tommy

0 Kudos
Message 1 of 6
(2,199 Views)

Look up Producer/Consumer Design Pattern.  

 

LabVIEW is based on the idea of Data Flow -- a "Structure" (a loop, a VI, a Case Statement) doesn't start until all of its inputs have data, and none of its outputs have data until the Structure finishes (at which point, data are present on all of the outputs).  What this means is that you can have multiple structures (loops, VIs, etc.) running "simultaneously" (or as best at the computer can do so).

 

In Producer/Consumer, you have one loop "Producing" data (say, reading from a data stream incoming from somewhere and saving the data someplace), and another, independent, loop running at its own speed and processing, or "Consuming" any data "saved someplace".  A common method for handling the intermediate data store is a Queue, which you can think of as a "flexible storage location, with one routine, "Enqueue", for adding data at one end and another routine, "Dequeue", for seeing if data are present and giving you the oldest remaining member of the Queue.  Here is an NI White Paper on this topic.

 

Bob Schor

 

 

0 Kudos
Message 2 of 6
(2,190 Views)

Thanks for the tip.

 

Is it somehow possible to create a 'virtual' data flow with LabVIEW for just a simulation and to see if my Producer/Consumer Design Pattern is even working?

 

 

0 Kudos
Message 3 of 6
(2,154 Views)

@tommy_shelby wrote:

Is it somehow possible to create a 'virtual' data flow with LabVIEW for just a simulation and to see if my Producer/Consumer Design Pattern is even working?


I don't know of anything to virtually simulate a serial port other than you making your own simulator (ramp pattern, sine wave, random number, etc) to replace the VISA calls.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 6
(2,147 Views)

Hi tommy,

 

s it somehow possible to create a 'virtual' data flow with LabVIEW for just a simulation and to see if my Producer/Consumer Design Pattern is even working?

Sure!

Spoiler
You can replace that VISARead (or whatever you use to read data from your device) by a loop generating "virtual" aka simulated test data…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 6
(2,145 Views)

@tommy_shelby wrote:

imagine you have a data-stream incoming from somewhere. You can interpret it as ASCII signs. Let's say you want to work with some signs they are coming in, but not of all them. E.g. let's say I have to find certain signs and write them in a file.


Tommy,

     You asked for a "virtual data stream".  Here's one way to do that:

  1. Generate a "set" containing members of the stream.  For simplicity and "generality" (i.e. code that will work with almost all versions of LabVIEW), we'll say the elements are single ASCII characters and the "set" is a string of the characters from which you will choose, e.g. " abcdefghijklmnopqrstuvwxyz0123456789".  If you want to add <CR> or <LF>, you can use string functions to append them to this string.
  2. Calculate the number of characters in the String (see the String Palette for a function to do this).
  3. Do all this before entering your "generation" loop, which does the following:
    1. Calculate a random number from 0 to N-1 (N = string length).  To do this, multiply the random (0, 1) number by N and round down.  Call this number X.
    2. Extract the Xth character from the String.  This is your "Produced Output".
    3. Put a Wait (ms) Delay in the loop to govern the speed at which the Loop runs and produces characters.  Be sure to also have a means of stopping the Loop (maybe a button called "Stop Producer").

Bob Schor

0 Kudos
Message 6 of 6
(2,133 Views)