LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array to Cluster to Typ-Def Cluster

Solved!
Go to solution

Hi all,

 

I know that I have been asking similar questions as this one before, but I need to ask again, since I am still not satisfy with what I got.  Here is my problem:

 

I am converting a 16 elements array into a cluster.  Then, I feed this cluster into a type-def cluster.  Essentially, I am trying to update my type-def cluster will new values by write another cluster with the same number of elements into it.  Everything is fine, but I am getting a coersion dot.  If you don't know already, I hate coercion dot.  Is there a way to by-pass it?  Thanks!

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 17
(3,880 Views)

I think that you are stuck with the coercion dot, using your current method of doing things.

 

You get a coercion dot because your built cluster is not the identical datatype to your typedef'd cluster, even though it contains the same number and type of elements.  Your typedef'd cluster has named, defined elements...your other cluster, the one you're building from the array, doesn't.  In order to get rid of the coercion dot, I believe you must use instances of your typedef.

 

I'm not sure why you need that interim cluster.  Can't you wire directly from the array to your typedef'd cluster?  Am I misunderstanding your problem?  Can you post a quick little example so we can take a look?

 

d

 

 

Message Edited by DianeS on 03-05-2010 02:11 PM
0 Kudos
Message 2 of 17
(3,876 Views)

Yik

 

Could you post an example of your code?  Why cant you just use the say type def cluster for the update?

 

Dan

Herrlin

Just trying to spread the LabVIEW love.
0 Kudos
Message 3 of 17
(3,870 Views)

If the result is identical in every way except the type def, then you COULD type cast the non-typed as the type def.

 

(Ben now slinks away and covers his head for when Aristos Queue finds out he's telling someone to type cast).

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 17
(3,863 Views)

See attached code.  What do you mean by feeding an array directly to a cluster without first converting the array to a cluster first?  Please elaborate on the type cast a little.  Should I make a dummy control for type casting then?

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 5 of 17
(3,860 Views)

Wire the type def(constatn is OK) to the top middle of the type cast, and the un-type-def'd to the left input. The output should be a type def'd version of your cluster.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 17
(3,854 Views)

Attached another VI that is giving me the coercion problem.

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 7 of 17
(3,853 Views)

Hi Ben,

 

I was afraid that your way is the only way.  Is it worth doing it or should I just stay with the dot?

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 8 of 17
(3,850 Views)

Coercion dots are not evil.

 

Let me repeat that.

 

Coercion dots are not evil.

 

 

Coercion dots are there to tell you that there's a datatype change occurring. Sometimes this is perfectly fine and innocuous. As the programmer you should know when this is the case, and when it is not.  In some cases coercion is bad. Like in the classic example when you're coercing a huge auto-indexed array after a loop ends rather than doing the coercion inside. The coercion should flag you that there may be a potential data loss, especially if going from a larger datatype to a smaller datatype. Sometimes this doesn't matter anyway, so there's no harm done. Is it worth it to put in a conversion function just to get rid of a red dot? Depends. How pedantic are you?

Message 9 of 17
(3,834 Views)
Solution
Accepted by topic author jyang72211

Stick with the dot. If you change you def the code will break to get your attention. If you use the type cast, it may hidethe broken wire and give you a very strange crash in one a sub-VI that gets that data down the wire or in a complete different VI (been there done that. That is why I was covering my head in the earlier post. It took Aristos Queue and his group to figure out I had type cast the wrong type of cluster in one VI that was crashing a dynamic VI when it came time to deallocate a buffer).

 

Coercion dots of the greatest concern when dealling with arrays since they upcasting to a larger type of number (u8 to U32) can't be done in place and requires copying the buffer. Arrays can have large buffer so the duplication is bad. In the case of clusters and type def vs non-typ def'd the dot is only a FYI.

 

Ben

 

PS Plese not identical post times for the same message.

 

PPS LV train teaches that coercion dots are bad. If you take a certification test, forget what we have just said until after you pass, then remember again when you have passed.

Message Edited by Ben on 03-05-2010 02:46 PM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 17
(3,834 Views)