Simple Macro issue (I hope)

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Simple Macro issue (I hope)

Postby tomsmith » Wed Jan 19, 2022 2:40 pm

Hi guys, I'm new here and very much new to writing macros, I've done a few for probing on my machine but have a simple problem I can't seem to figure out. I just want to have a macro running in the background to turn on an output if the machine position is above 1500mm and turn it off it they are below, here is what I have so far:

int pistonPort = 1;
int pistonPin = 1;

double Ymachposvariable = exec.GetYmachpos();
if(double Ymachposvariable > 1500)
{
exec.Setoutpin(pistonPort, pistonPin);
}

if(double Ymachposvariable < 1500)
{
exec.Clroutpin(pistonPort, pistonPin);
}
tomsmith
 
Posts: 22
Joined: Wed Jan 19, 2022 2:33 pm

Re: Simple Macro issue (I hope)

Postby ger21 » Wed Jan 19, 2022 5:08 pm

Try this:

Code: Select all
int pistonPort = 1;
int pistonPin = 1;
double Ymachposvariable = exec.GetYmachpos();

if (Ymachposvariable > 1500)
{
exec.Setoutpin(pistonPort, pistonPin);
}
else
{
exec.Clroutpin(pistonPort, pistonPin);
}
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2794
Joined: Sat Sep 03, 2016 2:17 am

Re: Simple Macro issue (I hope)

Postby ger21 » Wed Jan 19, 2022 5:24 pm

Make sure you the for a macroloop you put the code in a loop:

while(loop)
{
//macro here
Thread.Sleep(50);
}
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2794
Joined: Sat Sep 03, 2016 2:17 am

Re: Simple Macro issue (I hope)

Postby tomsmith » Wed Jan 19, 2022 5:46 pm

Thanks Ger, but still no luck, its still not turning on the output trying with the below code:

int pistonPort = 2;
int pistonPin = 1;
double Ymachposvariable = exec.GetYmachpos();

if (Ymachposvariable > 1500)
{
exec.Setoutpin(pistonPort, pistonPin);
}
else
{
exec.Clroutpin(pistonPort, pistonPin);
}





also I tried the following but i'm getting script errors:

while(loop)
{
int pistonPort = 1;
int pistonPin = 1;
double Ymachposvariable = exec.GetYmachpos();

if (Ymachposvariable > 1500)
{
exec.Setoutpin(pistonPort, pistonPin);
}
else
{
exec.Clroutpin(pistonPort, pistonPin);
}

Thread.Sleep(50);
}
tomsmith
 
Posts: 22
Joined: Wed Jan 19, 2022 2:33 pm

Re: Simple Macro issue (I hope)

Postby ger21 » Wed Jan 19, 2022 6:09 pm

How are you running it?
I just tried a modified version, and it worked fine. I saved it as M21777.txt, and configure it as a macroloop. Make sure your not using a pin that's assigned to anything else.
[attachment=0]macroloop.JPG[/attachment]

while(loop)
{
int pistonPort = 1;
int pistonPin = 8;
double Ymachposvariable = exec.GetYmachpos();

if (Ymachposvariable > 50)
{
exec.Setoutpin(pistonPort, pistonPin);
}
else
{
exec.Clroutpin(pistonPort, pistonPin);
}

Thread.Sleep(50);
}
Attachments
macroloop.JPG
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2794
Joined: Sat Sep 03, 2016 2:17 am

Re: Simple Macro issue (I hope)

Postby tomsmith » Wed Jan 19, 2022 10:32 pm

I think the configuration must be my problem, would you be so kind and tell me how I can configure it as a macroloop. thanks again Ger
tomsmith
 
Posts: 22
Joined: Wed Jan 19, 2022 2:33 pm

Re: Simple Macro issue (I hope)

Postby tomsmith » Wed Jan 19, 2022 10:35 pm

Never mind, got it, and it's working perfectly, thanks for all your help Ger
tomsmith
 
Posts: 22
Joined: Wed Jan 19, 2022 2:33 pm

Re: Simple Macro issue (I hope)

Postby tomsmith » Thu Jan 20, 2022 9:42 am

Just one more little issue I am struggling with, I made a mistake and actually need the output to turn on in a certain zone, for example, the output should be only on when between 70 and 80 and off everywhere else, I've tried to modify the code but with no success, any idea?

while(loop)
{
int pistonPort = 1;
int pistonPin = 16;
double Ymachposvariable = exec.GetYmachpos();

if (Ymachposvariable > 80)
{
exec.Setoutpin(pistonPort, pistonPin);
}
or
if (Ymachposvariable < 70)
{
exec.Clroutpin(pistonPort, pistonPin);
}

Thread.Sleep(50);
}
tomsmith
 
Posts: 22
Joined: Wed Jan 19, 2022 2:33 pm

Re: Simple Macro issue (I hope)

Postby ger21 » Thu Jan 20, 2022 1:15 pm

while(loop)
{
int pistonPort = 1;
int pistonPin = 16;
double Ymachposvariable = exec.GetYmachpos();

if (Ymachposvariable > 70 && Ymachposvariable < 80)
{
exec.Setoutpin(pistonPort, pistonPin);
}
else
{
exec.Clroutpin(pistonPort, pistonPin);
}

Thread.Sleep(50);
}
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2794
Joined: Sat Sep 03, 2016 2:17 am

Re: Simple Macro issue (I hope)

Postby tomsmith » Thu Jan 20, 2022 3:29 pm

Works perfectly, thanks Gerry, great help
tomsmith
 
Posts: 22
Joined: Wed Jan 19, 2022 2:33 pm

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 6 guests