Calling a Python subroutine

More
20 Dec 2019 15:23 #152949 by Elco
I am trying to find out how to call a python subroutine with an o-call. Following the documentation,
the TOPLEVEL location is defined in the .ini file and the log shows that __INIT__ procedure is executed.

But the o<test1> call does not find the Python routine (test1.py) in /linuxcnc/ncfiles. The document says the
routine is called when an O-word call like o<proc> call is executed and the name oword.proc is defined and callable.

I could not find an example, but I assume the oword.proc module is a file with that name, with the Python routine inside.
Or is the name oword.test1 (in my case) defined somewhere else?

Thanks for any advice.

Please Log in or Create an account to join the conversation.

More
20 Dec 2019 16:01 #152952 by Todd Zuercher
I don't think you can call a python program with an o call.

G-code remapping can call an o-sub or python. but that isn't the same thing.
You can run a python script file as a custom M-code. (M100...)

Please Log in or Create an account to join the conversation.

More
20 Dec 2019 16:21 #152953 by Elco
Replied by Elco on topic Calling a Python subroutine
Yes,, of course. Sorry about using the wrong term. I write python subroutines in this case, essentially converting a lot of (somewhat incompatible) G-code routines that I wrote in the past. Picking up variables is well documented, but I am puzzled about where and how to define the oword module. I assume It can contain multiple subroutine definitions.

I am not looking at remapping existing code, but calling python subroutines from the main G-code.

Please Log in or Create an account to join the conversation.

More
07 Jan 2020 21:44 #154259 by andypugh

Todd Zuercher wrote: I don't think you can call a python program with an o call.)


You can, you can call any executable file.

linuxcnc.org/docs/2.7/html/gcode/o-code....#ocode:calling-files
and
linuxcnc.org/docs/2.7/html/gcode/m-code.html#mcode:m100-m199
both apply.

I have just tried it, though, and failed. But then I couldn't make a G-code M100 work either. I think my test system (which is a compiled run-in-place) is not setting the SUBROUTINE_PATH correctly. I need to do a lot of cleaning up.

The steps should be to create a python file with the shebang for python (#!/usr/bin/python though if your system has usr/bin/env use #!/usr/bin/env python) then make that file executable (chmod +x filename)

Maybe practice with a file called 100 and M100 first, possibly also begin with a G-code sup and change one thing at a time.

Please Log in or Create an account to join the conversation.

More
07 Jan 2020 21:57 - 07 Jan 2020 21:58 #154263 by Todd Zuercher
Andy, are you sure your not confused? The links to the docs on o-code calls only seem to reference calling g-code subs. And for M100 codes, I thought for sure I had tried in the past to use a g-code sub as a custom M-code and failed, then asked about it and was told it wasn't possible,
Last edit: 07 Jan 2020 21:58 by Todd Zuercher.

Please Log in or Create an account to join the conversation.

More
08 Jan 2020 21:33 #154347 by andypugh
You are probably right, after some more experiment.

But, there is a workaround: You can call an ngc subroutine that calls a user-Mcode that runs Python. I have just tried that, and it works.

Please Log in or Create an account to join the conversation.

Time to create page: 0.087 seconds
Powered by Kunena Forum