Page 1 of 1

Changing Pulley Selection with a button

PostPosted: Fri Sep 04, 2020 12:34 am
by MattTheNoob
I'm trying to set up buttons to change between my two pulley options and also change the encoder PPR at the same time. (The PPR part is working fine. Dezsoe hooked me up almost 2 years ago... http://cncdrive.com/forum/viewtopic.php?f=4&t=1608 Where does the time go?)

For the pulley, I'm using the setfield for pulley number, but when I press the "apply" button or callbutton(168), the pulley selection goes back to the previous setting. I'm thinking that I need to call "M215 P1" or "M215 P2" from the button macro, but I'm not sure how to call a macro from a macro.

Code: Select all
   AS3.Switchbutton(true, 20055);
   AS3.SetLED(true, 455);
   AS3.Setfield(1,2013); // Sets pulley number to 1

   AS3.Switchbutton(false, 20056); //this turns off the other button that sets the pulley number to 2
   AS3.SetLED(false, 456);

   AS3.Setfield(113, 864); // set new value into field 864
   AS3.Validatefield(864); // Validate
   exec.Callbutton(168); // Apply settings

Re: Changing Pulley Selection with a button

PostPosted: Fri Sep 04, 2020 5:32 am
by dezsoe
Just 2 more lines. First you have to wait for the apply to finish, then call the M215:

Code: Select all
   AS3.Switchbutton(true, 20055);
   AS3.SetLED(true, 455);
   AS3.Setfield(1,2013); // Sets pulley number to 1

   AS3.Switchbutton(false, 20056); //this turns off the other button that sets the pulley number to 2
   AS3.SetLED(false, 456);

   AS3.Setfield(113, 864); // set new value into field 864
   AS3.Validatefield(864); // Validate
   exec.Callbutton(168); // Apply settings

   while (AS3.Getbuttonstate(168)); // Wait for the apply to finish
   exec.Code("M215 P1"); // Change pulley

Re: Changing Pulley Selection with a button

PostPosted: Fri Sep 04, 2020 12:01 pm
by MattTheNoob
Ah, Exec.code! I didn't know that trick. Thanks!

So let me ask this... if I do the exec.code "M215 P1" do I even need to do the "as3.setfield (1,2013)" part to change the pulley number to 1?

Re: Changing Pulley Selection with a button

PostPosted: Fri Sep 04, 2020 12:26 pm
by dezsoe
No, M215 will change it.

Re: Changing Pulley Selection with a button

PostPosted: Fri Sep 04, 2020 4:35 pm
by MattTheNoob
That works perfectly! For anyone else trying this, here's the final form of the macros to change pulleys and spindle PPR with push buttons.


Change to Pulley 1
Code: Select all
//
//   M20055 is the Macro for setting the High spindle pulley
//

   AS3.Switchbutton(true, 20055);
   AS3.SetLED(true, 455);

   AS3.Switchbutton(false, 20056);
   AS3.SetLED(false, 456);

   AS3.Setfield(113, 864); // set new PPR value into field 864
   AS3.Validatefield(864); // Validate

   exec.Callbutton(168); // Apply settings
   while (AS3.Getbuttonstate(168)); // Wait for the apply to finish
   exec.Code("M215 P1"); // Change pulley


Change to pulley 2
Code: Select all
//
//   M20056 is the Macro for setting the LOW spindle pulley
//

   AS3.Switchbutton(true, 20056);
   AS3.SetLED(true, 456);

   AS3.Switchbutton(false, 20055);
   AS3.SetLED(false, 455);

   AS3.Setfield(607, 864); // set new PPR value into field 864
   AS3.Validatefield(864); // Validate

   exec.Callbutton(168); // Apply settings
   while (AS3.Getbuttonstate(168)); // Wait for the apply to finish
   exec.Code("M215 P2"); // Change pulley