LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to output element from array with time delay and the element is not inside the loop?

 Hi, I am a new user of LabVIEW. I encountered an issue with the output element from an array with a time delay. I have attached a picture of my block diagram for demonstration. 

The method I used was exporting the element from the array using indexing. But it seems that only the last value can be exported out of the loop. So I am wondering if it is possible to make the 'Numeric' varies in the same pattern as the 'element' that is within the loop. Many thanks!

 

 

0 Kudos
Message 1 of 12
(1,566 Views)

I think you forgot to attach the image.

-------------------------------------------------------
Applications Engineer | TME Systems
0 Kudos
Message 2 of 12
(1,557 Views)

Screenshot 2023-07-30 at 00.13.15.png

0 Kudos
Message 3 of 12
(1,553 Views)

Sorry about this. I have reuploaded the picture and please have a check.

0 Kudos
Message 4 of 12
(1,549 Views)

You need to learn the basics of dataflow. There are learning resources listed at the top of the forum.

 

  • Your while loop is a fake FOR loop because you know the number of iterations before the loop starts. Use a FOR loop instead!
  • Wiring [i] to index array is the same as autoindexing.
  • Your code makes no sense. You show one element at a time in order, but then you use an "last element" tunnel to output the last element when the loop stops. If you want to output the entire array, you already have that. Why do you need to generate it again? You could also use an indexing output tunnel, but that seems pointless.
  • Can you explain the purpose of all this? What are you trying to achieve (tell us what you want to do, not how you want to do it!). Where do you need the output later?
  • Doesn't that "-1" belong before the loop? The result is always the same, so why calculate it N times???  (yes, the compiler will fix it under the hood, but it's better to code cleanly!)

To get better help, attach your VI, not a picture!

 

(For your reference, here's equivalent code that does exactly what yours does. Arguably simpler! Right? Of course this is not the solution because you want a different behavior, which is not entire clear.)

 

altenbach_0-1690677926925.png

 

0 Kudos
Message 5 of 12
(1,533 Views)

@altenbach wrote:

 

(For your reference, here's equivalent code that does exactly what yours does. Arguably simpler! Right? Of course this is not the solution because you want a different behavior, which is not entire clear.)

 

altenbach_0-1690677926925.png

 


The Magic 8-Ball says "I think the OP wants the vi to act as if Altenbach's For loop added a Shift Register, initialized with an empty array of DBL, and a build Array (concatinating) wired from SR in and Autoindexed element to SR out and an indicator as DBL[].

 

Pointless code, but it may be practical for leaning basics about Loops, Tunnels, etc...


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 12
(1,491 Views)

Sorry for the unclear question, let me describe it in more detail.

First, my purpose is to output the element in the array continuously with a time delay. I understand that it can be simply achieved by adding the array to for loop and using autoindexing, creating an indicator within the loop and adding the wait function. The element in the array can be indicated one by one. However, I need these numbers for further programming. This can be interpreted to mean that elements in the array are delayed and input into the other function.

Second, from the equivalent code, I can see that the 'Element' indicator can display the element within the array with a 2s time delay. But these numbers can not be extracted from the loop due to the principle of loop operation. So what I am asking can also be interpreted as are there any methods to output the ELEMENT from the array with a time delay without using for or while loop?

I am not sure if I explained it a bit clearer, so if there are still questions feel free to ask. Many thanks.

Kind regards,
Jerry

0 Kudos
Message 7 of 12
(1,460 Views)

@Jerry0117273 wrote:

Sorry for the unclear question, let me describe it in more detail.

First, my purpose is to output the element in the array continuously with a time delay. I understand that it can be simply achieved by adding the array to for loop and using autoindexing, creating an indicator within the loop and adding the wait function. The element in the array can be indicated one by one. However, I need these numbers for further programming. This can be interpreted to mean that elements in the array are delayed and input into the other function.

Second, from the equivalent code, I can see that the 'Element' indicator can display the element within the array with a 2s time delay. But these numbers can not be extracted from the loop due to the principle of loop operation. So what I am asking can also be interpreted as are there any methods to output the ELEMENT from the array with a time delay without using for or while loop?

I am not sure if I explained it a bit clearer, so if there are still questions feel free to ask. Many thanks.

Kind regards,
Jerry


Clearer! 😀

You could use a Notifier to update the Notification Data (as a scalar DBL) to each consumer of the data.  You can also use Queues or Channel Wires for that.  You could even use a User Event.  The choice depends on how many listeners you have and how you use use the data.

 

I know some posters will say that you could use Local, Global or Shared Variables.  They are technically correct but, those are really poorer choices because they break dataflow and are too easy to missuse.


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 12
(1,453 Views)

@JÞB wrote:
Pointless code, but it may be practical for leaning basics about Loops, Tunnels, etc...

Yes, that was my only "point". 😄

0 Kudos
Message 9 of 12
(1,431 Views)

@Jerry0117273 wrote:

First, my purpose is to output the element in the array continuously with a time delay.... This can be interpreted to mean that elements in the array are delayed and input into the other function. ... But these numbers can not be extracted from the loop due to the principle of loop operation. 


I think you are dealing with a mental block here. You are using terms such as "output" and "extracted", etc. that are very vague. What processes the data later as input? We need to complete picture!

 

Maybe that further processing can be done inside the loop right there? Maybe you can branch the array wire and process the same elements elsewhere?

 

Can you be very specific what should happen with these "outputs", whatever that means? Maybe instead of explaining the convoluted mechanics, explain it from the perspective of the user. What does he do and what should happen as a function of his interactions and time?

0 Kudos
Message 10 of 12
(1,427 Views)