The unwanted movements are probably caused by changing the settings during a cycle run. If you cannot avoid changing the settings then here are some advices:
- You don't need apply and save: save will first apply.
- Save the current cycle start state then stop cycle if it's running. Do your changes, apply or save the settings then restart cycle if it was running. (The macro can be called from MDI and from a g-code file, so you have to know if you need to restart.)
- Code: Select all
wasCycleRunning = exec.GetLED(54);
if (wasCycleRunning)
{
exec.Stop();
while (exec.IsMoving()) ;
exec.Codesync(""); // Clear Ismacrostopped
while (exec.IsMoving()) ;
}
// ...code...
if (wasCycleRunning) exec.Callbutton(128); // Cycle start if it was started
- exec.Wait is not a good way to wait for apply/save to finish. When you call the Callbutton then check the state of the button and wait for it to turn off.
- Code: Select all
exec.Callbutton(btnSaveSettings);
while (AS3.Getbuttonstate(btnSaveSettings));
- As I wrote in the other thread: use exec.Codesync instead of exec.Code. (Or exec.Codelist if you have more g-codes to execute.) Also, after every call you should check for exec.Ismacrostopped() to handle a stop (and reset) condition. (Reset also calls stop.) The easy way is to move your whole macro to a bool function after #Events and return true only if everything is finished. Then you can decide in one place to continue the execution or abort the whole macro and also the cycle.