LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I build an array not knowing final size at startup?

Hi,
I need to be able to build an array with a certain number of rows but that number is not known at runtime. Instead it can't exceed 5 in a certain time period. So my question is: every 20 seconds I need to send out the 5 row array but if lets say 10 rows of data come in in 20 seconds I am not sure how to handle the data to have it build 2 arrays and send them out one after another at the elapse of the 20 seconds as opposed to just sending an array with 10 rows and losing half the data on the receiving side. Please any help will be appreciated,
Alex
0 Kudos
Message 1 of 6
(3,121 Views)
I think you should send out data only when you get 5 rows, that is, make your app wait untill 5 rows are received, and then pass data out. This way, you allways get the same array size, and avoid data loss.
Hope this helps
0 Kudos
Message 2 of 6
(3,121 Views)
Maybe I am not understanding your answer. I have data coming in constantly so if in 20 seconds I get enough data to populate 10 rows I need to be able to send out 5 rows at a time one after the other, or lets say I get 12 rows then I would need to make 3 sends at 20 seconds, etc... The time is the main factor, I can't wait until I get 5 rows, if lets say I have only 1 row after 20 seconds I still NEED to send it out. I know my question is a little too broad but any help would be appreciated,
Alex
0 Kudos
Message 3 of 6
(3,121 Views)
Perhaps what you need is allways send the maximum amount of arrays, although some can be empty...
0 Kudos
Message 5 of 6
(3,121 Views)
There is an algorithm that I can think of right now but you would have to customize it to what you need:

Build a WHILE loop on the outside. Inside this WHILE loop, put a FOR loop. The FOR loop will take 5 for the number of times it has run or if the number is less than 5, have it send the number out.

The WHILE loop will continue to run if the ARRAY SIZE is >5. After the program has sent the 5 data, it would subtract it from the number read from ARRAY SIZE. I am thinking that you would use a Shift Register here.

I am not quite sure I understand how your timing works but if you want to do it fast, you send more data. Does your application somewhere defines how much data is expected?

I hope that helps. Regards,

Shan Pin Koh
0 Kudos
Message 4 of 6
(3,121 Views)
I understand that you have to send a least a message every 20 seconds (could be empty ?), but can you send more messages if you get more data (e.g. 3 message of 5 rows in 20 sec) ?
If you can, then all you have to do is to trigger the sending of a message each time the array size reaches 5, or if 20s ellapsed since last sent message.
Here is an example, using shift registers. there is a random data generation so that you can see it working (if you set the time between data long enough, then you will see the data sent after 20 sec. Well not exactly 20 sec, but i guess you can figure this out later by yourself...)

I hope this will be of any help
0 Kudos
Message 6 of 6
(3,121 Views)