Hello Guest it is April 27, 2024, 07:40:59 PM

Author Topic: My mcode does not run when called from the Gcode/MDI window  (Read 263 times)

0 Members and 1 Guest are viewing this topic.

My mcode does not run when called from the Gcode/MDI window
« on: March 11, 2024, 06:38:26 PM »
I created a new m code, m500 and put it in the folder 'C:\Mach4Hobby\Profiles\AXYZ\Macros'.

The contents of the file are:
Code: [Select]
function m500()
wx.wxMessageBox("Works")
end

if (mc.mcInEditor() == 1) then
m500()
end
I'm running the profile in AXYZ and have confirmed this.

When I type 'M500' in the MDI window, or put it in a gcode file it does not execute. It just sits on the line and the cycle time counter goes up. I don't get any errors, it doesn't do anything.

I tried making a simple gcode file that looked like:
Code: [Select]
X0 Y0
m500
X1 Y1

The machine moves to 0,0 then just sits on the m500 line.

I tried calling the command from a button and it works fine

I stepped through the function and the message box pops up correctly.

What am I doing wrong?


Offline cncmagic

*
  •  63 63
  • what me worry? heck...it ain't my machine anyway
    • View Profile
Re: My mcode does not run when called from the Gcode/MDI window
« Reply #1 on: March 11, 2024, 09:34:50 PM »
works on my test machine.. I tried it as M150 and M500 and both seem to work exactly as you have it shown.. :o
any semblance of information posted to anything remotely  close to accuracy is merely coincidence. Use at you own discretion.. or play the lottery.. same odds
Re: My mcode does not run when called from the Gcode/MDI window
« Reply #2 on: March 12, 2024, 09:56:30 AM »
Is the "m" case sensitive?

Offline cncmagic

*
  •  63 63
  • what me worry? heck...it ain't my machine anyway
    • View Profile
Re: My mcode does not run when called from the Gcode/MDI window
« Reply #3 on: March 12, 2024, 10:47:01 AM »
I believe it is.. the macro itself should be lowercase.. the gcode and mdi doesn't make any difference.  ???
any semblance of information posted to anything remotely  close to accuracy is merely coincidence. Use at you own discretion.. or play the lottery.. same odds
Re: My mcode does not run when called from the Gcode/MDI window
« Reply #4 on: March 12, 2024, 04:24:27 PM »
Make sure none of your other macros have error in them and make sure there are no files in the macros folder that may contain other m500() function. e.g. if you have renamed a file 'm500old.lua' and it still contains an m500() function it will cause it to mess up
Re: My mcode does not run when called from the Gcode/MDI window
« Reply #5 on: March 12, 2024, 05:40:29 PM »
I only have the m500 file in the Macros folder.

I tried upper and lower case with no difference.

I did notice something weird though with the button, When I press it it's starts the cycle and hangs like when running it in the MDI window. When I press the button again is when it executes.

The code is in the 'Button clicked' event and looks like:
Code: [Select]
local inst=mc.mcGetInstance()
mc.mcCntlGcodeExecute(inst, "m500\n")

Offline cncmagic

*
  •  63 63
  • what me worry? heck...it ain't my machine anyway
    • View Profile
Re: My mcode does not run when called from the Gcode/MDI window
« Reply #6 on: March 12, 2024, 05:52:29 PM »
calling from a button script is different.. search through the forum and you can find what you are looking for.. if the button isn't calling any actual G codes, or axis moves, you call it differently. There are lots of responses previously that you will be able to find.  :(
any semblance of information posted to anything remotely  close to accuracy is merely coincidence. Use at you own discretion.. or play the lottery.. same odds
Re: My mcode does not run when called from the Gcode/MDI window
« Reply #7 on: March 14, 2024, 05:29:18 PM »
I messed around with it a lot and still couldn't figure out why it wasn't working. As a test I made a new profile with no edits, added the M500 from above and it worked fine.

I ended up copying my screen set in to this new profile and it worked, I can't figure out what I did to break it, It must be one of the files I was editing i made some odd mistake. But I'm moving along now.