- Posts: 28
- Thank you received: 1
Custom Python M-code. Interpreter state not idle
3 years 2 months ago #276878
by Faggan
Custom Python M-code. Interpreter state not idle was created by Faggan
Hi,
Im writing a custom python M-code. according to manuals and guides it is recommended to check the interpreter state (among other things) before sending commands.
(s.interp_state == linuxcnc.INTERP_IDLE)
s.interp_state returns an integer 0-3 that corresponds with the state. The Idle state is from what i can understand integer 0.
However. The state returned is 2 (paused?) I get the same result on my physical machine and in simulation.
In short. because its not idle i cant send mdi commands. Or at least i think thats why. Never the less, it should be idle...
I have copied the example in the python interface manual and it has the same issue.
Im writing a custom python M-code. according to manuals and guides it is recommended to check the interpreter state (among other things) before sending commands.
(s.interp_state == linuxcnc.INTERP_IDLE)
s.interp_state returns an integer 0-3 that corresponds with the state. The Idle state is from what i can understand integer 0.
However. The state returned is 2 (paused?) I get the same result on my physical machine and in simulation.
In short. because its not idle i cant send mdi commands. Or at least i think thats why. Never the less, it should be idle...
I have copied the example in the python interface manual and it has the same issue.
Please Log in or Create an account to join the conversation.
3 years 2 months ago #276887
by MaHa
Replied by MaHa on topic Custom Python M-code. Interpreter state not idle
Sometimes, for inspiration how to solve a certain problem, i have a look at other linuxcnc python code, eg. axis ui.
github.com/LinuxCNC/linuxcnc/blob/master...axis/scripts/axis.py
From line 963 to 993 could be related to what you are doing.
github.com/LinuxCNC/linuxcnc/blob/master...axis/scripts/axis.py
From line 963 to 993 could be related to what you are doing.
Please Log in or Create an account to join the conversation.
3 years 2 months ago #276888
by Faggan
Replied by Faggan on topic Custom Python M-code. Interpreter state not idle
Hi,
Thanks for your reply.
It looks a lot like what i've seen on other examples.
My main issue is that s.interp_state == linuxcnc.INTERP_IDLE is never true.
I have even tried omitting that check and running a simple mdi command like: "c.mdi("G0 X10 Y20")" but the command is not processed. Instead i get a "KeyboardInterrupt" and the program exits. Probably due to the fact that the Interpreter is indeed not idle.
Thanks for your reply.
It looks a lot like what i've seen on other examples.
My main issue is that s.interp_state == linuxcnc.INTERP_IDLE is never true.
I have even tried omitting that check and running a simple mdi command like: "c.mdi("G0 X10 Y20")" but the command is not processed. Instead i get a "KeyboardInterrupt" and the program exits. Probably due to the fact that the Interpreter is indeed not idle.
Please Log in or Create an account to join the conversation.
3 years 2 months ago - 3 years 2 months ago #276911
by cmorley
Replied by cmorley on topic Custom Python M-code. Interpreter state not idle
Hard to diagnosis accurately without sample code, but are you polling s right before the interpreter state check?
Last edit: 3 years 2 months ago by cmorley.
Please Log in or Create an account to join the conversation.
3 years 2 months ago #276913
by Faggan
Replied by Faggan on topic Custom Python M-code. Interpreter state not idle
This code wont work: (copied from python interface manual)
import linuxcnc
s = linuxcnc.stat()
c = linuxcnc.command()
def ok_for_mdi():
s.poll()
return not s.estop and s.enabled and s.homed and (s.interp_state == linuxcnc.INTERP_IDLE)
if ok_for_mdi():
c.mode(linuxcnc.MODE_MDI)
c.wait_complete() # wait until mode switch executed
c.mdi("G0 X10 Y20 Z30"
Thats not the specific code I want to run. But it has the same issue.
The issue specifically is: (s.interp_state == linuxcnc.INTERP_IDLE)
This is not true the interpreter is not idle.
s.interp_state returns a 2. From what i can tell from the manual, provided the statuses for interp_state is in order 2 should mean INTERP_PAUSED.
import linuxcnc
s = linuxcnc.stat()
c = linuxcnc.command()
def ok_for_mdi():
s.poll()
return not s.estop and s.enabled and s.homed and (s.interp_state == linuxcnc.INTERP_IDLE)
if ok_for_mdi():
c.mode(linuxcnc.MODE_MDI)
c.wait_complete() # wait until mode switch executed
c.mdi("G0 X10 Y20 Z30"
Thats not the specific code I want to run. But it has the same issue.
The issue specifically is: (s.interp_state == linuxcnc.INTERP_IDLE)
This is not true the interpreter is not idle.
s.interp_state returns a 2. From what i can tell from the manual, provided the statuses for interp_state is in order 2 should mean INTERP_PAUSED.
Please Log in or Create an account to join the conversation.
3 years 2 months ago #276922
by cmorley
Replied by cmorley on topic Custom Python M-code. Interpreter state not idle
Took a bit for the penny to drop 
This is an mcode, so the interpreter is always running - 2 is interp reading.
This is an mcode, so the interpreter is always running - 2 is interp reading.
Please Log in or Create an account to join the conversation.
Time to create page: 0.144 seconds