Improved streaming stability

This commit is contained in:
Thomas Herrmann 2021-09-05 21:12:38 +02:00
parent 06ec3c35b7
commit af58d2c0b0

62
cnc.py
View File

@ -55,33 +55,7 @@ def grblConnect2():
# Stream g-code to grbl
#Stream GCODE from -https://onehossshay.wordpress.com/2011/08/26/grbl-a-simple-python-interface/-
def displayPosition():
if grbl != 0:
grbl_command = '?'
grbl.write(str.encode(grbl_command))
position = str(grbl.readline())
print(position)
position = position.replace('Idle|', ',')
position = position.replace('WPos:', '')
position = position.replace('MPos:', '')
position = position.replace('>', ',')
position = position.replace('|', ',')
position.strip()
coordinates_list = position.split(',')
#print(coordinates_list)
try:
show_ctrl_x.config(text = coordinates_list[1])
show_ctrl_y.config(text = coordinates_list[2])
show_ctrl_z.config(text = coordinates_list[3])
show_ctrl_x_w.config(text = coordinates_list[4])
show_ctrl_y_w.config(text = coordinates_list[5])
show_ctrl_z_w.config(text = coordinates_list[6])
except:
print("Listerror")
else:
print("No Connection yet")
root.after(500,displayPosition)
def jogWrite(AXIS, CMD, scale):
DECIMAL = [0.1,1,10,100]
@ -94,7 +68,6 @@ def jogWrite(AXIS, CMD, scale):
def directWrite(CMD):
grbl_command = CMD
if freetosend == 1:
sendGRBL(grbl_command)
def latchWrite(CMD):
@ -108,7 +81,6 @@ def latchWrite(CMD):
if CMD == 'G10':
zero_all.config(bg = loaded)
else:
states[CMD] ='0'
if CMD == 'M3':
@ -218,7 +190,7 @@ def grblWrite():
#l = line.split(";",1)
grbl_command = l
print("GCODE",grbl_command)
if freetosend == 1:
sendGRBL(grbl_command)
GCODE.close()
@ -236,14 +208,45 @@ def grblClose():
def sendGRBL(grbl_command):
global freetosend
freetosend = 0
#print(grbl_command)
grbl.write(str.encode(grbl_command+ '\n')) # Send g-code block to grbl
time.sleep(0.01)
grbl_out = grbl.readline() # Wait for grbl response with carriage return
infoScreen(grbl_out)
freetosend = 1
return grbl_out
#infoScreen("finished")
def displayPosition():
if grbl != 0 :
grbl_command = '?'
position = str(sendGRBL(grbl_command))
print(position)
position = position.replace('Idle|', ',')
position = position.replace('Run|', ',')
position = position.replace('WPos:', '')
position = position.replace('MPos:', '')
position = position.replace('>', ',')
position = position.replace('|', ',')
position.strip()
coordinates_list = position.split(',')
print(coordinates_list)
try:
show_ctrl_x.config(text = coordinates_list[1])
show_ctrl_y.config(text = coordinates_list[2])
show_ctrl_z.config(text = coordinates_list[3])
#show_ctrl_x_w.config(text = coordinates_list[4])
#show_ctrl_y_w.config(text = coordinates_list[5])
#show_ctrl_z_w.config(text = coordinates_list[6])
except:
print("Listerror")
else:
print("Serial Busy")
root.after(500,displayPosition)
root = Tk()
root.title('touchCNC')
@ -251,7 +254,6 @@ root.geometry('1024x600+0+0')
root.resizable(False,False)#17203b
root.tk_setPalette(background='#11192C', foreground='white',activeBackground='#283867', activeForeground='white' )
increments = IntVar()
movement = Frame(root, relief = 'ridge', bd = BORDER)
left = Button(root, text="-X", width = buttonsize_x, height = buttonsize_y, command = lambda:jogWrite('X', '-1', increments),bd = BORDER, bg = standard)