Hello Guest it is March 29, 2024, 11:28:46 AM

Author Topic: subroutine only  (Read 3884 times)

0 Members and 1 Guest are viewing this topic.

subroutine only
« on: November 23, 2011, 10:42:31 PM »
I have figured out from sample programs how to write a subroutine within a program that runs, however I do get an error message (Return called no sub in effect - looping). I cannot find a sample of and have not  been able to figure out how to write a subroutine only and store in subroutine file for future call back. Hoping someone would be willing to give an example of how to do this. Thanks


Scott

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: subroutine only
« Reply #1 on: November 24, 2011, 09:45:51 AM »
When writing a sub you MUST include the M99 to return to the parent program. BUT if you try to run it as a seperate program you will get the error above. MACH sees the return call(M99) BUT it cannot find the parent that called it.

To test and run the program just comment out the M99 for testing .

WHen you are done place the sub in the SUBPROGRAM directory in MACH.

From the Program running you call it with M98 "Nameofsub.txt" L1

Hope that helps, (;-) TP
Re: subroutine only
« Reply #2 on: November 24, 2011, 01:48:59 PM »
Thanks, I did figure out I was putting M30 at the end of sub rather than at end of main and that was causing the error message. I still cannot get a sub only written and saved to call back up. I am confused about the terminology. With my old allen bradley controlled mill there is both sub programs and subroutines with their own definitions. The terms seem be used interchangeably in mach. Your message says sub but then at the end you say subprogram directory. I cannot find a subprogram , but there is a subroutine wich is what I have been saving the attempts in. Can you please clarify and if not to much trouble write a short example of how you would do a sub only for storage.

Thanks for help, Scott

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: subroutine only
« Reply #3 on: November 24, 2011, 02:40:16 PM »
THe Sub directory is call "Subroutines"  It is located in the MACH3 directory.

An outside sub and a inside sub is exactly the same thing. The difference being that you NAME the outside sub for example "TestSub.txt" and store it in the subdirectory "Subroutines".

Where in the inside program sub it is named as a  O word  for example  o001  and is stored inside the parent Gcode program itself as part of the Gcode.


(TestSub.txt)
G0 X0 Y0
G1 X10 Y10 F100
M99
%


o001
G0 X0 Y0
G1 X10 Y10 F100
M99
%


Outside sub call

M98 "Testsub.txt" L1

Inside sub call

M98 P001 L1

Does that help, (;-) TP


Re: subroutine only
« Reply #4 on: November 24, 2011, 10:25:54 PM »
TP,  Yes ! I think I can get it now. The samples are so helpful. I will not have time to try again for a day or so. Thank you so much, I had no idea about the outside sub call, and will give it a try.

Scott

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: subroutine only
« Reply #5 on: November 24, 2011, 10:48:39 PM »
IF you get stuck just post what you have working and we can help from there.

(;-) TP