Home AMX User Forum AMX General Discussion

online code doesn?t work inside a module

Hello!

I?ve created a module with a DATA_EVENT[dvTp] online code inside of it, and it works strange for me.

the program only executes the online code when the master is power off and then power on, but the online event doesn?t get executed when i reboot the master or the touch panels, is it normal or is there something that i?m missing?

I?ve put the define_module statements after the DEFINE_VARIABLE section of the main program.

Any help?

Thanks and salutes!!!

Comments

  • MorgoZMorgoZ Posts: 116
    Ok, the question were wrong.

    The online event works fine inside a module, the problem is that the device that i check for its online event (a touch panel) is defined at the DEFINE_START section of the main code, and it seems to be that the modules are executed before the DEFINE_START, so there is no device defined when the module is defined.
    I need to define the device at the DEFINE_START because it is inside of a structure, and i think that the structures have to be initialized at the DEFINE_START, don?t they?

    So, if you think that i can initialize the device (of the structure) somehow to define it before the module, please tell me.

    Thanks!!!!!
  • In general, DEFINE_MODULE is mostly done at the end of DEFINE_START. So you have a chance to initialize your variables, and then pass them inside the module.

    But I think it is more a problem of the DEFINE_START at all. DEFINE_START would be passed after reboot much earlier than the panel would be online. So a simple routine like
    DEFINE_START
    SEND_COMMAND dvPanel,'PAGE-START'
    
    would fail.

    Another issue may be the so called Event table. The NetLinx compiler creates this table which includes any device/channel/Level/Timeline Event ID used in the code at compile time, not at program start. So it is "fixed" and it would not be possible to use a variable i.e for a device in a button_event without recreating this table.
    DEFINE_VARIABLE
    DEV dvMyDevice
    
    DEFINE_START
    dvMyDevice = 10001:1:0 // ok by syntax...
    
    DEFINE_EVENT
    DATA_EVENT[dvMyDevice] // ...but the event would not be created into the table by the compiler
    {
    }
    

    To get the above to work, the command REBUILD_EVENT() must be used to recreate the event table. See language manual for more details.
    DEFINE_VARIABLE
    DEV dvMyDevice
    
    DEFINE_START
    {
    dvMyDevice = 10001:1:0 // ok by syntax...
    REBUILD_EVENT() // recreate the event table, only the elements affected within the braces
    }
    
    DEFINE_EVENT
    DATA_EVENT[dvMyDevice] // now the event would work 
    {
    }
    
    See details to REBUILD_EVENT() in the NetLinx langauge manual, or type it in studio and hit F1
  • MorgoZMorgoZ Posts: 116
    Many thanks for your help!!!

    Once i read about this sentence, but i didn?t notice that it could help me now ;)

    Salutes!!
Sign In or Register to comment.