LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how do you create a type definition for an enumeration

Solved!
Go to solution

Sorry for this newbe question, but I am working on cleaning up my act using producer/consumer kinds of event driven state machines.  To do this effectively, it is handy to create a type definition for the enumeration control that defines the potential states of the consumer loop.  I don't understand any of the discussion in the books I am reading.  I have simply placed an enumeration control on the front panel and edited the state names, using them to define the Queue for the consumer loop.  However, when I use other queue functions, and create a constant for the state to put on the queue, that constant gets pulled at the time it is created.  If the list of states is changed, the queue element using the previously defined constant shows a coersion symbol (little red dot), and the constant does not contain the new potential state ... is that what the type definition does is propagate that definition to the constants so they keep up with additions to the enumeration list...?

 

I have been messing with a short example to see how all this works.  If someone could help me with the type definition thing I would appretiate it.

 

Thanks

 

Hummer1

0 Kudos
Message 1 of 11
(5,079 Views)

That is because Type Defintions only define the data structure that is stored in the control.  So when you (auto) update, unless the data structure changes properties of the specific control will not update.  So what you are trying to do, cannot be done in the way you are trying to do it.

 

I've gone down the exact same path...

 

In other words, properties of a control are not part of a Type Defintiion.  The list of items in your enum are part of the strings[] property.

Message Edited by Nickerbocker on 10-20-2009 05:02 PM
0 Kudos
Message 2 of 11
(5,076 Views)

Ok, then how about type definitions for a cluster.  If I want to create a cluster out of some controls I have on the page...say, slide and slide 3 in the example, and then pass their values around in a cluster....how would I create a type definition for the cluster?

 

Thanks for your patience.

 

Hummer1

0 Kudos
Message 3 of 11
(5,071 Views)
Solution
Accepted by Hummer1

Hi Hummer1,

 

Do the following:

 

1.  Under the "file" menu, select "New..."

2.  A dialog box will pop up.  Select "custom control" and click "ok"

3.  A new front panel will pop up, called "control1.ctl".  Put your enumerated constant on this new front panel.  Add all of your states for your state machine, the way you have been doing.

4.  Under the menu on your new custom control, you will see a field labeled "control".  Click on it and choose "type definition" (or "strict type definition").

5.  Save your new custom control as "states.ctl" or "enum.ctl" or whatever name strikes your fancy.

 

Now go back to your main VI.  From the "controls" palette, click "select a control".   Choose the typedef you just created.  Put it on the front panel.  Right click on it and select "find terminal".  Your block diagram will pop up and the control's terminal will be highlighed.  Right click on it and select "change to constant."  You can now wire this constant into your queue.  Do the same thing for any other subVIs that use the same queue, so that they're all referencing the typedef.

 

When you want to make changes to your control, open it the same way you'd open a VI and make the changes.  Then, under the "file" menu, select "Apply changes".  The changes you made will propagate through to all of your VIs.

 

I've attached a little example of a typedef for you.

Diane

 

Message 4 of 11
(5,069 Views)

Does that work the same way for making a structure into a cluster...How do you do that?  Take a bunch of unassociated controls on a front panel, make them into a cluster...then have the ability to add controls to the cluster ...

 

Is it as simple as build cluster array and then array to cluster...or what.?

0 Kudos
Message 5 of 11
(5,062 Views)

Do it the exact same way.  Open a new custom control.  Build your cluster on its front panel.  Choose "type def".  Save it under whatever name makes you happy.

 

To add it to your VI, choose "select a control" from the controls palette.  Whenever you want to make changes to the cluster, open your custom control, make the changes, and select "Apply changes".

 

It will behave just like a normal cluster on your VI's block diagram, so you can use "unbundle by name", "bundle by name", etc.

0 Kudos
Message 6 of 11
(5,058 Views)

Well if you are like me and coding along and realize that the control or constant needs to be a typedef....if it is a constant on your block diagram, right click and change it to a control. Double left click so you go to the front panel. If it's not dashed-line highlighted do so by dragging a box around it. Then Edit (from top menu) and select Customize Control. Make your changes (e.g. type def) and save it. X out and LabVIEW will ask you if you want to replace the non-customized with the control you just made and saved.

 

Hope this helps  

Now Using LabVIEW 2019SP1 and TestStand 2019
0 Kudos
Message 7 of 11
(5,055 Views)

Unless I overlooked it in one of the above messges, I think an important statement was not made when using typedef enum constants.

 

Now that you have the enum constant typedef'd, you need to go through all the places in your code where you have your original constant and replace it with a copy of the new typedef constant.  If you don't, then you will get a coercion dot.  Once you've replaced all the constants, the coercion dots should go away.

 

Now that you have done that, if you need to update a typedef by adding a new item to the enum list, you can open up the typedef and add it.  Now all the constants all over the place will now have that new item in its list.

Message 8 of 11
(5,032 Views)

That's where I was going when I told him:

 

"Do the same thing in any subVIs that use the queue, so that all of the queues reference the typedef"

 

But you are quite right, I did not specifically tell him to replace ALL of those queue references, everywhere, with the new typedef.  Good comment!  Thanks for clarifying!

0 Kudos
Message 9 of 11
(5,024 Views)

...and something that I did see mentioned was making the queue ref a type def as well so that changes to the cluster type def show up in the queue data.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 11
(4,997 Views)