LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

配列からクラスタに変換 クラスタ要素数 自動変更 Converting an array to a cluster Programmatically set the number of elements in the cluster

Solved!
Go to solution

配列をクラスタに変換する際、

クラスターの要素数をプログラム的に設定する方法はありますか?

 

When converting an array to a cluster

Is there a way to programmatically set the number of elements in the cluster?

0 Kudos
Message 1 of 13
(3,716 Views)

No.

You need to set the number of cluster elements at edit time…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 13
(3,682 Views)

Thank you very much for your quick reply.

I’m grateful for your guidance.

 

 

Best regards,
Y.Yamazaki

0 Kudos
Message 3 of 13
(3,667 Views)
Solution
Accepted by topic author Y.Yamazaki

Hi Y,

 

some background:

LabVIEW is a strictly typed language: you define the datatype of any value (aka wire) at edit time.

 

When converting an array to a cluster you define the cluster datatype at edit time by setting its number of elements. You cannot change this setting at runtime because this would require a recompile due to the changed datatype!

Best regards,
GerdW


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

Dear GerdW

 

Thank you for the detailed explanation.
I learned a lot.

 

Thanks again for your support!

 

 

Best regards,

Y.Ymazaki

0 Kudos
Message 5 of 13
(3,649 Views)

You might try a map.

 

For example with a string and a variant. To get variant values by name.

 

Or for instance with a number and an integer. That gives you integers by index. If the indices are sequential, an array will be even faster (but more work to maintain).

0 Kudos
Message 6 of 13
(3,624 Views)

For what it's worth, I once had a decent use case for something *mostly* similar and came up with a pretty simple working solution.

 

It will NOT adjust the cluster size at execution time, but it *does* make the auto-sizing more automatic at development time.

 

I had a project where I had several different typedef'ed clusters containing different #'s of booleans.  There was some generic processing and evaluation I needed to do which pushed me toward an array-based solution where I converted from cluster to array before calling the processing sub-vi.  Then I'd convert back to cluster with the appropriate # of elements.

 

As development progressed, I would occasionally need to add or remove booleans from some of these typedef'ed clusters.  And then I'd need to edit any of the places where I was converting from array to cluster to update the # of elements again.

 

What I found to work out nicely was to instead use the Type Cast function to convert array to cluster.  I brought over a wire from my original cluster (prior to converting to array and calling the processing function) as the "Type" input.  Because of the way both arrays and clusters are stored with a leading 4 byte size, this Type Cast worked just right.  And whenever I changed one of the cluster typedefs to have more or less booleans, I didn't need to update the processing code.  The cluster size coming out of Type Cast was automatically updated to become correct.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 7 of 13
(3,580 Views)

Somebody made a VIM for all 256 cases at this link

 

https://lavag.org/topic/15221-how-to-change-content-type-of-n-element-cluster/?do=findComment&commen...

 

VIMs attached, but reference original link/author in your program

 

mcduff

Download All
0 Kudos
Message 8 of 13
(3,577 Views)

I usually convert an array of variants to a cluster by flattening the variants to string, concatenating the strings, and then unflatten to the cluster. That works for any number of elements.

0 Kudos
Message 9 of 13
(3,557 Views)

Dear Kevin P

 

Thank you for your reply.

For me, the proposal may be of a high level.😅
However, we would like to thank you for your polite explanation.
We will consider it as a reference.

 

 

Best regards,
Y.Yamazaki

0 Kudos
Message 10 of 13
(3,552 Views)