Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: BR549 on November 28, 2014, 11:02:59 PM

Title: Mcodes ??
Post by: BR549 on November 28, 2014, 11:02:59 PM
Has anyone given any thought as to what AUX Mcodes need to be created ?  Standardizing the Mcode woul dmake POST creation a lot easier rather than having to create many different post ofr many different Mcode definitions.

I have looked at several major players in the CNC control world  and there ARE some standards as far as standards go(;-)



Just a thought, (;-) TP
Title: Re: Mcodes ??
Post by: BR549 on November 28, 2014, 11:12:48 PM
When creating a Mcode is it possible in LUA to have outside parameter calls like we had in Mach3 ???

M102 Pxx Qxx Rxx


(;-) TP
Title: Re: Mcodes ??
Post by: MachMotion Development Team on December 01, 2014, 10:17:28 AM
This is a example of how to read parameters in a Mcode for Mach4.  You can use any of the parameters in this list.

-----------------------------------------------------------------------------
-- Machine Type: Standard Mill Control
-- Author: MachMotion Development Team
-- Created: 09/24/2013
-- Modified by: MachMotion Development Team
-- Modified on: 01/10/2014
-- Description: Example: Reading Variables into MCodes
-- Copyright: © 2013-2014 Edge Solutions LLC All Rights Reserved
-----------------------------------------------------------------------------

function m700(hVars)
   local macroname = "m700"
   local a,b,c,rc
   local inst = mc.mcGetInstance() -- Get the current instance

   local nilPoundVar = mc.mcCntlGetPoundVar(inst,0)
   
   local message = ""
   if hVars ~= nil then
      
        local ParameterLetterArray = {"A", "B", "C", "D", "E", "F", "H", "I", "J", "K", "L", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
        local ParameterNumberArray = {mc.VAR_A, mc.VAR_B, mc.VAR_C, mc.VAR_D, mc.VAR_E, mc.VAR_F, mc.VAR_H, mc.VAR_I, mc.VAR_J, mc.VAR_K, mc.VAR_L, mc.VAR_P, mc.VAR_Q, mc.VAR_R, mc.VAR_S, mc.VAR_T, mc.VAR_U, mc.VAR_V, mc.VAR_W, mc.VAR_X, mc.VAR_Y, mc.VAR_Z}
        for i = mc.VAR_A, #ParameterNumberArray do
         rc = mc.mcCntlGetLocalVar(inst, hVars, ParameterNumberArray)
         message = message .. "#" .. ParameterLetterArray .. ":" .. tostring(rc) .. ", "
      end
      wx.wxMessageBox(message)
   end
   return nil, true, macroname .. " Ran Successfully"
end

if (mc.mcInEditor() == 1) then
    m700()
end
Title: Re: Mcodes ??
Post by: Ya-Nvr-No on December 01, 2014, 10:51:17 AM
-----------------------------------------------------------------------------
-- Machine Type: Standard Mill Control
-- Author: MachMotion Development Team
-- Created: 09/24/2013
-- Modified by: MachMotion Development Team
-- Modified on: 01/10/2014
-- Description: Example: Reading Variables into MCodes
-- Copyright: © 2013-2014 Edge Solutions LLC All Rights Reserved

This is what you can do with a "Development Team" and a Year or more head start,   :o
Cool, thanks Andrew and Team
I always like to learn something new.  8)

Title: Re: Mcodes ??
Post by: BR549 on December 01, 2014, 10:53:37 AM
OK I am assuming that it works like

M700 A1.5 B2.5

And that the Vars's should print out on the message bar ??

Are the ABC,etc the same as #vars in Gcode ??

Please explain how it is to work.  I ran it but did not get as expected.

(;-)
Title: Re: Mcodes ??
Post by: MachMotion Development Team on December 01, 2014, 10:57:05 AM
M700 A1.5 B2.5

