DEFINE_MUTUALLY_EXCLUSIVE Section
Spire_Jeff
Formerly Caffeinated Programmer
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
Comments
-
Well, as I expected, the FOR loop seems to throw the compiler into a tizzy. Hmm, maybe I can write a little function to do this.... I will post it if I come up with something interesting.
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.DEFINE_CALL 'EXCLUSIVE ON' (DEV dvTP,INTEGER nBTNS[],INTEGER nON_INDEX) { STACK_VAR INTEGER x; STACK_VAR INTEGER y; y = LENGTH_ARRAY(nBTNS); FOR(x=1;x<=y;x++) { IF(x == nON_INDEX) ON[dvTP,nBTNS[x]] ELSE OFF[dvTP,nBTNS[x]] }; }
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 -
No where near NetLinx
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? -
In Programmer II the instructor told us not to use Mutually Exclusive for feedback purposes. Is he wrong?
-
I?ve still got the towel handy from my last post in case I need to use it again but you should just be able to do this.Spire_Jeff wrote:DEFINE_CALL 'EXCLUSIVE ON' (DEV dvTP,INTEGER nBTNS[],INTEGER nON_INDEX) { STACK_VAR INTEGER x; STACK_VAR INTEGER y; y = LENGTH_ARRAY(nBTNS); FOR(x=1;x<=y;x++) { IF(x == nON_INDEX) ON[dvTP,nBTNS[x]] ELSE OFF[dvTP,nBTNS[x]] }; }DEFINE_CALL 'EXCLUSIVE ON' (DEV dvTP,INTEGER nBTNS[],INTEGER nON_INDEX) { OFF[dvTP,nBTNS] ON[dvTP,nBTNS[nON_INDEX]] }
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. -
I was told the same but I don't recall the reasoning behind it.TonyAngelo wrote:In Programmer II the instructor told us not to use Mutually Exclusive for feedback purposes. Is he wrong? -
As I recall, the reason for not using the Mutually Exclusive section was related to relays controlling electrical devices, but it has been a while. I can tell you that the DEFINE_MUTUALLY_EXCLUSIVE section has not caused any problems for me, but I only use it for button feedback. The only thing is that when dealing with an array of touch panels, you have to use the individual touch panels, or you will have problems.
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 -
Joe,
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 -
Glad to hear it.
-
TonyAngelo wrote:In Programmer II the instructor told us not to use Mutually Exclusive for feedback purposes. Is he wrong?
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. -
The problem with DEFINE_MUTALLY_EXCLUSIVE is it causes some weird effects due to the rather murky interaction between output channels and feedback channels, which aren't necessarily the same thing, especially with relay outputs. The workaround is use the keyword TOTAL_OFF instead of just OFF on the channel, or your feedback may not reflect the actual output. As far as I know, only hardware channels like relays are really affected, but it's just arcane enough that I'm not certain.
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums
