SOLVED: Python Interface: getting active gcodes

  • fletch
  • fletch's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
17 Jul 2023 11:23 - 17 Jul 2023 11:27 #275642 by fletch
I'm trying to clean up the Manualmatic G5x offset functionality and need to find out if G90 or G91 is active. The Python Interface kindly offers
linuxcnc.stat.gcodes
: "Active G-codes for each modal group. G code constants G_x - G_xxx" so I naively expected a quick
if ( self.linuxcnc.G_90 ) in self.ls.gcodes:
would see me right but it would appear G_90 is not a constant of
linuxcnc
(nor is it of
stat
or
command
.

I also tried a string, as in
if ( "G_90" ) in self.ls.gcodes:
but even after explicitly setting G90 via MDI the response is still negative.

Any help in using the
linuxcnc.stat.gcodes
would be greatly appreciated and as a bonus, an understanding of what "for each modal group" means also, because I think that might be relevant...

As a PS, is there an automatically generated 'API doc' for the Python Interface available? The Python Interface doc is really useful but sometimes there's a need to dig a little deeper (and I still can't find the source!)
Last edit: 17 Jul 2023 11:27 by fletch. Reason: Wrong markup for code

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

More
17 Jul 2023 13:24 - 17 Jul 2023 13:29 #275645 by rmu
Replied by rmu on topic Python Interface: getting active gcodes
IIRC linuxcnc.stat.gcodes should contain a list of integers, G90 would be 900, G91 910 and so on. github.com/LinuxCNC/linuxcnc/blob/master...k/taskmodule.cc#L441
Last edit: 17 Jul 2023 13:29 by rmu.
The following user(s) said Thank You: meister, fletch

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

  • meister
  • Away
  • Platinum Member
  • Platinum Member
More
17 Jul 2023 13:56 #275647 by meister
Replied by meister on topic Python Interface: getting active gcodes
import sys
import linuxcnc

try:
    s = linuxcnc.stat() # create a connection to the status channel
    s.poll() # get current values
except Exception as detail:
    print("error", detail)
    sys.exit(1)

print(s.gcodes)

if 900 in s.gcodes:
    print("G90 active")
elif 910 in s.gcodes:
    print("G91 active")

The following user(s) said Thank You: fletch

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

  • fletch
  • fletch's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
17 Jul 2023 14:29 #275651 by fletch
Many thanks Robert and Oliver - the Python Interface is a little misleading when it describes 'G code constants' as G_90 and G_91 so it didn't occur to me to drop the 'G_'.

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

More
17 Jul 2023 22:36 #275689 by cmorley
Gstat might be useful tool.
linuxcnc.org/docs/2.9/html/gui/gstat.html

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

Time to create page: 0.059 seconds
Powered by Kunena Forum