LabVIEW FPGA Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
jakidd

Support Type Cast from Integer to Enum

Status: New

Old Title: FPGA Case Structure Needs To Display Enum Values

 

In LabVIEW the case structure can show enum values, while the FPGA case only shows the numeric value. Would like to see the below example capable in FPGA.

Untitled.png

9 Comments
Dragis
Active Participant

You should be able to wire an enum directly to a case structure in FPGA. Are you getting an error if you use enums on FPGA?

jakidd
Member

Sorry, my wording was wrong. I would like to be able to Type Cast a numeric to a enum, thus the case structure has enum values for the selects.

Dragis
Active Participant

That makes more sense. I have updated the title of the idea to reflect this. 

 

Also, there is a way to cast from an integer to an enum. It isn't pretty, and I won't accept it as a "fix" for this idea, but it is a workaround. You have to use clusters in such a way that forces LabVIEW to choose the enum type instead of widening to the integer type.

 

enum-cast.png

jakidd
Member

FPGA2.png

FPGA1.png

dwisti
Member

Why not use a simple subVI to coerce the data types?  The subVi input control is of the integer data type and is wired the output indicator which is the enum.  This should give you a coercion dot on the enum.

jakidd
Member

I just tried that, using a subVI to coerce, and that is a solution, thanks! I was unaware you could do that.

agileLynx
Member

This is thread is a couple years old, but google led me here, so I'll contribute. You can do the type cast directly on the block diagram without resorting to a subvi.  The trick is to cast from signed numeric to unsigned numeric to enum.

 

Depending on the enum datatype, it may be U8, U16, or U32.

 

To cast from a (nonnegative) integer to an enum with a U16 representation, first call "To Unsigned Word Integer", to cast to U16, and then call "Type Cast" to convert to your desired enum type.

 

Type Cast to Enum

rpursley8
Active Participant

This example by agileLynx is not quite correct.  You much convert a number to an integer of the same bit size as your Enum representation (i.e. if the Enum is a U16, then the number must be cast to a U16 or I16 before passing through the Type Cast to Enum).

Randall Pursley
d.w.b
Member

Use Coerce To Type instead.

 

I suspect type casting an integer to an enum fails on little-endian processors (e.g. Type Cast 1 = Type Cast 0x01000000 = 0x00) but works on big endian processors (e.g. Type Cast 1 = Type Cast 0x00000001 = 0x01).