Hello Guest it is March 28, 2024, 05:24:15 AM

Author Topic: How to pass parameters to a User Macro in the MDI or G-code line  (Read 6948 times)

0 Members and 1 Guest are viewing this topic.

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
How to pass parameters to a User Macro in the MDI or G-code line
« on: December 01, 2014, 11:30:24 PM »
Ok, here is a working example for passing parameter(s) to a User M-Code!!

Thanks goes out to Steve Murphy for the correct way to do this.

You can call a “USER” macro any number you want (not the OEM numbers).
For example “m700” or maybe “m55633” whatever in your MDI or G-code line.
In the G-Code that you run, there are 4 “Local Var letters” that you cannot run in the tap file, (but you could fill them by standard pound var value assignment).
Those tap file letters are: G, M, N and O

NOTE: You can pass ZERO or ONE parameter to "User Macros", in this example that ONE parameter
is a handle called: "hVars" this handle is to the local pound vars A-Z
the ONE parameter is this "hVars"
so, if you had: m103 R500  that your code would turn on the spindle CW and you would parse the R parameter for what to set the spindle speed to....
the hVars (local pound vars) live on the stack only.

(both the m700 macro, and the MCode Parameter Test.tap are posted here.

Here is the working m700() macro:
----------------------------------------------------
--Brought to you by the: "Mach4^2 Development Team"!!
--Team members both Frick, and Frack!!
----------------------------------------------------
function m700(hVars)
   local macroname = "m700"
   local rc
   local inst = mc.mcGetInstance() -- Get the current instance   
   local nilPoundVar = mc.mcCntlGetPoundVar(inst,0)   
   local message = ""
    if hVars ~= nil then
          rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_A)
          message = message .. "A" .. ":" .. tostring(rc) .. ", "
          rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_B)
          message = message .. "B" .. ":" .. tostring(rc) .. ", "
          rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_C)
        message = message .. "C" .. ":" .. tostring(rc) .. ", "
          rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_D)
          message = message .. "D" .. ":" .. tostring(rc) .. ", "
          rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_E)
      message = message .. "E" .. ":" .. tostring(rc) .. ", "
      rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_F)
      message = message .. "F" .. ":" .. tostring(rc) .. ", "
      --[[
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_G)
          message = message .. "G" .. ":" .. tostring(rc) .. ", "
      --]]
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_H)
          message = message .. "H" .. ":" .. tostring(rc) .. ", "
          rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_I)
          message = message .. "I" .. ":" .. tostring(rc) .. ", "
          rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_J)
        message = message .. "J" .. ":" .. tostring(rc) .. ", "
          rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_K)
          message = message .. "K" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_L)
        message = message .. "L" .. ":" .. tostring(rc) .. ", "
      --[[
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_M)
          message = message .. "M" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_N)
        message = message .. "N" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_O)
        message = message .. "O" .. ":" .. tostring(rc) .. ", "
      --]]
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_P)
        message = message .. "P" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_Q)
        message = message .. "Q" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_R)
        message = message .. "R" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_S)
        message = message .. "S" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_T)
        message = message .. "T" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_U)
        message = message .. "U" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_V)
        message = message .. "V" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_W)
        message = message .. "W" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_X)
        message = message .. "X" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_Y)
        message = message .. "Y" .. ":" .. tostring(rc) .. ", "
        rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_Z)
        message = message .. "Z" .. ":" .. tostring(rc)

      wx.wxMessageBox(message)
   end
end

if (mc.mcInEditor() == 1) then
    m700(0)
end

Here is the MCode Parameter Test.tap

(Mcode Parameter Test)
G01 F50
m700 A1 B2 C3 D4 E5 F6 H7 I8 J9 K10 L11 P12 Q13 R14 S15 T16 U17 V18 W19 X20 Y21 Z22
X2
M30

Scott
fun times
Re: How to pass parameters to a User Macro in the MDI or G-code line
« Reply #1 on: February 14, 2017, 09:43:01 PM »
Is this for Mach3 or Mach4?

thanks
Re: How to pass parameters to a User Macro in the MDI or G-code line
« Reply #2 on: February 14, 2017, 10:01:29 PM »
Found my answer..  No only Mach4

For Mach3 see:

http://www.machsupport.com/forum/index.php/topic,28451.msg199825.html#msg199825

Read the replies following it because there are a few gotcha's.