I would like to use a boolean selector to choose forward or off for a relay. When I put the boolean selector in the code it only allows me to set the true/false conditions to be constants. I’ve seen the true/false conditions actually be “forward” or “off”. How do I do this? Thanks!
All Booleans in LabVIEW are green in color and can only be True or False. Alternatively, you can use an enum (short for “enumerated type”), which is actually an unsigned 16-bit integer. You’ll find it in the Numerics palette. Once you drop an enum into the diagram or front panel, right click it and select Edit Items (there are quicker ways to edit the names, but not as self-explanatory).
You can then add as many items as you like. In your case you would add a “Forward” and an “Off” item.
What you probably want is a Select block. You’ll find it in the Programming>Comparison palette. It takes a boolean input and uses it to decide which of two other inputs it should output. So you’d use it in combination with the relay enum constants described by airnate to control the relay. You’d wire an “Off” constant to one input, a “Forward” constant to the other input, and then have the boolean input pick which one is actually sent to the relay set vi.
Where do you get the “Off”, “Forward” and “Reverse” constants from?
If you create the enumerated type on the block diagram, it becomes a blue constant. Once you right click on the constant and select Edit Items, you can add any text you want and create your “Off”, “Forward”, and “Reverse”.
The enumerated type can be found in the Numeric sub palette in the Programming palette as shown in the attached picture. My cursor didn’t show up in the picture, but look for the highlighted square surrounding the enum on the palette.
For a more detailed explanation,
- Go look at the LabVIEW help. From the LabVIEW Help menu, select Search the LabVIEW Help…
- Select the Search tab.
- Type enum constant and press enter.
- In the list that shows up, select Enum Constant and the help will appear in the right pane.
One other word of caution, if you make multiple constants (which I presume you’re doing), you should really make a typedef out of one and use the typedef wherever you have an instance of it. Search for Custom Controls in the LabVIEW help for the topic, Creating Custom Controls, Indicators, and Type Definitions. Then scroll down that article to find the section entitled Type Definitions and Strict Type Definitions
A simple way to get the enumerated constants you want is to right-click on the input to the set relay vi and choose “create constant”. You can then unwire it from the relay input and wire it to the boolean selector instead.
Thanks Alan for the reply! The problem is solved! Did it exactly as you suggest!