That should work fine... I will post the mcodes so you can download and test.
Title: Re: Mcodes ??
Post by: MachMotion Development Team on December 01, 2014, 10:59:07 AM
Attached is the M700 mcode. Example: M700 A2 B3
Title: Re: Mcodes ??
Post by: MachMotion Development Team on December 01, 2014, 11:02:46 AM
This is what you should see in the test.  All the rest of the Vars are nil and thats why they display the odd number.  If you want to see if a var is nil compare it to: local nilPoundVar = mc.mcCntlGetPoundVar(inst,0).  If its nil it will = nilPoundVar.
Title: Re: Mcodes ??
Post by: BR549 on December 01, 2014, 11:03:32 AM
OK ARe the abc,etc used in the Macro array the SAME as the Gcode #var abc. If so there is a problem.

(;-) TP
Title: Re: Mcodes ??
Post by: BR549 on December 01, 2014, 11:09:37 AM
I put this in the MDI  press cycle start and I get NOTHING it appears to run but NO messageBox

M700 A111 B222

(;-) TP
Title: Re: Mcodes ??
Post by: MachMotion Development Team on December 01, 2014, 11:18:17 AM
I don't know what to say..

It works fine for me, but I'm running build 2129.   What build are you running?

I think any build 2114 or newer should work fine.
Title: Re: Mcodes ??
Post by: Ya-Nvr-No on December 01, 2014, 11:33:19 AM
Seems to quit right here at the X

One thing to take note of if you create an mcode you have to restart mach4 to get it to work, as it has to be compiled with the other mcodes on starting.

We are missing something from the load script I would have to assume. As something is not initialized
Title: Re: Mcodes ??
Post by: BR549 on December 01, 2014, 11:35:27 AM
I am running 2128 .

(;-0 TP
Title: Re: Mcodes ??
Post by: BR549 on December 01, 2014, 11:41:06 AM
OK I will leave that for yall to sort out.

BUT My question remains does the M700 macro with parameters have ANYTHING to do with the Gcode G65 local  #vars A-Z ??

(;-) TP
Title: Re: Mcodes ??
Post by: poppabear on December 01, 2014, 12:46:12 PM
just as a side note,
the macro is just using tables and a for loop that the function passes parameters to.
Craig, the DSC module uses this very kind of thing (and your FC module as well).

Terry:
this is a good resource if you want to learn about lua.
http://lua-users.org/wiki/TutorialDirectory

Scott
Title: Re: Mcodes ??
Post by: BR549 on December 01, 2014, 12:58:07 PM
HIYA Scott I already have that in a HOTKEY to the site(;-).

My question on the Array variables is to clear up IF it is using the G65 local #var in ANY WAY. In the code I see a reference where the GETVAR() call is used.

REMEMEBER that the G65 #vars(1-26,A-Z) are local ONLY to the G65 Macro call and are not to be used any where else. IF you allow the Mcodes to reference them we are in trouble houston.

(;-) Just a thought, (;-)TP
Title: Re: Mcodes ??
Post by: poppabear on December 01, 2014, 01:59:58 PM
Hey Terry,

the:    mc.VAR_A to mc.VAR_Z  are from the Mach4API.h
and that is how you get to those variables via mcLua.

Craig and I, did a Pound Var doc a while back (see tool box).
But the findings (at that time), where some where broken, or
didn't do what you thought... etc..  (there is a early M4 thread about
it here somewhere). At any rate, at that time, those issues where on
the "to fix" list... 
I personally have not gone back and checked them,
since then.... mostly, because I use CAM to do my G code programming,
so really don't use pound vars much but for custom macros.

Craig, and/or Andy may have more recent information on them in this regard.

Scott
Title: Re: Mcodes ??
Post by: poppabear on December 01, 2014, 11:05:11 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
Title: Re: Mcodes ??
Post by: dude1 on December 01, 2014, 11:25:04 PM
good work second Development Team
Title: Re: Mcodes ??
Post by: poppabear on December 01, 2014, 11:28:42 PM
thats, Squared..........  (^2).........  :)

Also, note that Frack will be showing how to take those passed parameters and put them into global vars, and/or registers for other stuff.

