LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

parallel while loops

Hello,


I'm trying to have two parallel while loops running in my labview vi.  The top while loop works as it should, plotting portions of my incoming data frame.

 

The second (bottom) while loop I am trying to grab the audio data of my frame which is the 3rd and 4th byte of the packet and write this to a .wav file.


I'm really new to LabView and am not sure if I am doing this the correct way, but I also know the second while loop does not seem to be running.  How do I get this to run in parallel with the top loop?

Thanks for any help.

0 Kudos
Message 1 of 15
(3,045 Views)

Hi LKcire,

 


@LKcire wrote:

I'm trying to have two parallel while loops running in my labview vi. 


When you want to have parts of your code to run in parallel then there should be NO data dependency between those parts!

Now look at your code: is there any data dependency (aka wire/dataflow) between both loops?

 


@LKcire wrote:

I also know the second while loop does not seem to be running.  How do I get this to run in parallel with the top loop?


By avoiding data dependencies!

Btw.:

  • Wouldn't it be easier to place that file saving code into the top loop instead of separating it in a second loop?
  • Wouldn't it be easier to save those 2 bytes as just 2 bytes instead of converting them into a rather huge waveform file???
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 15
(3,043 Views)
Spoiler
Ok thank you that does make sense about the code dependencies.

I originally tried to write the two bytes in the first loop after I picked them out of the packet, however, it really slowed down my plot and I was clearly missing data chunks during this.

I can't just save the 2 bytes because the end goal is to save those audio bytes into a .wav file

Thanks for the reply.


0 Kudos
Message 3 of 15
(3,020 Views)

Hi LKcire,

 


@LKcire wrote:
Ok thank you that does make sense about the code dependencies.

I originally tried to write the two bytes in the first loop after I picked them out of the packet, however, it really slowed down my plot and I was clearly missing data chunks during this.

I can't just save the 2 bytes because the end goal is to save those audio bytes into a .wav file

No need to hide your answer in a spoiler tag…

 

I suggested to save those bytes in a "raw binary" file instead of that convoluted wavefile creation because it really is slow the way you implemented it!

So again I suggest:

  • Save those 2 bytes in a binary file. (Depending on amount of data you might even collect them in an array.)
  • After the loop has finished you might convert the collected bytes into the desired waveform - there is no need to do that conversion while acquisition!
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 15
(3,014 Views)

Hi!

 

A structure like a WHILE loop only starts to execute when all inbound wires carry data, and all outbound wires will carry data away when the structure is done.

That means, only when "stop" is clicked and the upper loop ends, the string data will flow out from the upper loop into the lower loop. Only then, the lower loop will start. And it will overwrite the same *.wav file with the same data over and over again, until you click "stop 2"

 

Further more, if during the last execution of the upper loop, there was no initial 0x24 byte, the FALSE case will be executed, which sends out an empty string.

 

And oh, the *.wav file will only contain a single sample.

 

 


I have modified your code:

 

  1. There is no need to multiply each new value by 5E-5, just stay with U16 values. You are displaying this data in waveform graphs. To get the correct scaling there, it is possible to apply a factor (and offset) to their axes.
  2. I've created a queue of type U16 array. When "Save" is clicked, the currend data is put into the queue, an then the upper loop continues. Important: "Save" uses "latch" as mechanical action, that is, it is reset to OFF as soon as LabVIEW reads its value.
  3. The lower loop waits until some data appears in the queue, then asks for a file name, and stores the *.wav file.
    If no data appears for 100ms, a timeout occurs, and the loop executes again.
    Further more, when the upper loop is stopped, the queue is deleted. That will throw an error in the lower loop, causing it to stop, too.

 

This is just a minor change, but I think it does what you want, and it is closest to your idea. (But I can't test the VI)

 

The following picture was created from the block diagramm via Edit > Create snippet from selection. You can actually drag this picture into an empty block diagramm!

 

snippet.png

 

Message 5 of 15
(3,007 Views)

Thank you for doing this... I actually cannot drag it into a blank block diagram... if I try it only shows the link to the image in my block diagram.

 

0 Kudos
Message 6 of 15
(2,993 Views)

@LKcire wrote:

Thank you for doing this... I actually cannot drag it into a blank block diagram... if I try it only shows the link to the image in my block diagram.


 

You need to download the image, then drag the downloaded png file to the block diagram.

 

altenbach_0-1636059161750.png

 

Message 7 of 15
(2,984 Views)

Thanks, it wouldn't let me drag and drop because I have an earlier version of LabView.  Would you be able to just post the .vi so I can work with that?


Thanks again.

0 Kudos
Message 8 of 15
(2,929 Views)

I tried to recreate what you have in the image, but the data is not correct.  It saves 20KB of data when I click "Save" however it is not my audio bytes.  It looks corrupt.

 

 

0 Kudos
Message 9 of 15
(2,916 Views)

It actually does not even ask for the filename so I'm not certain that any "real" data is getting into the queue.

 

 

0 Kudos
Message 10 of 15
(2,915 Views)