LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert to enumeration

I want to convert an integer number to an enumeration (linked to a typdef) and then wire to the selector of a case structure.
It is easier to read the code when the case displays the labels in text instead of numbers.
 
When I use the  "type cast" this is terrible slow on the realtime target. Why? To my opinion that should be just a reinterpretation of the data, nothing to do during runtime.
 
On the FPGA targets the "type cast" is not available somehow. Why?
 
in 8.2 I found somehow a special integer to enumeration converter under the add-ons menue (probably from the supervisory and control). In 8.5 I can not find it anymore and I can not copy it from one VI to another.
 
Hello, hello!! Did I miss something or am I the only one that has nice typedefs of enumerations (for example for statemachines) and have to convert a integer to an enumerator?
0 Kudos
Message 1 of 30
(7,650 Views)
Why convert at all. If you aet up your structure correctly you do not have to convert. If you have an enum input to a subvi all you have to do is wire an integer number to it and it will accomplish the same thing



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 2 of 30
(7,629 Views)

I have to convert an integer number to an enumerator because I use, for example, the index of a loop for the case selector.

Sometimes I also have a computation and the result must be converted to the enumeration.

Sometimes I have stored data in an other format and a part of it must be extracted and converted to an enumeration.

So, why you want me to avoid the conversion? Is it really something that difficult or extraordinary unusual?

Anyway, thank for the reply!

 

 

0 Kudos
Message 3 of 30
(7,623 Views)

@FritzFranz wrote:

"I have to convert an integer number to an enumerator because I use, for example, the index of a loop for the case selector. " This can still be done but the case structure must be in a subvi.

"Sometimes I also have a computation and the result must be converted to the enumeration." Why convert, if you put your code in a subvi you don't have to convert because the enum control will take an integer input and do the correct case based on the integer input. lets say that you set up an enum in a subvi that is setup like this.

  1. Something : 0
  2. Something elsee : 99

If you wire in an integer value of 99 to the subvi the enum will take it in and process the case for 99.

"Sometimes I have stored data in an other format and a part of it must be extracted and converted to an enumeration." What type of format?

"So, why you want me to avoid the conversion? Is it really something that difficult or extraordinary unusual?"  To many conversions of any kind will bring a program to its knees no matter how well it is written or how readable it is. I am just trying to get you to strucure your code so that you will not have to do so many different kinds of converions.

 

 

 

 

 







Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 4 of 30
(7,613 Views)

Thank you for helping me structuring my code!

I do not want to use subvis because they have a significant overhead on real time targets (on the same order as the type cast). 

And also the code would not be more readable if every thin is in subvi's.

 

0 Kudos
Message 5 of 30
(7,598 Views)
I am not sure of what causes overhead in RT. I do not use it. And the subvis were just for clarity. Enums are nice because you just fill them up and then right click on the structure and select add case for every value and you get a nice readable case structure. I love using them myself. I am just saying that maybe there is a way that you can structure your code so that you will not have to do so many conversions.



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 6 of 30
(7,592 Views)
You can convert and integer to an enum with a bundle and unbundle.

The special integer to enumeration converter under the add-ons directory is installed fromthe state diagram editor and is found at:

C:\Program Files\National Instruments\LabVIEW 8.2\vi.lib\addons\statediagram\;DNI_IntToEnum.vi

0 Kudos
Message 7 of 30
(6,879 Views)

Hi Fritz,

I am either not following you or you are onto simething I want to know more about.

What kind of target are you uisng and are you saying you are taking anoticable performance hit from code like this?

Could you post some example code that demonstrates your concern so we can take a closer look, please?

Regarding the ";DNI_IntToEnum.vi" VI that dwisti mentioned.

Yes that comes with the SDE and is used to type cast the iteration count to the target states. Rumour has it that it and any other VI that is named such that it starts with ";D" is Jeff K winking at you.

Ben

Message Edited by Ben on 10-14-2007 11:13 AM

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 30
(6,870 Views)

...yes on a normal desktop pc with LabVIEW RT 7.1 we noticed a significant time overhead used by the type cast operator as in your example. We found this with the execution trace toolkit and we were somehow happy because we could increase the speed of our rt-application but on the other side the code is not that readable anymore...

 

 

0 Kudos
Message 9 of 30
(6,867 Views)
Something I forgot to mention, ;DNI_IntToEnum.vi will work in Labview 8.5.  Also, ;DNI_IntToEnum.vi works in FPGA code too.
0 Kudos
Message 10 of 30
(6,838 Views)