Created
April 15, 2019 14:54
-
-
Save hexagon5un/b2fc76c7168994153ab1f36340b39bbd to your computer and use it in GitHub Desktop.
gcodesender.py with "improved" defaults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
"""\ | |
Simple g-code streaming script | |
https://github.com/bborncr/gcodesender.py/blob/master/gcodesender.py | |
""" | |
import serial | |
import time | |
import argparse | |
parser = argparse.ArgumentParser(description='This is a basic gcode sender. http://crcibernetica.com') | |
parser.add_argument('-p','--port',help='Input USB port', nargs="?", default="/dev/ttyUSB0") | |
parser.add_argument('file', help='Gcode file name') | |
args = parser.parse_args() | |
## show values ## | |
print ("USB Port: %s" % args.port ) | |
print ("Gcode file: %s" % args.file ) | |
def removeComment(string): | |
if (string.find(';')==-1): | |
return string | |
else: | |
return string[:string.index(';')] | |
# Open serial port | |
#s = serial.Serial('/dev/ttyACM0',115200) | |
s = serial.Serial(args.port,115200) | |
print 'Opening Serial Port' | |
# Open g-code file | |
#f = open('/media/UNTITLED/shoulder.g','r'); | |
f = open(args.file,'r'); | |
print 'Opening gcode file' | |
# Wake up | |
s.write("\r\n\r\n") # Hit enter a few times to wake the Printrbot | |
time.sleep(2) # Wait for Printrbot to initialize | |
s.flushInput() # Flush startup text in serial input | |
print 'Sending gcode' | |
# Stream g-code | |
for line in f: | |
l = removeComment(line) | |
l = l.strip() # Strip all EOL characters for streaming | |
if (l.isspace()==False and len(l)>0) : | |
print 'Sending: ' + l | |
s.write(l + '\n') # Send g-code block | |
grbl_out = s.readline() # Wait for response with carriage return | |
print ' : ' + grbl_out.strip() | |
# Wait here until printing is finished to close serial port and file. | |
raw_input(" Press <Enter> to exit.") | |
# Close file and serial port | |
f.close() | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment