- GCode and Part Programs
- O Codes (subroutines) and NGCGUI
- I'm having trouble calling a subroutine from a separate file.
I'm having trouble calling a subroutine from a separate file.
06 Feb 2019 01:20 #125779
by bondglen
I have made many subroutines and have never had a problem calling any of them. But these new ones will not function when called from a separate file. If I include them all in one file, everything is fine.
I have 3 subroutines. I set a global parameter and call the first routine. The first subroutine calls the other two subroutines.
I can't get it to work. nothing happens. I am able to call other routines and they work fine.
It seems that the subroutine might be running in the background.
When I run the subroutine, the stop button becomes inactive, like the program has ended.
But changes on the digital I/O pins sometimes cause action!!?? (The subroutines read the digital I/O pins)
I can't figure this one out.
If anybody has any ideas, please let me know.
Thanks,
Glen
I have 3 subroutines. I set a global parameter and call the first routine. The first subroutine calls the other two subroutines.
I can't get it to work. nothing happens. I am able to call other routines and they work fine.
It seems that the subroutine might be running in the background.
When I run the subroutine, the stop button becomes inactive, like the program has ended.
But changes on the digital I/O pins sometimes cause action!!?? (The subroutines read the digital I/O pins)
I can't figure this one out.
If anybody has any ideas, please let me know.
Thanks,
Glen
Please Log in or Create an account to join the conversation.
06 Feb 2019 22:24 #125884
by bondglen
Replied by bondglen on topic I'm having trouble calling a subroutine from a separate file.
I gave up trying to make the new subroutines work. Went back to old files that previously work perfectly... they don't work! Apparently I have messed up something in my system.
I'm going to do a new install of LinuxCNC.
Glen
I'm going to do a new install of LinuxCNC.
Glen
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
Less
More
- Posts: 5008
- Thank you received: 1440
07 Feb 2019 03:30 #125903
by Todd Zuercher
Replied by Todd Zuercher on topic I'm having trouble calling a subroutine from a separate file.
Where are you saving your sub files? Is it possible you could have changed the path in your ini file?
Please Log in or Create an account to join the conversation.
07 Feb 2019 22:41 #125958
by bondglen
Replied by bondglen on topic I'm having trouble calling a subroutine from a separate file.
Ok, got it back to where I was originally.
No, the path is still good.
There seems to be some sort of critical requirements for the %.
If I don't use them, LinuxCNC will hang when I load the file.
If I use them at beginning and end of subroutine file, it doesn't work.
Some files seem to work well with no % at the beginning, and at the end use % and M30.
Got to have the M30.
These subroutines, all of them will work fine when executed with MDI. (% and M30 at the end)
I'm trying to find more info on file format for subroutines.
No, the path is still good.
There seems to be some sort of critical requirements for the %.
If I don't use them, LinuxCNC will hang when I load the file.
If I use them at beginning and end of subroutine file, it doesn't work.
Some files seem to work well with no % at the beginning, and at the end use % and M30.
Got to have the M30.
These subroutines, all of them will work fine when executed with MDI. (% and M30 at the end)
I'm trying to find more info on file format for subroutines.
Please Log in or Create an account to join the conversation.
08 Feb 2019 00:08 - 08 Feb 2019 00:21 #125965
by BigJohnT
Replied by BigJohnT on topic I'm having trouble calling a subroutine from a separate file.
linuxcnc.org/docs/2.7/html/gcode/overvie...de:file-requirements
There is a big difference between wrapping G code with a pair of %% and using M2 to end a file.
Also note that the subroutine file name and the subroutine name must match and the file must be executable and I know I put that in the docs but dang if I an find it now. This is an example subroutine file.
Edit: make sure the SUBROUTINE_PATH = /home/yourusername/linuxcnc/subroutines is a valid path in the [RS274NGC] section of the ini file.
Edit: call the subroutine file like this:
JT
There is a big difference between wrapping G code with a pair of %% and using M2 to end a file.
Also note that the subroutine file name and the subroutine name must match and the file must be executable and I know I put that in the docs but dang if I an find it now. This is an example subroutine file.
(file somefile.ngc)
o<somefile> sub
G0 X2
o<somefile> endsub
M2
Edit: make sure the SUBROUTINE_PATH = /home/yourusername/linuxcnc/subroutines is a valid path in the [RS274NGC] section of the ini file.
Edit: call the subroutine file like this:
o<somefile> call
M2
JT
Last edit: 08 Feb 2019 00:21 by BigJohnT.
Please Log in or Create an account to join the conversation.
08 Feb 2019 16:34 #126007
by bondglen
Replied by bondglen on topic I'm having trouble calling a subroutine from a separate file.
I think my path to the subroutines is set ok, because I have other subroutines that are called from a file and they work fine. All my subroutines are in the same directory.
What is the difference in calling from a file and entering the command in MDI?
From MDI everything works good, but when I try to call it from a program file it doesn't work.
The same program will call other subroutines without problems.
What is the difference in calling from a file and entering the command in MDI?
From MDI everything works good, but when I try to call it from a program file it doesn't work.
The same program will call other subroutines without problems.
Please Log in or Create an account to join the conversation.
08 Feb 2019 21:22 - 08 Feb 2019 21:23 #126018
by BigJohnT
Replied by BigJohnT on topic I'm having trouble calling a subroutine from a separate file.
Attachments:
Last edit: 08 Feb 2019 21:23 by BigJohnT.
Please Log in or Create an account to join the conversation.
09 Feb 2019 03:52 #126034
by bondglen
Replied by bondglen on topic I'm having trouble calling a subroutine from a separate file.
Ok, I made all files executable. It had no effect.
I took one of the subroutines that won't work and began cutting out several lines of code at a time and trying it. Normally, EMC just hangs after trying to load the file. I continued to cut out lines of code until it started working. Here is what I came up with.
o307 while [#5399 EQ 0]
This line of code doesn't work
if I change it to:
o307 while [#5399 NE 0]
it will load.
The preceding line is
M66 P2 L0
So the value of #5399 could be 0 or 1 depending on digital input pin 2.
Maybe I should change the code from EQ 0 to NE 1.
I think it has something to do with the digital input.
I took one of the subroutines that won't work and began cutting out several lines of code at a time and trying it. Normally, EMC just hangs after trying to load the file. I continued to cut out lines of code until it started working. Here is what I came up with.
o307 while [#5399 EQ 0]
This line of code doesn't work
if I change it to:
o307 while [#5399 NE 0]
it will load.
The preceding line is
M66 P2 L0
So the value of #5399 could be 0 or 1 depending on digital input pin 2.
Maybe I should change the code from EQ 0 to NE 1.
I think it has something to do with the digital input.
Please Log in or Create an account to join the conversation.
09 Feb 2019 11:28 #126045
by BigJohnT
Replied by BigJohnT on topic I'm having trouble calling a subroutine from a separate file.
The while loop is working I guess but must not ever be equal 0. You can use a debug statement to see what the variable is just before entering the while loop. Axis for example will run the G code file to plot the path out so while that is going on and the variable is not equal to 0 the interpreter waits forever in the while loop. You can in Axis control the preview
linuxcnc.org/docs/devel/html/gui/axis.html#axis:preview-control
JT
linuxcnc.org/docs/devel/html/gui/axis.html#axis:preview-control
JT
Please Log in or Create an account to join the conversation.
09 Feb 2019 16:30 #126062
by bondglen
Replied by bondglen on topic I'm having trouble calling a subroutine from a separate file.
Ok, I tried (AXIS,show) and (AXIS, hide), but they didn't do the trick, but when I used (AXIS, stop) everything started working. But no preview on the screen.
So I re-wrote the subroutine that reads the digital pins to get rid of the do/while loops.
The M66 code provides for a 'wait for high', or 'wait for low' on the digital input pins.
So I used M66 L3 Q5000, and M66 L4 Q5000 to get rid of the do/while loops and now have preview back.
Everything works great!
Many thanks, BigJohnT
So I re-wrote the subroutine that reads the digital pins to get rid of the do/while loops.
The M66 code provides for a 'wait for high', or 'wait for low' on the digital input pins.
So I used M66 L3 Q5000, and M66 L4 Q5000 to get rid of the do/while loops and now have preview back.
Everything works great!
Many thanks, BigJohnT
The following user(s) said Thank You: BigJohnT
Please Log in or Create an account to join the conversation.
- GCode and Part Programs
- O Codes (subroutines) and NGCGUI
- I'm having trouble calling a subroutine from a separate file.
Time to create page: 0.106 seconds