LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use a typedef in a class?

Solved!
Go to solution

Hello.  I am working on an LVOO application for communicating with an ANT+ device.  I am currently working on the ANT message factory and I have a question about typedefs.  I would like to give the user the option of selecting from a text ring a message to send to the device.  My searches on this website have so far uncovered schemes to programatically populate the "strings[]" property of the text ring, and dynamically load classes.  I also found a way to use variants as look-up tables (i.e. as dictionaries are used in Python).  This is great, and allows me to add new classes to the application simply by creating a new child class and adding its [name, path] pair to a file.  I am using a text ring typedef to store the values of the message names that the user can select.  My question is, can/should I store this typedef in a class?  Some searching revealed that classes are considered to have obviated the need for typedefs in many cases, so I suspect I might be missing something.  I have attached the message factory VI.  Not that it will make much sense without its dependencies, but perhaps it will help show my thought process.

 

I have also been wondering which class to store the typedef in.  I have a message class (called "ANT_Command") as well as a device class and a session class.  My gut says put it in the session class, but the device class might be a better place for it.  I suppose it could also live in the message superclass...

 

Any feedback would be appreciated Smiley Happy

 

Thanks,

-Jamie 

0 Kudos
Message 1 of 6
(4,021 Views)

Why do you need a typedef for a text ring?  It'll only force the datatype but won't force the strings displayed.  Are you sure you don't mean an enum?

0 Kudos
Message 2 of 6
(4,019 Views)

Why would an enum be better?  I thought the only difference was that a text ring allows you to define the values as something other than integers.  I don't really care about the values, I just want to let the user choose a message from a list and then extract the string that was selected so that I can look up the path to the selected message's class.  Maybe there's a more appropriate data structure but I don't see what an enum would buy me.

 

The reason I chose a text ring over an enum is that, according to this you can't programatically change the strings in an enum but according to this you can for a text ring.  The reason I'm using a typedef is because after I update the Strings[] property of the text ring, I want the changes to persist.  I suppose if I put the ring in a class that perhaps I don't need to use a typedef?  I figured I was mixing paradigms, which is why I asked the question.

 

Edit: ah, now I understand what you mean that typedefs won't force strings but just types.  Then forget the typedef part 🙂

 

Thanks,

-Jamie

 

 

0 Kudos
Message 3 of 6
(4,000 Views)
Solution
Accepted by topic author jfalesi

But the values and associated strings are NOT stored int he typedef information, thus having a ring typedef just doesn't make sense.

 

Updating the typedef of a ring to include different strings will NOT update any controls linked to that typedef because the strings are NOT part of the datatype.  With an ENUM, the strings ARE a part of the datatype and thus are propagated with every change to the typedef control.

Message 4 of 6
(3,996 Views)

Got it, thanks.  I already have message names stored in a class so I think I will just create text rings on the fly whenever I need to give the user the option of selecting a message.

 

-Jamie

0 Kudos
Message 5 of 6
(3,983 Views)

Follow-up question:  I am attempting to add an enum to my Device class.  I found this to edit the strings[] property of an enum, as long as the enum is in a VI that is not running.  My idea was to create an accessor VI for the enum attribute and use the accessor as the "reference" VI in the linked example.  However, I after running the enum changer part, the accessor has a broken wire where the enum control connects to the enum attribute in the Device class (see attached).  This brings three questions to mind:

 

1) How do I eliminate the broken wire due to the list of enumerated items being different in a VI that's supposed to set an enum?  This sounds impossible.

 

2) Is there a way to open a reference to a control, i.e. the Device class's control panel?  I assume that if I can find a way to access the enum control on the class' front panel then I can use it instead of the accessor VI.

 

3) Am I making this ridiculously difficult?  My goal is to be able to drop a Message Factory VI on the canvas and then drop the enum control from the Device class on the canvas, and wire up the enum to an input on the factory.  This would ensure that the user can select only the messages that are implemented (i.e. those that were read from a file and set as the enum's strings[] property).

 

Thanks in advance,

-Jamie

0 Kudos
Message 6 of 6
(3,933 Views)