Jump to content

For loop stops unexpectedly


Recommended Posts

Hi,

I'm trying to show a waveform from a file using the waveform graph, but I modified my diagram to be able to show it from the index of the array that I want. In this case I have a buffer size and I display the signal from 0 to buffer size, then from 1 to buffer size +1, and so on.

But I can't understand why the code stops at certain point without reaching the total size of the signal.

You have here my VI and the file with the waveform, maybe you need to change the path on the diagram to be able to open the file. Also I use the waveform as an array internally beacuse I will need to do some work with it later.

If you can help me with that I will be very thankful

Desplazamiento2.vi

archivo.lvm.zip

Link to comment

Your second mistake was in wiring the buffer size to the max queue size of the obtain queue node. The top loop is filling the queue with five elements and waiting for the bottom loop to respond, which it never does because of the way an Event structure works (see below).

post-7534-0-09963700-1353326011.png

Your third mistake was in thinking that the event structure would respond to a change in the Buffer Full indicator. You could use a Value (Signaling) Property node to accomplish this:

post-7534-0-71272800-1353325477.png

Your first mistake was your archetecture; take a look at the Producer-Consumer design pattern. Your VI will run if you change the two things I've mentioned, but it'll take forever to finish. If only I had finished my Algorithms course...

You could do this, and your graph will fill instantly.

post-7534-0-66237900-1353326389.png

Link to comment

Your second mistake was in wiring the buffer size to the max queue size of the obtain queue node. The top loop is filling the queue with five elements and waiting for the bottom loop to respond, which it never does because of the way an Event structure works (see below).

Actually, he needs that to throttle the producer loop to always provide “buffer” number of elements to the consumer loop. Instead, he has a bug in setting the number of iterations of the inner FOR loop (it should be “buffer”-1); removing that, the “buffer full” locals, and adding a Val(signal) property makes the code work.

But this is all academic as...

This is a very over-engineered way of doing what could be done with one simple loop with “Array Subset” in it. I recommend the OP start from scratch after resolving not to use any local variables, queues, or event structures.

— James

Link to comment

Thanks for your fast reply,

I just change the Buffer Full indicator and now the event structure works properly. BUT if I remove the max queue size, the number of elements displayed would be in increment.

drjdpowell, sorry, I don't understand where I'm wrong with the numbers of iterations.

When I run the highlight execution the queue get the correct size of elements, 5 in this case, then the event structure flush the queue, and start again from element 1 to 6, 5 again but this time it doesn't trigger the event structure and the for loop keeps waiting.

the main reason of doing this VI with queues, event structures, etc is because in the future this project can require real-time data from a mic or a NI card, or the possibility to add a scroll signal. So I think this form will be more scalable solution but if you know another way better to do it, please make me know it.

thank you so much

Link to comment

When I run the highlight execution the queue get the correct size of elements, 5 in this case, then the event structure flush the queue, and start again from element 1 to 6, 5 again but this time it doesn't trigger the event structure and the for loop keeps waiting.

That’s because the second time around your are setting N=6, so the FOR loop needs to execute six times, but the queue only holds 5, so it gets stuck waiting.

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.