to close
With the default code, there is a Dashboard Write in begin that takes an array of strings and sends them to the dashboard (it’s used there to populate an “auto selector” dropdown):
This is then read back in the beginning of the provided auto-code template for a case structure.
These strings are case-sensitive, space-conscience strings - requiring you to type the exact same value into the string array in Begin and into the case structure in Auto. Yuck.
For the sake of simplicity, let’s use an enum to provide the strings to the dashboard and to populate our case structure (an enum is a coding construct where names are given to numeric values - here, we’re using the names and taking advantage of the defined ordering).
In Begin.vi, create an enum control (we need to access the strings from the enum via properties, which are not available on a constant).
Right click on the control, and select: Create -> Property Node -> Strings[]
Then, connect the strings array to the dashboard.
We may want to update the values later (either adding, or substituting), so let’s take a moment to make this enum a TypeDef (docs here)
The value coming back from the dashboard is still a string, but we can convert it to the enum.
Place a copy of the typedef’d enum on the diagram connected to a “Scan from String” as the default value.
The “Scan from String” will identify the value of the enum that matches the passed string (while one can do this with arbitrary strings, it is best to do it only when the strings are guaranteed to be equivalent to one of the enum value names).
Connect the output from the “Scan from String” to a new case structure.
Open the typedef and provide the desired possible modes (make sure to include a do-nothing).
Apply changes:
(save and close the TypeDef)
Right click on the case structure and select “Add case for every value” this will create a case (branch) for each option in the enum.
(For an example of later updating the typedef enum with different or more values, see the TypeDef Tutorial)
You now have an enum that (if edited) will update both in Begin.vi - where it’s strings are sent to the dashboard to select an auto, and in Autonomous(…).vi - where it is used to parse the returned string and manage possible case structure values.