Files
wallter/plotter-app/streamer.py
Nathan-rek aacff9394f plotter app
2024-11-18 13:28:10 +01:00

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)