Skip to content

Instantly share code, notes, and snippets.

@koppi
Created June 23, 2016 14:29
Show Gist options
  • Save koppi/6faf5592e3dfe01d05af8a2763b7a891 to your computer and use it in GitHub Desktop.
Save koppi/6faf5592e3dfe01d05af8a2763b7a891 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
#
# submit an ngc file to a running LinuxCNC / Machinekit instance
#
# used as a filter for https://github.com/stewartoallen/grid-print
#
import sys
from shutil import copyfile
import linuxcnc
def ok_for_mdi(s):
s.poll()
return not s.estop and s.enabled and s.homed and (s.interp_state == linuxcnc.INTERP_IDLE)
def main(argv):
src = sys.argv[1]
dst = sys.argv[2]
print(src)
print(dst)
copyfile(src, dst) # for grid-print
ngc = "/tmp/gcode.ngc"
copyfile(src, ngc) # for LinuxCNC / Machinekit
try:
s = linuxcnc.stat() # create a connection to the status channel
c = linuxcnc.command()
if (not ok_for_mdi(s)):
print "not idle and not homed. Not submitting ngc job. Exiting"
sys.exit(1)
c.mode(linuxcnc.MODE_AUTO)
c.program_open(ngc)
s.poll()
print(s.file)
# c.reset_interpreter()
# for x in dir(s):
# if not x.startswith('_'):
# print x, getattr(s,x)
except linuxcnc.error, detail:
print "error", detail
sys.exit(1)
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment