Hello Guest it is March 28, 2024, 05:48:14 AM

Author Topic: Running a subroutine from inside a macro?  (Read 2032 times)

0 Members and 1 Guest are viewing this topic.

Running a subroutine from inside a macro?
« on: February 13, 2018, 12:00:34 AM »
Very random question.  I know that the subroutine's O# or name must match the main files O# but can you call said subroutine from inside a macro?  What if I would need to call multiple subroutines from inside of a file?  Is it possible to have it open a different O# subroutine?

Thanks.
Re: Running a subroutine from inside a macro?
« Reply #1 on: February 13, 2018, 10:44:01 AM »
Your question is a little bit confusing.  O# are used in gcode files, macros use function calls.  Could you restate the question so we know whether your trying to execute gcode files from a macro or another macro or anther function in the same macro?

RT
Re: Running a subroutine from inside a macro?
« Reply #2 on: February 13, 2018, 05:31:46 PM »
Sorry, it was a late night last night. If I choose to store a subroutine outside of the main file, it is my understanding that the subroutine must be named using the O# convention. What I’m wondering is two fold.  First, can I call a subroutine that is stored outside of the main file from inside a macro? Second, from reading another forum post (sorry not sure which one) it sounded like I can only call one subroutine stored outside of the main file when using hobby. Is this true or did I misunderstand.

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Running a subroutine from inside a macro?
« Reply #3 on: February 13, 2018, 11:52:53 PM »
sour kraut, to make it easier for you to learn get Peter Smid book on macros, I am quite sure you can not use maros at all in Mach4
Re: Running a subroutine from inside a macro?
« Reply #4 on: February 14, 2018, 12:10:37 AM »
dude1, don't let my number of posts fool you, I've been working with industrial CNC routers for almost 20 years now so I understand macro programming but it's might be a nice read either way.  You might be thinking about Macro B which can only be run on the industrial version but you can write your own macros using Lua.  Each Profile in the Mach4Hobby directory has a subfolder called Macros where you can store them.  I only asked this because I travel for a living and am not at home this week to test this out. 
Re: Running a subroutine from inside a macro?
« Reply #5 on: February 14, 2018, 12:42:34 AM »
There are multiple definitions of a macro.  If your gcode had a m900, what would your m900.mcs code contain?  Please provide a simplified example and we may be able to better answer how your definition  of macro differs from Mach4's.

RT
Re: Running a subroutine from inside a macro?
« Reply #6 on: February 14, 2018, 02:00:01 AM »
Hi,
WARNING THIS IS MY OWN UNDERSTANDING AND MAY, IN FACT PROBABLY,IS WRONG

If you have a Gcode file which includes one or more subroutines O#, and one or more macros M# then the main Gcode file can execute any of the
subroutines but the macros cannot.

The reasoning given was that the macro is in a sense a subroutine in itself. Thus the parent program, the Gcode file, calls a macro which attempts to
call a subroutine but that subroutine is defined in the parent and the call will fail. 'A parent can call on a child or children but a child cannot call on a parent'

Using this logic if a macro has a subroutine defined within itself it could be called successfully.

If you wish code to be called against the hierarchy then that code could/should be put in a panel.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Running a subroutine from inside a macro?
« Reply #7 on: February 14, 2018, 10:51:21 PM »
Some days it pays to stay off the internet. I responded in the wrong post.

http://www.machsupport.com/forum/index.php/topic,36577.msg250891.html#msg250891

Findings:

A subroutine can call a macro, and a macro can call a subroutine but more testing is needed.