LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I programaticaly replace an Enum with an other inside a cluster

Solved!
Go to solution

Hello,

 

In my programm, I'm using a Queued-State-Machine architecture to pass Datas (in variant) between main VI states and SubVIs states. I'm using 3 types of tests (where my sequence of axis motion is a bit different). These 3 types of tests have their own Enum to control some process (Enums don't have the same items). The Enum is placed in cluster named "Type & # Fonctions" which is itself placed in the main control (see MainControl picture). This main control is in a shift register, in a while loop.

 

My idea would be to replace the Enum (e.g. replace "Enum Type 1" with "Enum Type 3") . The limitation is that some Bundle functions and Variant to data function, wait to have exactly the same data type (same Enum Items), and I just want to unbundle the "Type & # Fonctions" cluster from my main control to have the correct Enum (see BD picture).

 

An alternative solution shoud be to have 3 controls with their own Enum (ex.: Main control Type 1.ctl - Main control Type 2.ctl - etc), and select the correspondant Main Control in accordance with my test; but I want to reduce the number of controls, so that the programm could be as autonomous as possible.

 

Therefore, I would know if there is a way to programaticaly replace the Enum in my Main (cluster) control..?

 

Best regards

 

 

Fred

 

Download All
0 Kudos
Message 1 of 11
(4,286 Views)
Solution
Accepted by topic author Fred_A

You can't do that at run-time. Doing so requires a data type change, which effectively means the application is trying to modify its own code (i.e., itself) and that is not allowed. You can use scripting to replace stuff, but that is an edit-time operation, not a run-time operation.

 

You can either replace that enum with a string, or you can use multiple controls as you had alluded to.

Message 2 of 11
(4,273 Views)

You might want to look into LabVIEW classes.  This kind of problem can usually be solved with dynamic dispatching VIs.

Message 3 of 11
(4,262 Views)

 


@DFGray wrote:

You might want to look into LabVIEW classes.  This kind of problem can usually be solved with dynamic dispatching VIs.


I had considered that, but I wasn't sure how you'd use dynamic dispatching for a control on the front panel. Admittedly I have little experience with dynamic dispatching.

 

0 Kudos
Message 4 of 11
(4,254 Views)

Why can't you just use one enum with all the states in it? Since you are using a queued state machine, you can queue up only the states you want based on which mode you are in. Maybe I'm misunderstanding what you are trying to do.

0 Kudos
Message 5 of 11
(4,253 Views)

Hello,

 

Thanks for the reply..

 

It is what I was thinking. I have tryed some conversions (like: Flatten to string, Type cast, ...) but it doesn't work.

Finaly, I will use multiple controls, because replacing that enum with a string will be less efficient in my case (too much constants).

 

In brief, thank you very much for the solution..Smiley Wink

 

Best regards

 

 

Fred

0 Kudos
Message 6 of 11
(4,252 Views)

You are right, it's a solution too, but it was symply to have a coherent/readable diagram.. sometimes should we make more compromise.. 😉

0 Kudos
Message 7 of 11
(4,242 Views)

sorry, I dont folow the flow of responses..

message n°7 was for : for(imstuck)

@ DFGray: I'm not sure it resolve this (specific problem), like smercurio_fc says, but in many cases LabVIEW classes, should be the solution. II've just started to study LVClasses, so I can't use it right now..

 

thanks at all

0 Kudos
Message 8 of 11
(4,237 Views)

A readable way - but not something I would particurly recommend due to the way things would change (potentially making debug rather interesting and bringing lots of Rube Goldberg ridicule from other developers), would be to have your Enums / constants on your diagram and programmatically update a RING at runtime with a cluster of strings and values according to the Enum required. That way you could type cast the ring output with the Enums (type def) at all instances where you want to see what is going on, but still maintain a flexible cluster!!

It would do what you want - select from the text list and show the case in text on the BD according to what is selected if you wrote your code in this way, you would just have to watch out for the incorrect Enum being type cast (good error handling) (string match on the ring text with the enum text maybe?)

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 9 of 11
(4,217 Views)

To dynamically dispatch a front panel control (or the equivalent of a front panel control) you would need to use a subpanel control and dynamically dispatch the VI that loads into the subpanel with one containing the control in question.  You would also need the appropriate communication mechanisms (queues, user events, ...) to get data into and out of the control.  User events would probably be easiest.

 

You may also be able to solve the issue with an X-Control, but all possible enums would need to be defined at development time.  The classes approach would allow dynamic loading at run time.

0 Kudos
Message 10 of 11
(4,194 Views)