Scott
Title: Re: Mcodes ??
Post by: dude1 on December 01, 2014, 11:33:52 PM
you will get A squire scale pay rise soon Frack only

something iI just noticed M codes start with a m not a M
Title: Re: Mcodes ??
Post by: Ya-Nvr-No on December 02, 2014, 12:35:24 AM
Works great, I called it m701
Frack too funny  ;D

Code: [Select]
----------------------------------------------------
--Brought to you by the: "Mach4^2 Development Team"!!
--Team members both Frick, and Frack!!
----------------------------------------------------
function m701(hVars)
   local macroname = "m701"
   local aa,bb,cc,dd,ee,ff,hh,ii,jj,kk,ll,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz = 0;

   local inst = mc.mcGetInstance() -- Get the current instance    
   local nilPoundVar = mc.mcCntlGetPoundVar(inst,0)  

    if hVars ~= nil then
        aa = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_A)
    mc.mcCntlSetPoundVar(inst, 1, aa);
        bb = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_B)
    mc.mcCntlSetPoundVar(inst, 2, bb);
        cc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_C)
    mc.mcCntlSetPoundVar(inst, 3, cc);
        dd = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_D)
    mc.mcCntlSetPoundVar(inst, 7, dd);
        ee = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_E)
    mc.mcCntlSetPoundVar(inst, 8, ee);
        ff = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_F)
    mc.mcCntlSetPoundVar(inst, 9, ff);
        hh = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_H)
    mc.mcCntlSetPoundVar(inst, 11, hh);
        ii = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_I)
    mc.mcCntlSetPoundVar(inst, 4, ii);
        jj = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_J)
    mc.mcCntlSetPoundVar(inst, 5, jj);
        kk = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_K)
    mc.mcCntlSetPoundVar(inst, 6, kk);
        ll = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_L)
    mc.mcCntlSetPoundVar(inst, 12, ll);
        pp = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_P)
    mc.mcCntlSetPoundVar(inst, 16, pp);
        qq = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_Q)
    mc.mcCntlSetPoundVar(inst, 17, qq);
        rr = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_R)
    mc.mcCntlSetPoundVar(inst, 18, rr);
        ss = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_S)
    mc.mcCntlSetPoundVar(inst, 19, ss);
        tt = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_T)
    mc.mcCntlSetPoundVar(inst, 20, tt);
        uu = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_U)
    mc.mcCntlSetPoundVar(inst, 21, uu);
        vv = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_V)
    mc.mcCntlSetPoundVar(inst, 22, vv);
        ww = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_W)
    mc.mcCntlSetPoundVar(inst, 23, ww);
        xx = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_X)
    mc.mcCntlSetPoundVar(inst, 24, xx);
        yy = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_Y)
    mc.mcCntlSetPoundVar(inst, 25, yy);
        zz = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_Z)
    mc.mcCntlSetPoundVar(inst, 26, zz);

    --mc.mcCntlSetPoundVar(inst, 13, mm);
    --mc.mcCntlSetPoundVar(inst, 14, nn);
    --mc.mcCntlSetPoundVar(inst, 15, oo);
   end
end

if (mc.mcInEditor() == 1) then
    m701(0)
end
Title: Re: Mcodes ??
Post by: BR549 on December 02, 2014, 12:41:21 AM
Question again.  Are these Macro Parameters M700 A-Z  the SAME as the Local vars A-Z used in the G65 macro call ?

If I set a Macro M700 A1.1 B2.2  are those values going to show up if I call a G65 A 0r B or queary #1 or #2 for its value.

I cannot test here as that it seems G65 is a licensed function ????? Never saw that before.

(;-) TP
Title: Re: Mcodes ??
Post by: Ya-Nvr-No on December 02, 2014, 08:23:33 AM
Added a checkval function to Fricks code
shows how to use a function to cut down on repetitive routines/code and pass back the checked value for validity.


Code: [Select]
----------------------------------------------------
--Brought to you by the: "Mach4^2 Development Team"!!
--Team members both Frick, and Frack!!
----------------------------------------------------
function checkval(rc)
if (rc <= 1e-009 or rc >= 1e009) then
rc2 = 0;
else
                rc2 = rc;
        end
