DEFINE_MUTUALLY_EXCLUSIVE Section
Spire_Jeff
Posts: 1,917
Anyone know if there is anyway to use FOR() Loops in the DEFINE_MUTUALLY_EXCLUSIVE section of a module? I am passing an array of touch panels to the module, but I never know how many touch panels are in the array. I need to make some of the buttons mutually exclusive and it would be nice if I could do something like:
DEFINE_MUTUALLY_EXCLUSIVE
FOR(x=1;x<=LENGTH_ARRAY(dvTPS);x++)
{
([dvTPs[x],nUSER_SELECT_BTNS[1]],
[dvTPs[x],nUSER_SELECT_BTNS[2]],
[dvTPs[x],nUSER_SELECT_BTNS[3]],
[dvTPs[x],nUSER_SELECT_BTNS[4]],
[dvTPs[x],nUSER_SELECT_BTNS[5]])
}
I have a feeling that I will just have to turn OFF/ON all buttons accordingly to handle this properly, but it the season of hope, so if anyone has any thoughts or ideas on the situation, I'd appreciate them. I am going to try the FOR loop and see if it will even compile.
Jeff
DEFINE_MUTUALLY_EXCLUSIVE
FOR(x=1;x<=LENGTH_ARRAY(dvTPS);x++)
{
([dvTPs[x],nUSER_SELECT_BTNS[1]],
[dvTPs[x],nUSER_SELECT_BTNS[2]],
[dvTPs[x],nUSER_SELECT_BTNS[3]],
[dvTPs[x],nUSER_SELECT_BTNS[4]],
[dvTPs[x],nUSER_SELECT_BTNS[5]])
}
I have a feeling that I will just have to turn OFF/ON all buttons accordingly to handle this properly, but it the season of hope, so if anyone has any thoughts or ideas on the situation, I'd appreciate them. I am going to try the FOR loop and see if it will even compile.
Jeff
0
Comments
Ok, here it is. This will only work when the mutually exclusive set is contained in an array, but I think this should work. I will edit it if needed after I finish the module that uses this.
Oh, I also did a quick test between using the y variable and just putting LENGTH_ARRAY in the FOR statement. Using an array of 10 buttons, it took an average of 1ms for the call to execute using the y variable and an average of 2ms for it to execute with the LENGTH_ARRAY. Obviously this isn't a big difference, but eventually it could add up to a bigger fraction of a second :P
Jeff
I'm not even opening up my NetLinx, but what if you kept it in mutually exculsive, use the length array outside of the for loop...say in the constants? so # of touch panels = length array then just in your mutually exclusive reference that variable?
Also as small aside, I believe a true mutually exclusive set is a break before make and your original code doesn?t do that (it?s possible for two buttons to be on for a split second). I?m sure it doesn?t matter for your case since it?s TP buttons, however, it were relays it could make a difference.
Good call Joe. I will try to switch it to that. I do tend to hesitate when manipulating arrays that deal with touch panels, because early on I recall having some problems with it functioning properly, but I wouldn't be surprised if it was just my coding that caused the problems
Thanks for the ideas.
Jeff
DEFINE_CALL 'EXCLUSIVE ON' (DEV dvTP,INTEGER nBTNS[],INTEGER nON_INDEX)
{
OFF[dvTP,nBTNS]
ON[dvTP,nBTNS[nON_INDEX]]
}
Works like a champ.
Thanks,
Jeff
I still use it. Seems to work fine. There are other ways to get it done. I suppose if it ever fails me, I'll make the switch.