LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Type Cast Enum to Ring

I don't understand why this doesn't work.  Which means I don't understand the Type Cast function Fully.

 

I want to convert a Enum to a Ring.  The Ring contains non sequential values.

 

Any Help would be appreciated.

 

Dan

Dan Shangraw, P.E.


   

0 Kudos
Message 1 of 8
(5,642 Views)

hope this helps:

 

 

Harold Timmis
htimmis@fit.edu
Orlando,Fl
*Kudos always welcome:)
0 Kudos
Message 2 of 8
(5,620 Views)

Hi Dan,

 

you have two problems:

1) An enum is always an U16, whereas your ring is defined as I32. That's why you get multiples of 65536 as output.

2) Your ring item values don't match the values of the enum. You're trying to cast a number, NOT a numbered item!

    Example: your DegC enum is represented by the value "0", which will be typecasted from U16 to I32. But your ring doesn't has an item for value "0", so you get an undefined "<0>" output.

 

Solution:

Make an array constant of correct  output values for each item of the enum. Then use IndexArray with index=enumitem to get the corresponding output.

 

Next solution:

To be more error safe you can get the string for the enum item, look for that string in the strings of the ring, then using it's index to get the correspnding (ring) value... Needs some property nodes, but will work too Smiley Wink

Message Edited by GerdW on 09-28-2009 05:26 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 8
(5,615 Views)

Typecasting changes the way that binary data are interpreted. Since both an Enum and a Ring are U16 data, typecasting doesn't care very much.

Item strings will not be affected by a type casting.

 

Sorry I overlooked the case of I32 rings, although this lead to the same conclusion.

Message Edited by pincpanter on 09-28-2009 05:29 PM
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 4 of 8
(5,612 Views)
I was hoping for a more elagant way to do this than creating an array of all the posible choices.

Dan Shangraw, P.E.


   

0 Kudos
Message 5 of 8
(5,594 Views)

ASTDan wrote:
I was hoping for a more elagant way to do this than creating an array of all the posible choices.

Why would that be difficult? Pass the enum into a For loop (which will autoindex) then you can build the array no problem

Cory K
0 Kudos
Message 6 of 8
(5,582 Views)

OK Here is what I have come up with.

 

I get the sting and values array from the ring property node then I index  that based on the value of the enum.

 

This solution assums that the Enum order and Ring order are correct.  This will work for my application

Dan Shangraw, P.E.


   

Message 7 of 8
(5,575 Views)

Wire enum to "format inot string" to get teh string for that enum value.

 

Take the enum string (from above) and wire it a serach 1-d array with the array input coming for the a "strings" property coming from your ring.

 

Itf the value returned by the serach is gtr or eq to zero that is your ring value. If is not then there wa an error matching them up.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 8
(5,548 Views)