Jump to content
Sign in to follow this  
viSci

string to enum

Recommended Posts

I just noticed that you can use the Scan from String vi to cast a string to an Enum. The vi will automatically adapt to the enum data type when the output is connected to a enum control. If connecting to a vi input that is an enum, you will need to have a local enum indicator to coerse the data type. Please excuse the post if this was obvious to everyone already.

Share this post


Link to post
Share on other sites

QUOTE(LV Punk @ Mar 27 2007, 06:53 AM)

The "Flatten to String" is irrelevant here, because the type information (the names of the enumeration items) is available on the receiving side when you unflatten, through the enumeration constant. In fact, the type information isn't even included in the string. Put a probe on the output from "Flatten to String" and you'll see this; if you're not convinced, convert the enumeration to a U16 and note that you get the same result.

Share this post


Link to post
Share on other sites

QUOTE(ned @ Mar 27 2007, 08:53 AM)

The "Flatten to String" is irrelevant here,

Flatten to string is required to transfer the data via TCP Write and TCP Read. If you're not convinced, wire any enum to TCP Write and note that you will get a broken wire ;) .

I was simply expanding on sachsm's happy observation that enums can be easily manipulated with string functions. Its more efficient and deterministic transmission wise to flatten the enum to a string than to format as a string and send 'broccoli' when 0x0002 can be used...

Share this post


Link to post
Share on other sites

QUOTE(LV Punk @ Mar 27 2007, 01:04 PM)

Flatten to string is required to transfer the data via TCP Write and TCP Read. If you're not convinced, wire any enum to TCP Write and note that you will get a broken wire ;) .

I was simply expanding on sachsm's happy observation that enums can be easily manipulated with string functions. Its more efficient and deterministic transmission wise to flatten the enum to a string than to format as a string and send 'broccoli' when 0x0002 (2 bytes) can be used...

Ah, my misunderstanding of what you were trying to say. I always think of enumerations fundamentally as numbers, not as strings, even though I regularly take advantage of the ease of converting between them, and I thought you were trying to say that there was some difference between flattening an enumeration to a string versus flattening its numerical equivalent.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.