Hello Guest it is March 28, 2024, 05:04:00 AM

Author Topic: Mcodes ??  (Read 13532 times)

0 Members and 1 Guest are viewing this topic.

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Mcodes ??
« Reply #20 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
Re: Mcodes ??
« Reply #21 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

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Mcodes ??
« Reply #22 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
Re: Mcodes ??
« Reply #23 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

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Mcodes ??
« Reply #24 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

fun times
Re: Mcodes ??
« Reply #25 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?
Andrew
MachMotion
Re: Mcodes ??
« Reply #26 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
« Last Edit: December 02, 2014, 01:54:23 PM by Ya-Nvr-No »

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Mcodes ??
« Reply #27 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



fun times

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Mcodes ??
« Reply #28 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

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Mcodes ??
« Reply #29 on: December 02, 2014, 01:16:09 PM »
I think they where just playing