Home AMX User Forum NetLinx Studio
Options

Data_Event with device arrays

Dear All,

I'm very often using arrays of devices when I like to handle events for all of them at the same time.

DEFINE_DEVICE

dvDEV1 = 5001:1:0;
dvDEV2 = 5002:1:0;
dvDEV3 = 5003:1:0;
dvDEV4 = 5004:1:0;
dvDEV5 = 5005:1:0;
dvDEV6 = 5006:1:0;

DEFINE_CONSTANT

dev dvDEV[ ] = {dvDEV1,dvDEV2,dvDEV3,dvDEV4,dvDEV5,dvDEV6};

I realized that if I'm using any ****_wait _**** inside a data_event of a device array, any command after the wait is ignored if in the meantime there is another device which triggers the event.

For example:

data_event[dvDEV]
{
online:
{
local_var integer iDev;

   iDev = get_last(dvDEV);

                     send_string 0, "'Device',itoa(iDev),' is sending string1'";
  wait 5{     send_string 0, "'Device',itoa(iDev),' is sending string2'";
  wait 5{     send_string 0, "'Device',itoa(iDev),' is sending string3'";
               }}
 }

string:
{
local_var integer iDev;

   iDev = get_last(dvDEV);

                         send_string 0,"'Feedback1 from Device ',itoa(iDev)";
   wait 100     send_string 0,"'Feedback2 from Device ',itoa(iDev)";            
 }

}

In case of "ONLINE", any device which is coming online is sending the first "string1".
If another device is coming online while the previous one has not reached at the end , any remaining "waits" are ignored and are never executed.
Only the last device which is coming online, is able to reach the end and execute any command inside the "waits" because there is no other remaining device that could come online and interrupt the procedure when firing the data_event.

In case of "STRING", the first string is always sent. The second one is also sent based on the last device which triggers the event during the 10 seconds of wait. At least, in this case the command after the "wait" is not ignored.

Is it a principle that a master is working like this ?

George

Comments

  • Options

    Probably. Not so sure about the 'waits are ignored' part, but it probably won't work the way you expect it to.

    Variables used in a WAIT are evaluated at the time the wait is executed, NOT at the time the wait is started.

    In your 'string' example, if within the 10 second wait, a string from another device comes in, 'iDev' will change to that device(index) and the wait will use _that _when it executes, so always the last device that triggered the event.
    If you want to use WAITS in this case, you'll have to specific. You can still use one data_event for the array, but have to treat each of the devices that triggered the event seperately when a wait is needed.

    data_event[dvDEV]
    {
        online:
        {
        switch (get_last(dvDEV));
        {
            case dvDEV1:
            {
            wait 5
            {
                send_string 0,"'Device 1 is online'";
                //do stuff
            }
            }
            case dvDEV2:
            {
            wait 5
            {
                send_string 0,"'Device 2 is online'";
                //do stuff
            }
            }
            case dvDEV3:
            {
            wait 5
            {
                send_string 0,"'Device 3 is online'";
                //do stuff
            }
            }
            case dvDEV4:
            {
            wait 5
            {
                send_string 0,"'Device 4 is online'";
                //do stuff
            }
            }
            case dvDEV5:
            {
            wait 5
            {
                send_string 0,"'Device 5 is online'";
                //do stuff
            }
            }
        }
        }
    
  • Options

    I think the wait has an internal ID that when it is re-encountered and is already running then it is ignored.
    This was probably a common problem where wait statements were being coded in the DEFINE_PROGRAM and would thus generate erroneous waits.

    i would rather use a timeline for each device

    DEFINE_DEVICE
    
    dvDEV1 = 5001:1:0;
    dvDEV2 = 5002:1:0;
    dvDEV3 = 5003:1:0;
    dvDEV4 = 5004:1:0;
    dvDEV5 = 5005:1:0;
    dvDEV6 = 5006:1:0;
    
    DEFINE_CONSTANT
    
    dev dvDEV[ ] = {dvDEV1,dvDEV2,dvDEV3,dvDEV4,dvDEV5,dvDEV6};
    
    long TLID_Online[6] = {1,2,3,4,5,6}
    long TLTL_Online[] = {500,500,500}
    
    DATA_EVENT [dvDEV]
    {
        ONLINE:
        {
            stack_var integer ndx;
            ndx = get_last(dvDEV)
            if (TIMELINE_ACTIVE(ndx))
                TIMELINE_SET(TLID_DevOnline[ndx],0)
            else
                TIMELINE_CREATE(TLID_DevOnline[ndx],TLTL_DevOnline,LENGTH_ARRAY(TLTL_DevOnline),TIMELINE_ABSOLUTE,TIMELINE_ONCE)
        }
    }
    
    TIMELINE_EVENT[TLID_DevOnline]
    {
        stack_var integer ndx;
        stack_Var integer iDev;
    
        iDev = get_last(TLID_DevOnline)
    
        switch(timeline.sequence)
        {
            case 1:
            {
                send_string 0, "'Device',itoa(iDev),' is sending string1'";
            }
            case 2:
            {
                send_string 0, "'Device',itoa(iDev),' is sending string2'";
            }
            case 3:
            {
                send_string 0, "'Device',itoa(iDev),' is sending string3'";
            }
        }
    }
    
Sign In or Register to comment.