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
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.
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