LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem typecasting to a type def.

I have a program that reads the values from certain channels on a Daytronic System10 device.  I have a cluster of named channels that I convert into an array and pass into a for loop containing the driver to read the value.  I end up with an array of data points and would like to associate each value with the name of the channel it came from.  This way I can utilize the unbundle by name function later, and also I might need to add channels later.  So I take the array of data points and tried typecasting them into a type def. that is linked to the cluster of channel names.  Problem is that this causes the values to become completely erroneous.  I've tried multiple variations involving array to cluster, variants, etc. all to no avail.  Without the typecasting the data values are correct.  Does anyone know why they would change?
 
 
0 Kudos
Message 1 of 4
(2,754 Views)

Type casting is not conversion. It takes the data that you have and simply reads is as the new data type. If the representations match, then the new data will be readable. Otherwise, it won't.

In general, I would recommend avoiding doing this automatically, because the data representation might change or because you could mess it up (what would happen, for instance, if you changed the order of the channels?). Instead, since you have named channels, I would advise using a VI which will do a bundle by name. If you need to reuse the code, delegate that functionality to a specific subVI which you will be able to replace.

If you do want to do this automatically, I would try looking at Kevin's method here, but I don't think it would work with named clusters. You could try reading the data structures white paper, but that would not help you if NI decides to change the data structures.


___________________
Try to take over the world!
0 Kudos
Message 2 of 4
(2,733 Views)
Hi ejoseph,
      The quick-and-dirty solution to your problem (and answer to your question) is to use the "Array To Cluster" function, on the Cluster palette.  If you use it, don't forget to right-click and set the cluster size.  I only mention it because it seems to specifically address the question you posed - though I wouldn't use this technique for the reasons Tst described.
 
Attached is a VI that may work for you; to map data into your cluster with some degree of safety/flexibility.  I haven't looked at other peoples solutions and would recommend you explore the link Tst provided.
 
Cheers.

Message Edited by tbd on 07-15-2006 02:37 PM

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 3 of 4
(2,728 Views)
Type cast seems to work in basic situations, but what Tst said is correct and should be taken into consideration. You might also try using property nodes to set the control values for your cluster controls. Check out this example.

Message Edited by Jarrod S. on 07-17-2006 10:06 AM

Jarrod S.
National Instruments
Download All
0 Kudos
Message 4 of 4
(2,694 Views)