45 lines
815 B
Python
45 lines
815 B
Python
import serial
|
|
import time
|
|
|
|
|
|
#### Load gcode testfile
|
|
|
|
#f = open("circlesss.gcode", "r")
|
|
#gcode = f.readlines()
|
|
#print(gcode)
|
|
|
|
|
|
|
|
#### Streamer
|
|
|
|
def stream_gcode(gcode):
|
|
# Open grbl serial port
|
|
s = serial.Serial('/dev/ttyACM0',115200)
|
|
|
|
|
|
# Wake up grbl
|
|
s.write("\r\n\r\n".encode('utf-8'))
|
|
time.sleep(2) # Wait for grbl to initialize
|
|
|
|
s.flushInput() # Flush startup text in serial inp
|
|
|
|
for line in gcode:
|
|
l = str(line.strip()) # Strip all EOL characters for consistency
|
|
|
|
|
|
print('sending '+ l)
|
|
s.write((l + '\n').encode('utf-8')) # Send g-code block to grbl
|
|
|
|
grbl_out = s.readline() # Wait for grbl response with carriage return
|
|
print( ' : ' + str(grbl_out.strip()))
|
|
|
|
|
|
# Close file and serial port
|
|
|
|
s.close()
|
|
|
|
print('job done')
|
|
|
|
#stream_gcode(gcode)
|
|
|