Home AMX User Forum NetLinx Studio

DEVLEV & LEVEL_EVENT

Hi,

I am struggling to get a LEVEL_EVENT to work for an array of levels.

Code:

DEFINE_VARIABLES
DEVLEV Scenes[]

DEFINE_START
Scenes[1] = {dvLights,1}
Scenes[2] = {dvLights,2}
Scenes[3] = {dvLights,3}
Scenes[4] = {dvLights,4}
Scenes[5] = {dvLights,5}
Scenes[6] = {dvLights,6}


DEFINE_EVENTS

LEVEL_EVENT[Scenes]
{
!!Do Something!!
}

When looking at the diagnostics I am seeing the levels change but it is not triggering the level event. Am I using this correctly?

TIA, Phil

Comments

  • frthomasfrthomas Posts: 176
    Your code seems edited so I am not sure this applies, but you probably need to set the actual size of the Scenes array. In DEFINE_VARIABLE you probably give it a size (it would not compile as shown), but it is the MAX size. Once you've added stuff to the array in DEFINE_START, you need to set its size with SET_LENGTH_ARRAY(Scenes, 6). Netlinx does not "see" you're adding stuff to the array and consequently thinks it is empty -> no event for an empty DEVLEV array.

    HTH

    Fred
  • hodeyphodeyp Posts: 104
    Fred,

    Thanks, you were right that this was an edited cut'n'paste - I do actually have the array size set to 6.

    Any other thoughts?

    regs, Phil
  • DEVLEV & LEVEL_EVENT

    Phil,

    While Fred is correct about the length of the array being 0 unless explicitly being set to the desired length using SET_LENGTH_ARRAY(), this is not the only problem with the code segment.

    You are building an event trigger table in runtime and this requires that you inform Netlinx that an event trigger list for a declared handler has been modified. In this case, once the DEVLEV array is built and the SET_LENGTH_ARRAY() command has been issued to establish the correct size of the array, you would include the REBUILD_EVENT() runtime command following them to force Netlinx to rebuild the event handler tables which would take into account the initialized DEVLEV values in your array.

    In your case, since the device component is always the same, you could have used a single device specification and an integer array for your level event.
    LEVEL_EVENT[dvLights, nLightLevels]
    {
        STACK_VAR INTEGER nLevel
    
        nLevel = GET_LAST(nLightLevels)    // level that caused the event
    
        ... do stuff ...
    }
    
    where nLightLevels is an array of integer values from 1 to 6. If you initialized the array in the DEFINE_VARIABLE section with the values 1 to 6, then REBUILD_EVENT() would not be needed. Otherwise, if initialized in DEFINE_START, you would need to rebuild the event table.

    The reason I point out the latter alternative is that there are some known issues with DEVLEV and DEV array handling in level events. In particular, using arrays of DEVs or arrays of DEVLEVs in an event handler where GET_LAST() is used to determine the device/level causing the event does not work (see TechNote 486). There are workarounds -- see the TechNote for more information. Note that the problems are limited to LEVEL_EVENTS and the use of the GET_LAST() command to determine the device generating the event.

    Reese
  • hodeyphodeyp Posts: 104
    thanks, did this and works as expected....

    ..or almost!

    Got a very frustrating one here, I have combined the levels on the lighting system with levels on the touchpanel.

    I have read all of the combine level notes both here and on the amx website and am certain I am doing thins as per example code. However, I am not getting levels sync'd even though they are combined...

    I ahve checked on the master using show_combine and get back the follwoing...

    Combines
    Combined Level([33005:1:1,1],[10001:1:1,3],[5001:1:1,1])
    Combined Level([33005:1:1,2],[10001:1:1,4],[5001:1:1,3])
    Combined Level([33005:1:1,3],[10001:1:1,5],[5001:1:1,2])

    I created the combines in the define_start section of the code as follows...

    COMBINE_LEVEL(vdvLevelControl,1,tpDrawingRoom,3,dvLUTRON,1)
    COMBINE_LEVEL(vdvLevelControl,2,tpDrawingRoom,4,dvLUTRON,3)
    COMBINE_LEVEL(vdvLevelControl,3,tpDrawingRoom,5,dvLUTRON,2)

    I have a single LEVEL_EVENT as per the below post.

    Now for the funny bit, if I select a level on the touchpanel all works as expected, lights change to reflect selected scene.

    I have also built a DATA_EVENT that receives status from the rs232 unit and parses it into current levels (for when lights are switched on from the light switch instead of the touchpanel)

    The DATA_EVENT has a SEND_LEVEL to the dvLUTRON [5001:1:1] and when I check the device status I can see that the correct level has been set in this device. However, this is not then passed back to the touchpanel.

    Am I using levels correctly??

    Regards

    Phil
  • frthomasfrthomas Posts: 176
    Have you tried sending the level to the virtual one?
  • hodeyphodeyp Posts: 104
    good suggestion - it works!!

    Am I missing the point here? I thought by combining levels they would 'act as one' and a level change on any of them would cause the level to change on the others and any corresponding LEVEL_EVENTS to be called...
  • frthomasfrthomas Posts: 176
    Conceptually yes, but then why would you need the virtual device in the first place? Why can't you combine arbitrary levels?
    In practice, the direction is important. Real device levels are synced on all devices in the COMBINE_LEVEL statement, but the programmers way to send a level is to send it to the virtual level.

    In many cases, real and virtual devices are handled differently by Netlinx, and this is one of the cases.

    Fred
  • DHawthorneDHawthorne Posts: 4,584
    hodeyp wrote:
    good suggestion - it works!!

    Am I missing the point here? I thought by combining levels they would 'act as one' and a level change on any of them would cause the level to change on the others and any corresponding LEVEL_EVENTS to be called...
    Not exactly. The way it works is that all the combined levels will respond to and affect the virtual level. All actions and reactions on the virtual will carry to all the combined elements. But actions directed towards one of the combined elements will only affect that single element and the virtual, and not the other elements. You need to use your virtual as the "gateway" for everything for a combine to work properly.
Sign In or Register to comment.