Hello Guest it is March 28, 2024, 09:13:37 PM

Author Topic: macro problem  (Read 1835 times)

0 Members and 1 Guest are viewing this topic.

Offline Bill_O

*
  •  563 563
    • View Profile
macro problem
« on: March 04, 2019, 04:57:44 PM »
I made a macro and saved it in the profile macros folder.
For some reason it is not working.
I also made a button that runs that m code.
It is not working either.
I actually think the problem is the macro because it will not run if i type m22 in the mdi either.
both are attached

Offline jbuehn

*
  •  101 101
    • View Profile
Re: macro problem
« Reply #1 on: March 04, 2019, 07:34:28 PM »
you need:

local inst = mc.mcGetInstance()

because you're passing that variable into mc.mcSignalGetHandle

Offline Bill_O

*
  •  563 563
    • View Profile
Re: macro problem
« Reply #2 on: March 05, 2019, 01:43:13 PM »
jbuehn,

thanks

bill

Offline Bill_O

*
  •  563 563
    • View Profile
Re: macro problem
« Reply #3 on: March 05, 2019, 04:03:51 PM »
when i try putting local inst = mc.mcGetInstance() the editor changes it to mc.mcCntlGetIntstanceHandle()

Offline jbuehn

*
  •  101 101
    • View Profile
Re: macro problem
« Reply #4 on: March 05, 2019, 09:28:36 PM »
when you start typing the mc.mc part you should get a drop down list that has mc.mcGetInstance() in it.

I'm guessing you had "Cntl" in there which is why it was selecting mc.mcCntGetInstanceHandle() and not just mc.mcGetInstance()
« Last Edit: March 05, 2019, 09:30:23 PM by jbuehn »

Offline Bill_O

*
  •  563 563
    • View Profile
Re: macro problem
« Reply #5 on: March 06, 2019, 07:52:59 AM »
jbuehn,
i did not put the cntl in it but i did find out how to make it not do the one i do not want.
if i type "mc.mcGetInstance" it only shows me the one with cntl and handle
if i type "mc.mcgetinstance" it brings up the one i want.
strange
bill

Offline Bill_O

*
  •  563 563
    • View Profile
Re: macro problem
« Reply #6 on: March 06, 2019, 09:50:30 AM »
still not functioning either when i push the button or type m22 in the mdi
i have attached them again.
once again i know i am missing something simple
i saved the m22 in the profiles macro folder as m22.mcs
do i need to do anything else?
Re: macro problem
« Reply #7 on: March 06, 2019, 11:39:36 AM »
Running the m22 macro, I am able to debug it and run it on MDI.
I'm not sure what issue you are having with the Macro, it runs fine for me.

The button press however, instead of using GCodeExecuteWait, use MdiExecute
Also, for best practice, keep the "m" lower case, you had it upper case. 
--New button script.
local inst = mc.mcGetInstance()
local N2Ac = "m22"
--mc.mcCntlGcodeExecuteWait(inst, N2Ac)
mc.mcCntlMdiExecute(inst, N2Ac)
Chad Byrd
Re: macro problem
« Reply #8 on: March 06, 2019, 11:57:53 AM »
Hi,
you are confusing a macro and a button script. Try writing them a two distinctly different pieces of code.

Next thing is don't call it m22(). All your macros should be named m100() or higher, avoiding m162 and m163
as they are also used by Mach for Laser Operations.


Try saving this as your macro, note that I renamed it m220():
Code: [Select]
function m220()
local inst=mc.mcGetInstance()
local sigHandle=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT2)
mc.mcSignalSetState(sigHandle,1)
end
if (mc.mcInEditor()==1) then
m220()
end

For the button script use this:
Code: [Select]
local inst=mc.mcGetInstance()
local sigHandle=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT2)
mc.mcSignalSetState(sigHandle,1)

You could as Chas has suggested call the macro with the mcCntlMDIExecute() API. When you press the button
the GUI chunk is running. Its actionis to execeute a macro which is in a different chunk, ie Mach has to switch from
one chunk to another. It can and does this all the time, but in this case is unnecessary, just repeat the functional code
in the button script and it will be compiled and contained within the GUI chunk and have no need of a context switch
to execute.
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: macro problem
« Reply #9 on: March 06, 2019, 12:18:33 PM »
Craig, I agree with you, I would much prefer having the logic in the button script as well.  May be a little redundant on the work, but it makes it bulletproof.
Chad Byrd