Hello Guest it is March 29, 2024, 01:31:51 AM

Author Topic: Mach4 default scripts  (Read 433 times)

0 Members and 1 Guest are viewing this topic.

Mach4 default scripts
« on: March 16, 2023, 11:30:35 AM »
Hey,

Im trying to write custom scripts for M3, M5, M30 commands, but I would like to see the default built in script for these commands. Is there a way to find it somewhere?

Thanks
Re: Mach4 default scripts
« Reply #1 on: March 16, 2023, 03:26:37 PM »
Hi,
I have never seen the scripts published anywhere. May I suggest you look at the SpinOn/SpinOff buttons in the Sreen editor.
The SpinCw and SpinCCW scripts are in the ScreenLoad script excerpted here:

Code: [Select]
---------------------------------------------------------------
function SpinCW()
    local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    local sigState = mc.mcSignalGetState(sigh);
   
    if (sigState == 1) then
        mc.mcSpindleSetDirection(inst, 0);
    else
        mc.mcSpindleSetDirection(inst, 1);
    end
end
---------------------------------------------------------------
-- Spin CCW function.
---------------------------------------------------------------
function SpinCCW()
    local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    local sigState = mc.mcSignalGetState(sigh);
   
    if (sigState == 1) then
        mc.mcSpindleSetDirection(inst, 0);
    else
        mc.mcSpindleSetDirection(inst, -1);
    end
end

Next suggestion is you need to write all your scripts in lower case, eg m4, m4 and m5. Mach's interpreter parses all Gcode to lowercase, strips out leading zeros and
whitespace. Usually human readable code is interpreted correctly but sometimes its not and it's a devil of a bug to find. Get used to writing all Gcode in lowercase.
I tend to still include whitespace for the sake of readability, but write Gcode in lowercase to better match Machs interpreter.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 default scripts
« Reply #2 on: March 16, 2023, 03:34:27 PM »
Mach4 uses it's own internal m3, m4, m5, m30 ect... unless you add one of these to the profiles's macro folder.  I make my own m30 when we get a machine going, that way I can turn on a stack light and buzzer when the part is finished. 
There is a thread on here somewhere with me asking that very question and one of the Mach4 developers said you needed to be sure certain things were in the macro, I can't remember what they are right off the top of my head.  However, the machine I'm working on does the following:
Turns off the spindle; turns off the coolant; calls a G40 with an mdiexecute api command and then I turn on my buzzer and stacklight. 
I have made custom m3 and m5 commands as well.
Like I said, just make a macro and save it in the macro folder of your profile that you are working with.  Mach4 --> Profiles --> your profile --> macros.  Save it as m3, m5, or m30.  It will replace whatever the stock commands are.
Chad Byrd
Re: Mach4 default scripts
« Reply #3 on: March 16, 2023, 03:43:15 PM »
Thanks for replys. I already have custom m3/4/5 working. I was just looking for original code for m30 so that I dont miss anything.
Re: Mach4 default scripts
« Reply #4 on: March 16, 2023, 03:46:26 PM »
Hi,
that is exactly how I handle my own m3/m4 scripts also.

This is where using lowercase is important. When Mach encounters an m3 it searches in the macros folder of the current profile, if it find it then it uses it. If it does not
find it it searches up the file tree until it does. Using lowercase will ensure, or at least increase the probability, that Mach will search and find the macro
that you intended to be used as opposed to the in-built macro.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 default scripts
« Reply #5 on: March 16, 2023, 03:53:45 PM »
I dont have problem with calling custom macros. I just want to find and have a look at original m30 script.
Re: Mach4 default scripts
« Reply #6 on: March 16, 2023, 05:10:36 PM »
I found what I was looking for.
Smurph talks about it a few posts down.

https://www.machsupport.com/forum/index.php?topic=33831.msg235284#msg235284
Chad Byrd
Re: Mach4 default scripts
« Reply #7 on: March 16, 2023, 05:35:32 PM »
Thanks, I found that yesterday. I think I will be able to script reliable code for m30 according to that. I was just curious, if I can find somewhere in Mach4 the actual code being executed, if there is no custom script.