LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Conditional compilation

I have developed a LabWindows/CVI application for a piece of equipment. I now want to apply this to a similar piece of equipment, but using slightly different UI panels and functions. Is there a way to conditionally include those panels and functions that are applicable to each piece of kit? I am particularly concerned about the automatic generation of include (.h) files for the UIR.
0 Kudos
Message 1 of 5
(3,495 Views)

If your panels are kept in separate UIRs, then you can just conditionally include the corresponding .h file and conditionally specify the .uir filename in LoadPanel:

 

#define EQUIPMENT_1

 

#ifdef EQUIPMENT_1

#include "Equipment1UI.h"

#define UIR_FILENAME    "Equipment1UI.uir"

#elif defined(EQUIPMENT_2)

#include "Equipment2UI.h"

#define UIR_FILENAME    "Equipment2UI.uir"

...

#endif

 

int main (int argc, char *argv[])
{
    ...

    panelHandle = LoadPanel (0, UIRFILENAME, PANEL));

    ...

}
 

This works well if your control constants (e.g. PANEL_BUTTON1, PANEL_GRAPH, ...) and callback functions are named consistently from one UIR to the next.

 

Another approach would be to put all your UI variations in one UIR file. Then your panel constants would have to be different, and therefore, so would all of your control constants. That makes things a little more tricky, because you have to pass a different constant into UI library functions depending on which piece of equipment you're building for. You can work around this issue pretty easily by doing something like this:

 

#ifdef EQUIPMENT_1
#define THE_PANEL      PANEL

#define CTRL(NAME)     PANEL##_##NAME
#elif defined(EQUIPMENT_2)
#define THE_PANEL      PANEL2

#define CTRL(NAME)     PANEL2##_##NAME
#endif

 

Then just use THE_PANEL wherever you need the panel constant, and use CTRL(BUTTON), for example, wherever you would have used PANEL_BUTTON or PANEL2_BUTTON.

 

Hopefully this gives you some ideas. If I'm way off in understanding your original question, please let me know.

 

Mert A.

National Instruments

0 Kudos
Message 2 of 5
(3,480 Views)

Thanks for those suggestions, I hadn't realised that there were so many ways of killing a cat! My tired brain was working over the weekend and came up with the idea of providing the basic set of controls on the standard panel, then conditionally including code to programmatically add the extra controls and reposition the standard ones where required using the control attributes. Which is the easiest to manage, in your experience?

 

When using separate uir's, do you just make a copy of the first one and keep it in the workspace under a new name? Presumably if you start working on the second one, it generates a new .h include file when you save changes?

0 Kudos
Message 3 of 5
(3,458 Views)

If your panels are really *slightly* different, you could create one panel only in the UIR editor with all controls needed for all types of devices, programmatically customizing its aspect dependng on the type of equipment tested. This permits you to have one set only of controls in your program.

You can programmatically apply all properties that you can set in the UIR editor, so you can:

  • Hide or discard controls not used for a type; alternatively tou can simply disable them or make them indicator, thus avoiding the user to operate on them
  • Assign different callback functions to controls (remember that callbacks not assigned to controls in the UIR editor must be declared in a separate #include file for the compiler to find them)
  • Remove callbacks from controls
  • Apply all cosmetic changes needed to adapt to that particular type of equipment


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 5
(3,433 Views)

That sounds exactly what I want to do. Many thanks. I was worried about maintaing different panels and include files.

0 Kudos
Message 5 of 5
(3,418 Views)