Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: wwenter on July 24, 2017, 08:56:33 AM
-
Hello All
Is there a macro that has been written that would allow me to enter a m41- m46 to change my lathe spindle range in a g code program for mach4
Thanks
-
Just read your post.
The macro below does this job for me.
I have defined the spindle range (6 gears) in solidcam and the post pocessor call the macro on tool change.
M101 P <Range>
Hope that helps.
function M101(hVars)
local inst = mc.mcGetInstance()
local CurrentSpindleRange = mc.mcSpindleGetCurrentRange(inst)
local NextSpindleRange = mc.mcCntlGetLocalVar(inst, hVars, mc.SV_P)
mc.mcCntlSetLastError(inst, "Sets spindle range to " ..NextSpindleRange)
if CurrentSpindleRange ~= NextSpindleRange then
wx.wxMessageBox("Change Gear to " ..NextSpindleRange, "Gear box")
rc = mc.mcSpindleSetRange(inst, NextSpindleRange)
end
end
if (mc.mcInEditor() == 1) then
M101()
end
-
Hi,
Can you explain me better please?
I have to do something similar too.
I do an example:
range 1 (from 0 to 500 rpm)
range 2 (from 0 to 1000 rpm)
range 3 (from 0 to 1500 rpm)
how should i do?
thank you!
-
A lot of machines use M40 and up to set the range. For example, M40, M41, and M42 for a three range spindle. All of those M code macro script would be implemented like GerdS example with the exception of no input parameter. The range would be hard coded.
Steve
-
I'm curious how the "P" Value is read. I didn't know you could add a "P" value to a macro line.
The code that GerdS posted doesn't do anything when I test it. I'm just running the sim on my laptop.
-
Okay,
I noticed that GerdS had the "M" capitalized in the macro. I made it lower cased and it works now.
Still, What does the P Value do in macros, it can be read by the (hVars) on a macro line?
What other things do people use this for?
-
local NextSpindleRange = mc.mcCntlGetLocalVar(inst, hVars, mc.SV_P)
That line pulls the P word from the G code line. It will be hard to debug in the editor since you can't really execute a G code line. There are also these related functions available:
flag, rc = mc.mcCntlGetLocalVarFlag(number inst, number hVars, number varNumber) -- This one tels you if the G code word was set on the G code line. e.g. "M101 P1"
local flag
flag, rc = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_P) -- flag would equal 1 because P1 was specified on the G code line.
flag, rc = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_Q) -- flag would equal 0 because Q was specified on the G code line.
comment, rc = mc.mcCntlGetLocalComment(number inst, number hVars) -- retrieve the comment on the G code line that contains the M code.
As I said earlier, it is hard to debug these things because no G code line has been executed when debugging in the script editor. So I put in a little helper API function that will simulate it. :)
hVars, rc = mc.mcCntlCreateLocalVars(number inst, string gCodeLine)
It would be used in the function call stub like this:
if (mc.mcInEditor() == 1) then
-- The function call stub is only ever executed when in the editor debugging, so it is safe to leave this in for testing.
local inst = mc.mcGetInstance()
local hVars, rc
hVars, rc = mc.mcCntlCreateLocalVars(number inst, string gCodeLine)
M101(hVars)
end
There are caveats to passung G code words to M codes. One is you can't use the M word as a variable. You can use a word more than once. And finally, the M code that takes variables has to be the only thing on the line.
Steve