Page 1 of 1

Add an output pin to M215 for relay

PostPosted: Wed Apr 28, 2021 9:45 pm
by Tom Jenn
I need to add an output port and pin to M215 P2 to drive a relay to change the range on my VFD.
M215 P Sets the pulley number, But it isn't in the Macro list (UCCNC\Profiles\MACRO_Default).
Please, Where can I find it, and can it be edited to do this?

Re: Add an output pin to M215 for relay

PostPosted: Wed Apr 28, 2021 11:10 pm
by dezsoe
Not all M-codes are saved as macros, there are some that are programmed into UCCNC and this is one of them. You have to write a macroloop to check for the Pulleynumber field (2013) and set an output as you need.

Re: Add an output pin to M215 for relay

PostPosted: Thu Apr 29, 2021 4:46 pm
by Tom Jenn
Thanks for that, dezsoe.
At this moment I have no idea how to do that, any help would be appreciated.
What is field (2013)?
Tom.

Re: Add an output pin to M215 for relay

PostPosted: Thu Apr 29, 2021 6:44 pm
by dezsoe
The current pulley number is stored in field #2013, so you have to check this value in a macroloop and if it is 2 then set the output else clear the output. Below is a macro for this. Save it to the Profiles\Macro_yourprofilename folder as Mxxxx where xxxx is any number that is not used. (E.g. 20000, you can see the profile name on the main screen.) Go to General settings, press Config macroloops and set the number you used to an empty row. Tick Autorun, click Run, click Save settings. Don't forget to edit outputPort and outputPin, I tested with port #3 pin #17.

Code: Select all
// ================================================================================================
// Check pulley, set output when pulley is 2 (M215 P2)
// ================================================================================================

const int outputPort = 3;
const int outputPin = 17;

bool isPulley2 = (AS3.Getfieldint(2013) == 2);

if (firstRun)
{
  // Force output to be set/clear on startup
  lastIsPulley2 = !isPulley2;
  firstRun = false;
}

if (isPulley2 != lastIsPulley2)
{
  // isPulley2 changed
  if (isPulley2)
    exec.Setoutpin(outputPort, outputPin);
  else
    exec.Clroutpin(outputPort, outputPin);
  lastIsPulley2 = isPulley2;
}

// ================================================================================================

#Events

// ================================================================================================

bool firstRun = true;
bool lastIsPulley2 = false;

// ================================================================================================

Re: Add an output pin to M215 for relay

PostPosted: Fri Apr 30, 2021 9:47 pm
by Tom Jenn
Hi dezsoe,
That is exactly what I wanted, it works well.
Thank you.
Tom.