Sub Program Call Value

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

Sub Program Call Value

Postby MrCactus1 » Sun Oct 30, 2022 2:03 pm

When calling a subprogram with M98P2000L#102, Does the "P" value get stored somewhere that I can read with a macro statement? I noticed in one of the posted programs here that it had "//exec.Code("#4114=" + AS3.Getfield(869) ); // Program Number {O CODE}", but field 869 in the manual states that this is used for "Setspindlespeed".
I would like to trigger certain events when the program runs across say O2000. One example would be to trigger an M01 if the button I have set for this is active, but without having to place the actual M01 in the program.
MrCactus1
 
Posts: 10
Joined: Thu Oct 27, 2022 9:04 pm

Re: Sub Program Call Value

Postby dezsoe » Mon Oct 31, 2022 1:10 am

That remark was bad. Field 869 is the set spindle speed as you read in the manual. You have to place the M1 into the g-code, you cannot watch for an M98. M1 is already optional, so you can place a switch on the screen with buttonnumber 561 to toggle the optional stop.
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Sub Program Call Value

Postby fsli » Mon Oct 31, 2022 11:48 am

I'm not sure this will give you what you're wanting, but you can pass an argument to the macro that is called from the subprogram. For example:

M98P2000
M30
O2000
M9991 {P2000}
M99

... then, inside the M9991 macro, the Pvar parameter value will be set to 2000:

// M9991.txt
if (Pvar != null)
Console.WriteLine("Pvar is: {0}", Pvar.ToString());
Frank
fsli
 
Posts: 97
Joined: Mon Jul 11, 2022 12:36 am

Re: Sub Program Call Value

Postby MrCactus1 » Mon Oct 31, 2022 7:48 pm

So I have found a way sort of to do this.
In a macro loop program I have the following:

string linetext = exec.Getcurrgcodelinetext();
string a = "G54";
string b = "G55";
string c = "G56";
string d = "G57";
string e = "G58";
string f = "G59";

if ((linetext == a) || (linetext == b) || (linetext == c) || (linetext == d) || (linetext == e) || (linetext == f)){
exec.Code("M1");

It will stop when it sees G54. But now it will not stop when G55 is called.
MrCactus1
 
Posts: 10
Joined: Thu Oct 27, 2022 9:04 pm

Re: Sub Program Call Value

Postby dezsoe » Mon Oct 31, 2022 8:05 pm

The macroloop runs 20 times per second, many lines may be executed between your line check, so it will not work. And the most important: never execute any code from macroloop or plugin while cycle is started.
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Sub Program Call Value

Postby fsli » Mon Oct 31, 2022 11:11 pm

This is an (I believe) unsupported and (I believe) undocumented trick which might be a starting point for you, or might create havoc. :o

The macro will execute the M1 only when it was called from the O2001 subroutine.

//M9991.txt
string calledRoutine = exec.Getgcodelinetext(exec.Substack[exec.Substack.Count - 1].substartID - 2);
Console.WriteLine(calledRoutine);

if (calledRoutine.Equals("O2001"))
exec.Code("M1");

G Code sample:
M98P2000
M30
O2000
M9991
M98P2001
M99
O2001
M9991
M99
Frank
fsli
 
Posts: 97
Joined: Mon Jul 11, 2022 12:36 am

Re: Sub Program Call Value

Postby MrCactus1 » Fri Nov 04, 2022 12:27 am

Thanks for the suggestion. But it will not run. I must be missing something here.
MrCactus1
 
Posts: 10
Joined: Thu Oct 27, 2022 9:04 pm

Re: Sub Program Call Value

Postby fsli » Fri Nov 04, 2022 11:09 am

MrCactus1 wrote:Thanks for the suggestion. But it will not run. I must be missing something here.


Does "it will not run" mean it doesn't compile, or it compiles but doesn't produce the expected result?

If it compiles, and you have the Console plugin enabled, do you see any output there?

Did you modify any part of the sample G Code, or the macro?
Frank
fsli
 
Posts: 97
Joined: Mon Jul 11, 2022 12:36 am

Re: Sub Program Call Value

Postby MrCactus1 » Fri Nov 04, 2022 12:47 pm

It does not compile, keeps throwing an error - CS1002 | in line: 14 | error text: ; expected
This is for the M9991 section.
MrCactus1
 
Posts: 10
Joined: Thu Oct 27, 2022 9:04 pm

Re: Sub Program Call Value

Postby fsli » Sat Nov 05, 2022 12:18 am

MrCactus1 wrote:It does not compile, keeps throwing an error - CS1002 | in line: 14 | error text: ; expected


If there's nothing else in your macro file, then line 14 is the exec.Code statement, so I'd have to guess you're missing a semicolon at the end.

However, I've been playing with this some more, and the results aren't consistent. I had three sample g code files that worked, then I stripped out some lines thinking it would work every time, but now I see that's not the case. So, sorry for the unfounded optimism. My interpretation of the purpose of startId doesn't appear to have been correct.
Frank
fsli
 
Posts: 97
Joined: Mon Jul 11, 2022 12:36 am

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 17 guests