return rc2
end

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)
checkval(rc)
message = message .. "A" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_B)
checkval(rc)
message = message .. "B" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_C)
checkval(rc)
message = message .. "C" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_D)
checkval(rc)
message = message .. "D" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_E)
checkval(rc)
message = message .. "E" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_F)
checkval(rc)
message = message .. "F" .. ":" .. tostring(rc2) .. ", "

rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_H)
checkval(rc)
message = message .. "H" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_I)
checkval(rc)
message = message .. "I" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_J)
checkval(rc)
message = message .. "J" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_K)
checkval(rc)
message = message .. "K" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_L)
checkval(rc)
message = message .. "L" .. ":" .. tostring(rc2) .. ", "

rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_P)
checkval(rc)
message = message .. "P" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_Q)
checkval(rc)
message = message .. "Q" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_R)
checkval(rc)
message = message .. "R" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_S)
checkval(rc)
message = message .. "S" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_T)
checkval(rc)
message = message .. "T" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_U)
checkval(rc)
message = message .. "U" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_V)
checkval(rc)
message = message .. "V" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_W)
checkval(rc)
message = message .. "W" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_X)
checkval(rc)
message = message .. "X" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_Y)
checkval(rc)
message = message .. "Y" .. ":" .. tostring(rc2) .. ", "
rc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_Z)
checkval(rc)
message = message .. "Z" .. ":" .. tostring(rc2)
wx.wxMessageBox(message)
end
end

if (mc.mcInEditor() == 1) then
m700(0)
end
Title: Re: Mcodes ??
Post by: poppabear on December 02, 2014, 08:47:43 AM
Yea, all those code calls in there, where just so all of A-Z calls could be seen.

Just comment out, or deleted the ones your not intending to use in your User macro.

Terry, as far as I am aware of, these parameters represent the Local Pound Vars.

Scott

Title: Re: Mcodes ??
Post by: MachMotion Development Team on December 02, 2014, 08:48:24 AM
I'm glad you guys worked it out... I found out why my example didn't work!!  When you copy code into this forum the text formatting drops the brackets around my array identifier.

This is how the forum modified my code:
rc = mc.mcCntlGetLocalVar(inst, hVars, ParameterNumberArray)

This is how it should have looked (I had to add spaces around the "i" to make it display):
rc = mc.mcCntlGetLocalVar(inst, hVars, ParameterNumberArray[ i ])

Do any of you know if there is a way to disable the formatting on a post?
Title: Re: Mcodes ??
Post by: Ya-Nvr-No on December 02, 2014, 08:57:28 AM
Sorry Andrew,  ::) I found my issue the [ i ] was missing from the message also

