Jump to content

Non sequential Typedefs/Ring


Recommended Posts

This has been discussed several times in these forums, but I have never actually found a resolution to the question:

 

In this scenario, I have a C enumerator defining a bunch of errors:

enum{    NoError = 0,    NotInitialized = 1,    MotorOverheated = 2,    MotorDisconnected = 4,    CommutatorError = 8}

 

When this value is sent to LabVIEW, i'd like to parse that easily by wiring it directly to a labview enum that I have created.

 

post-12653-0-93398900-1380898780.png

 

Here's the problem, the C enumeration is not sequential, and LabVIEW enumerators must be.  So there is an offset.  

 

Now if I were to use a Ring to define my motor errors, I run into the problem discussed in many threads regarding how rings do not update even if they are strict typedefs.

 

What i end up having to do is create a conversion VI that basically uses a case structure to convert the error from the C enumerator, to a labview typedef. What a pain.

 

post-12653-0-84073500-1380898932.png

 

So what's the best way to do this?

 

Link to comment

I don't know if this is the "best way" but have you thought about making your enum with Reserved3, Reserved5, Reserved6, Reserved7 placed in between valid values?  This way you can have your enum in a case statement, but also directly change from a U8 of value 4 to MotorDisconnected.

 

In the past my numbers have jumped alot, say from 0, 1, 125, 500, 1000 so using an enum with blanks was not a solution, but for this it may be.  In my case I was lucky and my enum value was something to the effect of "500 Baud", "1000 Baud" so I got it as a string and converted it to 500 and 1000 decimal but that too is not an option here.

 

EDIT:  Is there a valid reason why Enums must be sequential by the way?

Edited by hooovahh
Link to comment

So yes, I have thought of putting Reserved elements, but my example above was too simplistic for some of the elements I would need to parse. They could skip hundreds, like you were saying.

 

I guess my main problem is, Why do enums need to be sequential. In all other languages, they are not.

Edited by shred444
Link to comment
What i end up having to do is create a conversion VI that basically uses a case structure to convert the error from the C enumerator, to a labview typedef. What a pain.

 

attachicon.gifConversionVI.png

 

It should be pointed out that this could be automated by reading the definitions from the C code, making it considerably less painful. There's probably even some code which does this in the LAVA CR or elsewhere on the site.

Link to comment

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.

×
×
  • Create New...

Important Information

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