331
Mach4 General Discussion / Re: Help defining outputs in LUA script for tool change
« on: January 21, 2019, 04:26:12 PM »
TTalma,
The code you supplied was almost there; make the following changes and it should work fine.
You have to assign your "Blow Off" output to an Output# in the Mach4 Configuration.
Once you assign that to an output you can then use the following code in a macro to get the handle of the output to change it's state.
function m6()
------ Turn on Blow off ------
local BlowOff = mc.mcSignalGetHandle (inst, mc.mcOSIG_OUTPUT#) --Use the Output # you assigned the Blow Off in Mach4 configuration.
mc.mcSignalSetState(BlowOff , 1)
------ Move to current tool change position ------
local GCode = ""
GCode = GCode .. "G00 G91 G53 Z-1.0\n"
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ Turn off Blow off ------
mc.mcSignalSetState(BlowOff , 0)
end
if (mc.mcInEditor() == 1) then
m6()
end
To answer your question about "inst". Here is a post that Craig made this past week that sums it up nicely.
"It is possible and may become fact one day, that multiple instances of Mach can run at once. This was allowed for
in the original 'design' of Mach. As a consequence there are many instructions in Mach which need to be applied
to a particular instance of Mach. As it turns out Mach as currently deployed allows only one instance, usually instance
'0' and thus if you used the variable 'inst' in any part of Mach it will probably work. The safe way is to ensure that
the proper and current instance is used....ergo mc.mcGetInstance() is used within each scope."
The code you supplied was almost there; make the following changes and it should work fine.
You have to assign your "Blow Off" output to an Output# in the Mach4 Configuration.
Once you assign that to an output you can then use the following code in a macro to get the handle of the output to change it's state.
function m6()
------ Turn on Blow off ------
local BlowOff = mc.mcSignalGetHandle (inst, mc.mcOSIG_OUTPUT#) --Use the Output # you assigned the Blow Off in Mach4 configuration.
mc.mcSignalSetState(BlowOff , 1)
------ Move to current tool change position ------
local GCode = ""
GCode = GCode .. "G00 G91 G53 Z-1.0\n"
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ Turn off Blow off ------
mc.mcSignalSetState(BlowOff , 0)
end
if (mc.mcInEditor() == 1) then
m6()
end
To answer your question about "inst". Here is a post that Craig made this past week that sums it up nicely.
"It is possible and may become fact one day, that multiple instances of Mach can run at once. This was allowed for
in the original 'design' of Mach. As a consequence there are many instructions in Mach which need to be applied
to a particular instance of Mach. As it turns out Mach as currently deployed allows only one instance, usually instance
'0' and thus if you used the variable 'inst' in any part of Mach it will probably work. The safe way is to ensure that
the proper and current instance is used....ergo mc.mcGetInstance() is used within each scope."