Message sending is the means of controlling your component. The calling component will send a message to the called component telling it what to do.
There are various methods you could employ to send messages to your components , but we use enumerated types that are simple and self-documenting . In fact, the biggest bonus when using enumerated types is that you can drop your component on your block diagram, right-click on the input, and pop up a complete reference of the components' actions and attributes.
The LabVIEW online guide gives a comprehensive overview, however, for those too lazy here's a summary:
An enumerated type control can be thought of as a drop-down box
Enter additional items by using the labeling tool and pressing Shift-Enter
The enumerated type data type is U8, U16, U32, selectable from the Representation palette. The terms U8, U16, and U32 refer to the number of elements the enumerated type can hold (U8 = 256, U16 = 65,536 and U32 = lots and lots)
Wiring to a Case Structure makes the case display a string rather than a number
Arithmetic operations (except Increment and Decrement) treat enumerated type as their number representation
Increment and Decrement rotate at start and end
A number is converted to the closest enumeration; out-of-range numbers are set to the last enumeration
Well seven actually.
Converts the selected enumeration to its text representation (in the example shown in Figure 5.1 the output string would read "Error State").
This is useful for storing states in a file or database.
Converts the input string to its representative output. In the example shown in Figure 5.2 the output enumeration would be set to "Test 1", if there is a corresponding list item, or "Error State" if not.
This is useful for retrieving states from a file or database.
The example in Figure 5.3 converts the number to its enumerated type without making ugly coercion dots (Output String 2 would be set to "Test 2" in this case).
Care must be taken to ensure that the numeric is matched to the enumerations representation. If not, it may sit on "Error State". |
Figure 5.4 shows an enumerated type being cast to or from a string. This is very useful for sending commands through ports. For example, a real-time system could use it as a method of sending commands to and from a PC client to the real-time server using the Transmission Control Protocol/Internet Protocol (TCP/IP) functions.
Gives similar multiple selection functionality to a Select-Case statement in Pascal and Basic, or a Switch in C and Java. Using an enumerated type as in Figure 5.5 improves a system's readability and helps with self-documentation.
By putting the enumerated type in an array and allowing a For Loop structure to auto-index, a sequence of events can be driven. In the example shown in Figure 5.6 they go in sequence, but any order could be selected. From this simple structure a wealth of opportunities arise. For example, the array could be generated from a database or file, allowing a completely configurable system in very few steps.
Wiring an enumerated type into a While Loop shift register makes an extremely important structure called a state machine. The example shown in Figure 5.7 emulates a Sequence structure, but with added flexibility.
Consider the following. You've designed your component and created an enumerated type as a control and wired it to the connector. It's now deployed throughout your software. You now need to add some functionality to this component. You pop up and add a command to the enumerated type. If you put this new command anywhere but at the end of the list you will find all your popped up constants broken. If you put the new command at the end you will find ugly coercion dots everywhere. This is aggravating to say the least. The kindly people at National Instruments have given us a solution ”Strict Type Definitions.
You can edit your enumerated type on the Front Panel (highlight control and select Edit>>Customize Control . . ., or set your preferences to "edit a control on a double-click").
When the Panel shown in Figure 5.8 is displayed, select Strict Type Def. from the drop-down menu and then save in a Controls directory as controlName. ctl.
Now whenever you create a constant by popping up, it will be an instance of the Strict Type Definition. If you change one you change them all. Here are a few things to be aware of when dealing with Strict Type Definitions.
Bad Things
If you create a subVI by selecting it and using the Create subVI, the new Front Panel objects are not linked to the Strict Type Definition.
Similarly, popping up on a tunnel in a Case Structure does not create a tunnel.
And popping up from any of the built-in functions (Scan From String, Unflatten From String, etc.) doesn't create them either.
Good Things
Duplicating Cases and Sequences does preserve the link to the Strict Type Definitions.
Cutting and Pasting also preserves the link to the Strict Type Definitions.
Prior to LabVIEW 6 you didn't get a Strings[] attribute for a Strict Type Defined Enumerated Type, but you did for a normal enumerated type. This was overcome by looping around each element in the enumeration and creating the element content array from that loop.
We were a bit worried about the robustness of using Strict Type Definitions, for example, if we changed one how would this ripple through our software. In practice they have proven to be remarkably immune to change, invariably coping with anything that we could throw at them. Everything discussed here about Strict Type Definitions is also applicable to normal Type Definitions.
LabVIEW has the tools to define a flexible command and attribute message sending mechanism. Oh so powerful! Oh so underutilized !
Top |