I'll try to expand on my situation a little. I'm decoding a PCM stream to pull out some temperature data and display it for a demo of our system.
Here's the vi that I was working with as well as a couple of subvis. Don't laugh, I'm new to Labviews! 🙂 It's still a work in progress, so there is functionality that may be grouped into subvis in the future and certainly a lot of cleanup to do.
The company that made the PCM decoder card I am using sent me a vi to initialize the card and read the PCM frames into an array.
I modified the vi to pull out and decode the header informataion from the PCM frame, search the PCM frame for three different sensors, decode the temperature values, and then display them along with the frame count of the frame in which the sensor data was received.
Here's an attempt at describing the flow of the vi:
The vi that I received from the company was a sequence with 7 frames that went through the steps to initialize the card, set up my PCM information, return a handle to the card, and read one pcm frame into an array.
In the 7th frame of the sequence, I inserted a loop to continually read data from the card. The data is being received at a rate of approximately one frame per second.
As each frame is received, I take the array with the pcm data and pull out the header information and display it (including decoding the time value and displaying that).
I created a FIND MWIS (MWIS is our Micro Wireless Instrumentation Sensor) subvi. I pass the PCM array and a sensor ID to this vi and it will search the array for that sensor and return a true or false indicating whether it found the sensor and also return an 8-byte array containg the sensor data.
I use the true/false output from FIND MWIS as a selector on a case statement. If it's true, I decode and display the sensor data and I display the frame count that the data was received. If it's false, I do nothing.
If you've followed me so far, great!
Here's what I want to add. I want to calculate the sample rate of the sensor (which can be anywhere from once per second to once per hour). Since my frames are once per second, all I need to do is take the frame count of the last sensor reading and subtract that from the frame count of the new sensor reading. That will tell me how many seconds have passed between samples and thus, the sample rate.
I tried inserting a sequence into the TRUE frame of my case statemet, doing what I described in my original post, but wound up with a race condition and a sensor rate that would flash very breifly then change to 0. I guess I could pass each of the Frame counts from my 3 case statements out of the while loop through a shift register, but that seems kind of clunky.
Am I just approaching this whole problem from the wrong angle, or do I need to go pick up a Labviews book and start reading on the proper method of designing a vi? 🙂
PS - If you don't like local variables, don't even look at my MWIS Raw to Temp sub vi... It was my first shot at putting a moderately complex calculation into a vi. Doing it that way seemed to be easier than trying to figure out how to use formula nodes.
I plan on going back to play with it later, but it currently works and I'm not going to mess with it now 🙂