Home AMX User Forum NetLinx Studio
Options

Conditionally include a Module

Hi AMX Forum people,

I was wondering if it was possible to conditionally include a module?

Something like:

if(true)DEFINE_MODULE blah blah

This doesn't work though.

The compiler directives do not include a #IF only #IF_DEFINED etc

Thanks for any suggestions

Comments

  • Options
    viningvining Posts: 4,368
    Only compiler directives will control what gets pulled into the compiler, hence their name. Everything else is run time.
  • Options
    If you are using a duet module, you could load that at run time with your conditional. We use this often when we deploy code where elements are variable - like the make and model of a display, or they have lighting control in one room but not the other - yet both rooms run the same code. This not only allows you to load what you need, but it also allows you to change the module on the fly (i.e. display is replaced with different model).

    If you want to find out more about the process, check out the term 'Dynamic Binding' in the Netlinx Studio > Netlinx Keywords Help section.
  • Options
    Jumping in on this thread, as I'm trying to do the same thing. I found this keyword DYNAMIC_APPLICATION_DEVICE (DEV duetDevice, char[] deviceType, char[] friendlyName).

    I have no idea what the valid deviceType's are and what should go in the friendlyName. Does anyone have a good example of this. This documentation doesn't specify.

    Thanks,

    Javed
  • Options
    wengerpwengerp Posts: 29
    Morris wrote: »
    The compiler directives do not include a #IF only #IF_DEFINED etc

    While that's true it allows you to do whatever you could do with an #IF as well. Let me make an example: all my include files start with something like
    #IF_NOT_DEFINED _WC_UTILS_
    #DEFINE _WC_UTILS_
    
    ....my code...
    
    #END_IF
    

    This way I can include my include files whenever I want without having to bother about multiple definitions or similar nasty stuff.

    So you can use something like
    #DEFINE _TRUE_                // only define this when needed
    #IF_DEFINED _TRUE_
    DEFINE_MODULE blah blah
    #END IF
    
  • Options
    javedwahid wrote: »
    Jumping in on this thread, as I'm trying to do the same thing. I found this keyword DYNAMIC_APPLICATION_DEVICE (DEV duetDevice, char[] deviceType, char[] friendlyName).

    I have no idea what the valid deviceType's are and what should go in the friendlyName. Does anyone have a good example of this. This documentation doesn't specify.

    Thanks,

    Javed

    Hi Javed,
    I'm just now looking into this, and found a list of the deviceTypes - they're listed in the help under DDD - Device SDK Classes and Constants. Hope that helps (if you had not found it already). The 'friendlyName' I'm not sure about but think it's just a definition that you make for your self.
Sign In or Register to comment.