Asked
Resolved Resolved by DJ Sures!

C# Commands To Perform Sequential Actions That Wait To Complete Priors

If we use these two commands back to back (and in either order) the second one executes, but the first does not.

EZBManager.FormMain.SendFormCommand("Auto Position", "AutoPositionAction", "Gorilla"); EZBManager.FormMain.SendFormCommand("Auto Position", "AutoPositionAction", "Bow");

We know we are missing something simple, but how do we issue a SendFormCommand that actually waits for an action to complete, or how can we check to see if the command is complete to build in a delay?

Thanks!


Related Hardware JD Humanoid

ARC Pro

Upgrade to ARC Pro

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.

PRO
Portugal
#1   — Edited

You must use pause between actions. Use a "wait until" perhaps?

PRO
Synthiam
#2   — Edited

Wait until the first action has completed. Remember, ControlCommand does not wait (from this manual page)

User-inserted image

What I recommend doing is talking to the Auto Position directly rather than sending commands. Something like this, and makes sure the action doesn't repeat. Because you can't wait for something that will never end.


    void runActionAndWait(string actionName) {

      var  AutoPosition = (ARC.UCForms.FormAutoPositionerMovement)EZBManager.FormMain.GetControlByNameAllPages("Auto Position");

      if (autoPosition == null)
        throw new Exception("Auto position control doesn't exist");

      var action = autoPosition.GetAutoPosition.Config.Actions.FirstOrDefault( x=> x.Title.Equals(actionName, StringComparison.InvariantCultureIgnoreCase));

      if (action == null)
        throw new Exception($"The action '{actionName}' doesn't exist");

      if (action.Repeats)
        throw new Exception("This repeats and cannot be waited for");

      autoPosition.GetAutoPosition.ExecAction(action.GUID);

      while (autoPosition.GetAutoPosition.IsRunning) {

        System.Threading.Thread.Sleep(100);

        if (IsClosing)
          break;
      }
    }


Alternatively, if you have to specify a timeout because the action repeats, do this...


    void runActionForTime(string actionName, int timeoutMs) {

      var  AutoPosition = (ARC.UCForms.FormAutoPositionerMovement)EZBManager.FormMain.GetControlByNameAllPages("Auto Position");

      if (autoPosition == null)
        throw new Exception("Auto position control doesn't exist");

      var action = autoPosition.GetAutoPosition.Config.Actions.FirstOrDefault( x=> x.Title.Equals(actionName, StringComparison.InvariantCultureIgnoreCase));

      if (action == null)
        throw new Exception($"The action '{actionName}' doesn't exist");

      autoPosition.GetAutoPosition.ExecAction(action.GUID);

      for (int x = 0; x < timeoutMs; x += 100) {

        System.Threading.Thread.Sleep(100);

        if (IsClosing)
          break;
      }
    }


Lastly, you can cover both bases with something like this...


    void runActionForTimeOrStop(string actionName, int timeoutMs) {

      var  AutoPosition = (ARC.UCForms.FormAutoPositionerMovement)EZBManager.FormMain.GetControlByNameAllPages("Auto Position");

        if (autoPosition == null)
        throw new Exception("Auto position control doesn't exist");

      var action = autoPosition.GetAutoPosition.Config.Actions.FirstOrDefault( x=> x.Title.Equals(actionName, StringComparison.InvariantCultureIgnoreCase));

      if (action == null)
        throw new Exception($"The action '{actionName}' doesn't exist");

      autoPosition.GetAutoPosition.ExecAction(action.GUID);

      for (int x = 0; x < timeoutMs; x += 100) {

        System.Threading.Thread.Sleep(100);

        if (IsClosing)
          break;

        if (!autoPosition.GetAutoPosition.IsRunning)
          break;
      }
    }

#3   — Edited

Outstanding, thank you!!

I'll post back when I have this running but this is exactly what we needed!

Got your example code in and running, tried all variants.

It is oddly still doing the same thing with multiple calls to all of the variant runAction  methods you suggested. It will run the second behavior, supporting what you and the documentation say is correct, in that it just won't wait even though the these methods tell it to.

I'm going to tinker around the edges with the delay structures,  because the While...GetAutoPosition.IsRunning test doesn't seem to be doing anything or it is hanging up for some reason.  A few debugs felt like they were stalling in an infinite loop especially in the version that does not use a timer.