Using Enums in Driver Builder #476
Quali-Community
started this conversation in
Useful Tips & Guides
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Enums are a useful tool that allow you to give a published variable a defined list of values that can be entered into it.
Creating Enums:
1. Go to your Driver Builder's project 'Driver' page. You can do this by double-clicking your project (andnot one of the driver's functions) in the 'Workspace' window and choosing 'Driver' from the 'Page' drop-down list at the top.
2. In the Metadata pane there is a short XML document. Create an end-tag to the 'DriverCompilationMetadata' element by removing the slash from the end of the line (turning the '/>' at the end to just a '>'), and adding another line under it that looks like this: </DriverCompilationMetadata>.
3. Inside of the DriverCompilationMetadata element (between the two lines - the start-tag and end-tag), create another element with a start-tag and end-tag called 'Enumeration'. Add an attribute to the Enumeration tag called 'Name',and enter the name of the enum that you want to create as the attribute's value.
Example:
4. Inside the 'Enumeration' element create an empty-element tag called 'Member' for every value that you want to add to the enum. Each 'Member' element should have a 'Name' attribute that has the name of the enum member as a value. Each member will have a numeric value according to the order of the members (The first member will be '0', the second one will be '1' and so on). You can give a member a numeric value of your choosing by adding a 'Value' attribute to the element, and entering a number as the attribute's value.
Since the name of the enum memeber must start with a letter and can't have spaces as a normal variable name would - you can use the 'Alias' attribute to assign other more readable values.
Example:
The finished XML document should look something like this:
If you want to add another enum, just add another 'Enumeration' element under the first one and follow the same steps for it. When you are finished,save the document.
Using Enums:
1. Go to a function in your project, create a variable that will be used with the enum (you can choose either a string or a numeric variable, since an enum's member has both a string value ('Name' attribute) and a numeric value ('Value' attribute). The variable must be scalar). Publish the variable. You will be taken to the function's 'Interface' page. Go to your variable's row in the Interface page table, and in the 'Enum' column choose your enum from the list.
2. If you want your enum to have a certain default value, enter the value as the variable's initial value and check the 'Default' checkbox in the Interface page. If the variable has an initial value that isn't a member of the enum and the 'Default' checbox is checked your driver won't work.
(Quali) - 03/19/2013 03:49 PM
· 2704 ·
Beta Was this translation helpful? Give feedback.
All reactions