Home AMX User Forum NetLinx Studio

Compiler directives in IF statements

So I guess I am confused with compiler directives, specifically #DEFINE. I have a couple of #DEFINE's in some IF statements and the point is to only define them if a particular variable is true....simple enough. However it seems like at least with #DEFINE's that it runs that line no matter what regardless if it is in an IF statement and regardless if the condition is true or false. Is this correct? I have not done a proof of concept just slimming it down but I am fairly sure that this is happening.

Comments

  • MLaletasMLaletas Posts: 226
    So I guess I just am missunderstanding how #DEFINE works. Just did a proof of concept with the following code and results
    PROGRAM_NAME='Directive Test'
    (***********************************************************)
    (*  FILE_LAST_MODIFIED_ON: 03/01/2016  AT: 16:18:44        *)
    (***********************************************************)
    
    DEFINE_DEVICE
    
    dvMaster        = 0:1:0
    vdvTest            = 33001:1:0
    
    DEFINE_CONSTANT
    
    
    DEFINE_TYPE
    
    DEFINE_VARIABLE
    
    INTEGER nTest
    
    DEFINE_LATCHING
    
    DEFINE_MUTUALLY_EXCLUSIVE
    
    DEFINE_START
    
    DEFINE_EVENT
    
    CHANNEL_EVENT[vdvTest,1]
    {
        ON:
        {
        IF( nTest )
        {
            #DEFINE DEFINE_ENABLED
        }
        #IF_DEFINED DEFINE_ENABLED
            SEND_STRING 0,"'nTest: ',ITOA( nTest )"
            SEND_STRING 0,"'Define enabled went through'"
        #END_IF
        }
    }
        
    DEFINE_PROGRAM
    

    Results:
    Line      1 (16:19:52)::  nTest: 1
    Line      2 (16:19:52)::  Define enabled went through
    Line      3 (16:19:59)::  nTest: 0
    Line      4 (16:19:59)::  Define enabled went through
    
  • Compiler Directives only work at compile time - NOT RUNTIME.

    What are you trying to accomplish?

    I think the way you have this coded the DEFINE_ENABLED will always be defined.
    The Compiler does not evaluate IF ( nTest ) at Compile time.

  • MLaletasMLaletas Posts: 226
    Oh compile time, I must have read over that. So this will absolutely not work with what I am trying to do. Thank you donachiue. What I am trying to achieve is to read in a file that will designate what type of device it is, for example a Samsung display.
    #IF_DEFINED DISP1_SAMSUNG
    DEFINE_MODULE 'Samsung display' samsung1( dvdisp1, vdvdisp1 )
    #END_IF
    

    Now obviously that will not work, I have to rethink how I am going to approach this.
  • GregGGregG Posts: 251
    I use a meta-function and set a variable to indicate what type each monitor is, like this:
    Define_Function MonitorFunction(Integer nMonitor, Integer nInput)
    {
        Switch(nMonitorProtocol[nMonitor])
        {
            Case MONITOR_TYPE_NEC:
                NECFunction(nMonitor,nInput)
    
            Case MONITOR_TYPE_PLANAR:
                PlanarFunction(nMonitor,nInput)
    
            Case MONITOR_TYPE_PANASONIC:
                PanasonicFunction(nMonitor,nInput)
    
            Case MONITOR_TYPE_SAMSUNG_HOTEL:
                SamsungHotelFunction(nMonitor, nInput)
    
            Case MONITOR_TYPE_PANASONIC_NEW:
                PanasonicNewFunction(nMonitor, nInput)
    
            Case MONITOR_TYPE_VIEWSONIC:
                ViewsonicFunction(nMonitor, nInput)
    
            Case MONITOR_TYPE_SHARP_SPACES_AFTER:
            Case MONITOR_TYPE_SHARP_SPACES_BEFORE:
                SharpFunction(nMonitor,nInput,nMonitorProtocol[nMonitor])
    
            Default: { Send_String 0,'Unknown monitor type'}
        }
    }
    

    Of course, this means I can't use display modules... but no real loss there.
  • MLaletasMLaletas Posts: 226
    Thats not bad, I would have to convert all my modules to use that kind of functionality but thats definitely an option, btw i like you naming for the Sharp display :)
  • I've done this by defining multiple modules for a given display (or other device) each with their own virtual device, then another virtual device that the program interacts with and use an array of devices with a flag to control which one is active.

    So instead of:
    SEND_COMMAND vdvDISPLAY1, "'POWER ON',$0D"
    


    You would have:

    SEND_COMMAND vdvDISPLAY1[nACTIVE_DISPLAY], "'POWER ON',$0D"
    

    And so on. For DATA_EVENTS from the devices, you would do something like:
    DATA_EVENT[vdvDISPLAY1]
    {
             STRING:
             {
                     IF(GET_LAST(vdvDISPLAY1) == nACTIVE_DISPLAY)
                     {
                             //DO WHATEVER FEEDBACK HANDLING FROM DISPLAY1
                     }
             }        
    }
    

    It makes for a bunch of code but makes sense if you have a bunch of identical rooms that vary by display model or type of playback device for instance.
  • Here's another way you might accomplish your goal, without converting your modules over. It does not 'read' from a file that is loaded to the disc on chip, but may provide the functionality you are looking for.

    Have a config.axi file with your #define statements:

    #define Display_Samsung
    #define Bluray_Oppo
    #define Switcher_ExtronSIS
    etc, etc.....

    In your main program file, call this axi file first. Then use compiler directives to instantiate your modules if and only if the specific keyword is defined:

    #if_defined Display_Samsung
    define_module 'Samsung Display'
    #end_if

    Hope this helps,

    erik
Sign In or Register to comment.