LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically get names of all cases in a case structure

Solved!
Go to solution

Hi All,

          I have a subVI that is a state diagram (controlling some test equipment), with many states (i.e. each "state" is a case of a case structure), a text string chooses the case. All cases are named.

         Within this subVI is it possible for me to programmatically retrieve the text name for each case of this case structure? I wish to be able to retrieve these strings so that the main VI will only be able to call valid states.

        I have error handling to ensure that if an invalid state is called (by using the default case) that an error will be returned to my main vi, yet I would prefer to be able to retrieve the string to prevent any typo's etc.

 

      Not sure if I've explained this well.

     Thanks,

    ds1

 

0 Kudos
Message 1 of 22
(7,339 Views)

You can do it with LabVIEW scripting, however, I wouldn't leave scripting in a final application. Use a typedef enum if you don't want to worry about this. If you want to keep it as a string (remember, this is a heavily debated subject) just make sure you test all cases before making it an executable and that should suffice. If you want to check to make sure it's a valid string, this seems like a bit overkill on the error checking! Just work it out when testing, or again as was said above, use a typedef enum.

0 Kudos
Message 2 of 22
(7,329 Views)

You have, but I don't see how this will help you. Is someone entering the state name on the front panel? Let's say you're fed a state that doesn't exist. What do you intend to do?

 

To answer your question, you would use scripting to do that. LabVIEW 2010 opens up scripting as an API. You can enable scripting for earlier versions. Do a search and you will find out how to do this, and there are also numerous examples on using the scripting API.

0 Kudos
Message 3 of 22
(7,328 Views)

Hello ds1,

it's not very clear what could be the source of the typo error: the user or the developer? On the developer side, using enums instead of simple strings is the right choice.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 4 of 22
(7,317 Views)

Thanks guys!

               I actually generally use the enum instead of strings, (I guess I'd kinda forgotten why I'd preferred them!) My Main VI calls many states on the equipment, I thought the strings may have been easier to set up a sequencer (and saving my sequences in text would be more useful)

    The scripting I can look into although it sounds a little complex, perhaps this would be overkill in error handling!

   At present I have a state "No State Error" which is my default state, so if any state isn't recognised it will run this case (report error at exit the state diagram while loop)

    This should do, I guess I was getting carried away from what this program actually is required to do!! The user in the lab will easily spot the typo's after being flagged

 

Thanks again!

0 Kudos
Message 5 of 22
(7,312 Views)

@ds_1 wrote:

               I actually generally use the enum instead of strings, (I guess I'd kinda forgotten why I'd preferred them!) My Main VI calls many states on the equipment, I thought the strings may have been easier to set up a sequencer (and saving my sequences in text would be more useful)


If you need the string of the a typedef you can simply connect it to Format to string and you'll get a text readout. That took me a long while to find out. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 22
(7,301 Views)

Well, you can convert a string to an enum rather easily.

 

However, why would a user be allowed to change code? If the user is creating these sequence files perhaps you should have some sort of simple sequence editor so they don't have to write them by hand. Or, you should parse the file before you try to execute it. 

0 Kudos
Message 7 of 22
(7,297 Views)

Thanks for the suggestions again guys, I may just stick with the strings. A user for this code will be fellow engineers in the Lab, the VI is intended to be "generic" so all the typically used functions are accessible and "sequencable", however I won't be able to cover ever imaginable way it can be used, so it will always be editable.

  The VI will basically be a good starting point for those using the instrument to develop with.

0 Kudos
Message 8 of 22
(7,288 Views)
Solution
Accepted by topic author ds_1

 


@ds_1 wrote:

[...]   The scripting I can look into although it sounds a little complex [...]


It's not too complex, but it won't likely work in an executable.  This program gets a reference to the case structure (by looking for the label text) and returns a list of frame names.

 

Example_VI.png

 

Perhaps my CaseSelect plugin will help you with your string-based State Machine.  You can put valid states into String Constants by double-clicking from a list of cases.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 9 of 22
(7,256 Views)

Hi Jim,

          This does look straight forward, I'll give it a go, although the CaseSelect plugin though doesn't seem to be installed with my right-click-framework. I've updated VIPM (i'm on LV 8.5), not sure why it hasn't been found?

         Thanks,

      ds

0 Kudos
Message 10 of 22
(7,232 Views)