Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: rrc1962 on May 27, 2016, 05:29:25 PM
-
I'm trying to test some M codes in MDI without much luck. M codes that trigger outputs seem to work fine, but anything to create motion does not work. See code below. I tried all of the code execute functions with no luck. The function is running because last error is updating correctly, just not getting an movement. If I hit run in the editor, it runs fine. If I step through the code it runs fine. It does not work by typing M101 in MDI or by calling M101 in a Gcode file. The file name is m101.mcs. What could be wrong to make it run fine in the editor and fail in MDI and gcode?
function m101()
---------------------------------------------------------------------
-- GoTo Safe Z
---------------------------------------------------------------------
inst = mc.mcGetInstance()
mc.mcCntlSetLastError(inst, 'Move to SafeZ')
local SafeZ = scr.GetProperty('droSafeZ', 'Value')
local CodeLine1 = 'G00 Z' .. SafeZ
mc.mcCntlGcodeExecute(inst, CodeLine1)
--mc.mcCntlMdiExecute(inst, CodeLine1)
--mc.mcCntlGcodeExecuteWait(inst, CodeLine1)
end
if (mc.mcInEditor() == 1) then
m101()
end
-
Just tried using the sim and worked fine using had to add a number as I dont have the dro, try putting a messagebox below it to see what is getting passed to the gcode
function m101()
---------------------------------------------------------------------
-- GoTo Safe Z
---------------------------------------------------------------------
inst = mc.mcGetInstance()
mc.mcCntlSetLastError(inst, 'Move to SafeZ')
local SafeZ = 5 --scr.GetProperty('droSafeZ', 'Value')
local CodeLine1 = 'G00 Z' .. SafeZ
mc.mcCntlGcodeExecute(inst, CodeLine1)
--mc.mcCntlMdiExecute(inst, CodeLine1)
--mc.mcCntlGcodeExecuteWait(inst, CodeLine1)
end
if (mc.mcInEditor() == 1) then
m101()
end
DazTheGas
-
Interesting....
If I remove this...
local EndZ = scr.GetProperty('droEndZ', 'Value')
local CodeLine1 = 'G00 Z' .. EndZ
and just do this...
local CodeLine1 = 'G00 Z0.5'
It works. Yet when I look at what's getting passed to mc.mcCntlGcodeExecute, it is the same. CodeLine1 is the same in both cases.
-
Evidently you can't use a screen element in a M code...
This works...
inst = mc.mcGetInstance()
val = '0.50000'
gCode1 = 'G00 Z' .. val
mc.mcCntlGcodeExecute(inst, gCode1)
This does not...
inst = mc.mcGetInstance()
val = scr.GetProperty('droTest1', 'Value')
gCode1 = 'G00 Z' .. val
mc.mcCntlGcodeExecute(inst, gCode1)
-
Screen elements must not be visible to a normally running M code. The following code works....
inst = mc.mcGetInstance()
val = mc.mcProfileGetString(inst,'PersistentDROs', 'droTest1', '1')
gCode1 = 'G00 Z' .. val
mc.mcCntlGcodeExecute(inst, gCode1)
-
Correct. There is a LUA instance in the screen and a separate instance for the M code macros. The only thing available to both is the mc.* API. scr.* is only available in the screen scripts.