Author |
|
GadgetGuy Super User
Joined: June 01 2008 Location: United States
Online Status: Offline Posts: 942
|
Posted: January 23 2009 at 07:55 | IP Logged
|
|
|
I have a macro that tests a device and if it receives a "bad" answer waits 5 seconds and tries again.
To keep from creating an infinite loop I want to use an index counter (I'm currently doing this with a GLOBAL var but since there will be several of these test and retry macros I don't want to proliferate GLOBAL vars).
Can I use a LOCAL or TEMP var for my index? The PH User Manual indicates these vars persist thru subsequent macro calls to daughter macros, and are finally lost when the original macro completes.
But what happens when a macro (recursion) calls itself?
__________________ Ken B - Live every day like it's your last. Eventually, you'll get it right!
|
Back to Top |
|
|
BeachBum Super User
Joined: April 11 2007 Location: United States
Online Status: Offline Posts: 1880
|
Posted: January 23 2009 at 08:37 | IP Logged
|
|
|
If you’re talking about Insteon recovery, Jeff wrote one that is reentrant and reusable using very few Global Variables and is issued at the instance of a device change. Search for “generic SEND_INSTEON”. I have a different version that relies on global variables for each device and executes after the devices have been changed.
__________________ Pete - X10 Oldie
|
Back to Top |
|
|
GadgetGuy Super User
Joined: June 01 2008 Location: United States
Online Status: Offline Posts: 942
|
Posted: January 24 2009 at 07:26 | IP Logged
|
|
|
Pete - Mucho thanks for the code pointer.
In looking it over I had a moment of great epiphany.
I don't know why I was making it so hard. After incrementing my retry loop I then inserted a Wait and then called the same macro (ie, recursion). This meant I could not use a LOCAL or TEMP as they would not persist.
But DUH! It just didn't dawn on me to merely Jump back to the Start of the program after my Wait, thus staying within the macro and allowing me to use a LOCAL var for the loop counter. Your referenced example turned the light on for me.
It also showed me a new way to handle LOCAL vars thru the SET SYSTEM command. I was not aware of that choice and it makes the code a lot easier to read.
So kudos and thanks all around for a very helpful post.
__________________ Ken B - Live every day like it's your last. Eventually, you'll get it right!
|
Back to Top |
|
|