LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I use "conditional disable diagram" and "diagram disable structure" to disable and enable a section of a code programmatically? If yes, how?

I came across  "conditional disable structure"; I couldn't figure how to use it. I also took at "diagram disable structure". This last one is good, but I have to manually disable and enable which is not what I want to do. I would prefer to disable and enable programmatically when some conditions are met. I just wish there was a way to do it programmatically.

 

I looked at the example code by NI for "conditional disable structure." I couldn't quite understand it.

I look forward to hearing from you, guys.

 

Thanks!

0 Kudos
Message 1 of 11
(1,303 Views)

@GRCK5000 wrote:

I would prefer to disable and enable programmatically when some conditions are met. I just wish there was a way to do it programmatically.


That sounds like you just want a simple Case Structure.

 

The Conditional Disable Diagram and Diagram Disable Structure are for telling the compiler to ignore parts of code.  The CDDS is sort of programmable in that you can make project variables to set which case is enabled.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 11
(1,290 Views)

Hi GRCK,

 


@crossrulz wrote:
The CDDS is sort of programmable in that you can make project variables to set which case is enabled.

To expand this one:

  • Right-click your project and open the project properties dialog. Here you will find an entry to view/edit "Conditional disable symbols". (There are some pre-defined symbols as written in the help for the CDS.)
  • When creating a new case in a CDS you can select the symbol and define a value for that symbol to enable the case…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 11
(1,276 Views)

@GerdW wrote:

Hi GRCK,

 


@crossrulz wrote:
The CDDS is sort of programmable in that you can make project variables to set which case is enabled.

To expand this one:

  • Right-click your project and open the project properties dialog. Here you will find an entry to view/edit "Conditional disable symbols". (There are some pre-defined symbols as written in the help for the CDS.)
  • When creating a new case in a CDS you can select the symbol and define a value for that symbol to enable the case…

It should be noted that this is an edit time operation. This cannot be done on a built application or PPL. I believe the user is asking for a runtime option to enable/disable certain functionality in the code. In this case the only solution is a basic case structure.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 11
(1,256 Views)

Yes, you understood what I was asking. So I guess I will stick with case structure. I was just wondering if there was a different option besides case structure.

0 Kudos
Message 5 of 11
(1,249 Views)

If what you are after is a text description for each case, you can create an enum (preferably as typedef) to be wired to the case selector.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 6 of 11
(1,240 Views)

@GerdW wrote:

Hi GRCK,

 


@crossrulz wrote:
The CDDS is sort of programmable in that you can make project variables to set which case is enabled.

To expand this one:

  • Right-click your project and open the project properties dialog. Here you will find an entry to view/edit "Conditional disable symbols". (There are some pre-defined symbols as written in the help for the CDS.)
  • When creating a new case in a CDS you can select the symbol and define a value for that symbol to enable the case…

But this will only work in development environment, and VIs with the CDDS shouldn't be running.

 

Also, you can programmatically write CDS, but you can also read them. This has ups and downs. An up is that VIs using the symbol don't get recompiled, spoiling SCC. A down is that code using the symbol in a case isn't removed in a build. 

0 Kudos
Message 7 of 11
(1,239 Views)

@GRCK5000 wrote:

Yes, you understood what I was asking. So I guess I will stick with case structure. I was just wondering if there was a different option besides case structure.


Object oriented polymorphism is an alternative.

 

Switching child switches behavior. You'd still need to make the switch somewhere (in a case structure, selector, array index, CDDS or dynamically).

 

The benefit of OO is that the wire specifies the behavior. So, on init you can choose an implementation, leaving all users untouched. You can even add different behavior without changing any of the code using the class...

Message 8 of 11
(1,235 Views)

@GRCK5000 wrote:

I came across  "conditional disable structure"; I couldn't figure how to use it. I also took at "diagram disable structure". This last one is good, but I have to manually disable and enable which is not what I want to do. I would prefer to disable and enable programmatically when some conditions are met. I just wish there was a way to do it programmatically.

 


Why do you call if "good" if it does not suit your purpose??? What is your definition of "good" and what do you want it to actually do?

 

You've gotten some quite advanced answers, but I suspect that your question is much simpler!

 

These three structures serve very different purposes:

 

The diagram disable structure lets you define code sections that are completely ignored by the compiler. They can even contain broken code and the rest of the VI can still run. This is useful during programming where you want to test a small part of code while some other parts are still under constructions and broken.

 

The conditional disable structure contains instructions for the compiler to use one specific code depending on external factors. Some examples from my own use: (1) One of my programs runs on 32bit and 64bit LabVIEW, but depending on the current bitness, it needs to call a different dll (one is 32bit and one is 64 bit). The compiler of course knows the current bitness and will pick the right case accordingly. (2) most of my programs act differently depending if they are run in the development environment compared to a built executable. In the exe, closing the window (using the X in the upper right) will initiate shutdown (using a filtering event) and terminate the program while in the development environment it just stops the VI, keeping the window open so I can continue programming.

 

The case structure is the only one that can select different cases at runtime and is the only structure you need for that. It is extremely flexible and can contain as many cases as you possibly need and accepts a very rich selections of inputs (integers, strings, enums, etc.). If you feel that you need something else, please explain in detail and we will point you in the right direction.

 

0 Kudos
Message 9 of 11
(1,204 Views)

As many have said a simple case is all you should need, but you didn't really explain why you want to use those structures in your program...

 

So I will give you an example of how I use a case statement to "enable" or "disable" code.

 

We have several test system in our lab, throughout the years these systems have been piecemealed together with products from several equipment manufacturers.

 

I can run the same program on any of these systems because it contains all of the code for every possible piece of equipment.

 

Then by reading a system configuration file at at startup the program selects the proper code to run.

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 10 of 11
(1,192 Views)