Code: [Select]
-----------------------------------------------------------------------------
-- Machine Type: Standard Mill Control
-- Author: MachMotion Development Team
-- Created: 09/24/2013
-- Modified by: MachMotion Development Team
-- Modified on: 01/10/2014
-- Description: Example: Reading Variables into MCodes
-- Copyright: © 2013-2014 Edge Solutions LLC All Rights Reserved
-----------------------------------------------------------------------------
function m702(hVars)
   local macroname = "m702"
   local a,b,c,rc,rc2
   local inst = mc.mcGetInstance() -- Get the current instance

   local nilPoundVar = mc.mcCntlGetPoundVar(inst,0)
   local message = ""
   if hVars ~= nil then
     
        local ParameterLetterArray = {"A", "B", "C", "D", "E", "F", "H", "I", "J", "K", "L", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
        local ParameterNumberArray = {mc.VAR_A, mc.VAR_B, mc.VAR_C, mc.VAR_D, mc.VAR_E, mc.VAR_F, mc.VAR_H, mc.VAR_I, mc.VAR_J, mc.VAR_K, mc.VAR_L, mc.VAR_P, mc.VAR_Q, mc.VAR_R, mc.VAR_S, mc.VAR_T, mc.VAR_U, mc.VAR_V, mc.VAR_W, mc.VAR_X, mc.VAR_Y, mc.VAR_Z}
        for i = mc.VAR_A, #ParameterNumberArray do
        rc = mc.mcCntlGetLocalVar(inst, hVars, ParameterNumberArray[i])
        message = message .. "#" .. ParameterLetterArray[i] .. ":" .. tostring(rc) .. "\n"
      end
      wx.wxMessageBox(message)
   end
   return nil, true, macroname .. " Ran Successfully"
end

if (mc.mcInEditor() == 1) then
    m702()
end
Title: Re: Mcodes ??
Post by: poppabear on December 02, 2014, 09:06:31 AM
Andrew,

Just so your are aware this line in your code needs to be removed.

return nil, true, macroname .. " Ran Successfully"

This causes the mach instance to "hang" and not close.
Maybe (and this is just a guess), your returning to nothing those values,
from the MDI or G-Code line which may be contributing to the hanging
of the instance.

When you remove that line the problem goes away...
Perhaps you should put conditional code around your return statement,
for if your in the editor...

Scott



Title: Re: Mcodes ??
Post by: BR549 on December 02, 2014, 12:33:49 PM
GUYS you cannot have Mcodes using the SAME local vars as the G65. The G65 are local vars(A-Z ,#1-#26) for the G65 ONLY. It will create a serious BOOBOO if they get mixed up.

I am not sure why you would want to use the #vars anyway. The Mcode variable should only be unique to that Mcode in the same way that the MACH3 macros worked. That way there are NO cross linked values.

(;-) TP
Title: Re: Mcodes ??
Post by: dude1 on December 02, 2014, 01:16:09 PM
I think they where just playing
Title: Re: Mcodes ??
Post by: mc on December 02, 2014, 01:23:11 PM
Do any of you know if there is a way to disable the formatting on a post?

Use code brackets-
Code: [Select]
rc = mc.mcCntlGetLocalVar(inst, hVars, ParameterNumberArray[i])

that's [ code ] & [ /code ] without the spaces
Title: Re: Mcodes ??
Post by: poppabear on December 02, 2014, 02:30:21 PM
Thanks for the heads up "mc"
Title: Re: Mcodes ??
Post by: Ya-Nvr-No on December 02, 2014, 02:43:32 PM
That the reason I always use the code feature, and its viewably compact / and easy to copy.

was unaware of the code character stripping of just pasting code, my lesson for the day
Title: Re: Mcodes ??
Post by: mc on December 02, 2014, 03:40:05 PM
was unaware of the code character stripping of just pasting code, my lesson for the day
Anything out with code brackets in a post, will go through the standard forum parser, and be parsed accordingly, which is why the [ i ] get changed to mean italic.
The other major benefit, is the code brackets should cause a fixed width font to be used(typically courier or similar), so the code layout/indentation appears better.
Title: Re: Mcodes ??
Post by: Ya-Nvr-No on December 02, 2014, 03:47:48 PM
Duh... that makes sense, thanks  8) second lesson for the day  ;)
Title: Re: Mcodes ??
Post by: BR549 on December 02, 2014, 11:20:11 PM
OK NOW I got it. Here is a Mcode with Param actually doing something. I can see where this will be VERY handy to use instead of using the G65 which is a licensed function not available to the average Joe (;-)

(;-) TP

---------------------------------------------------
--Brought to you by the: "Grey Headed ChipSlinger"!!
----------------------------------------------------
function M900(hVars)
   
   local Va
   local Vb
   local Vc
   
   local inst = mc.mcGetInstance() -- Get the current instance 
   
   mc.mcCntlSetLastError(inst, "Test Mcode Parameter");
 
          Va = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_A)
         
          Vb = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_B)
         
          Vc = mc.mcCntlGetLocalVar(inst, hVars, mc.VAR_C)
       
      mc.mcCntlGcodeExecute(inst, "G0 X"..Va);     
    mc.mcCntlSetLastError(inst, "Test Mcode Complete"); 
         
   end

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