Hello Guest it is May 10, 2021, 09:02:43 PM

Author Topic: M Codes in MDI  (Read 1575 times)

0 Members and 1 Guest are viewing this topic.

M Codes in MDI
« 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?


Code: [Select]
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

Offline DazTheGas

*
  •  753 753
  • DazTheGas
    • View Profile
Re: M Codes in MDI
« Reply #1 on: May 27, 2016, 05:47:01 PM »
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

Code: [Select]
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
Theres always time for a choccy biccy
Re: M Codes in MDI
« Reply #2 on: May 27, 2016, 07:13:54 PM »
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.
« Last Edit: May 27, 2016, 07:19:28 PM by rrc1962 »
Re: M Codes in MDI
« Reply #3 on: May 27, 2016, 09:49:06 PM »
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)
Re: M Codes in MDI
« Reply #4 on: May 27, 2016, 10:01:09 PM »
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)

Offline smurph

*
  • *
  •  1,400 1,400
  • "That there... that's an RV."
    • View Profile
Re: M Codes in MDI
« Reply #5 on: May 27, 2016, 11:01:43 PM »
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.