mirror of
https://github.com/BKLronin/touchCNC.git
synced 2024-11-23 09:04:01 +01:00
Improved streaming stability
This commit is contained in:
parent
06ec3c35b7
commit
af58d2c0b0
62
cnc.py
62
cnc.py
@ -55,33 +55,7 @@ def grblConnect2():
|
|||||||
# Stream g-code to grbl
|
# Stream g-code to grbl
|
||||||
#Stream GCODE from -https://onehossshay.wordpress.com/2011/08/26/grbl-a-simple-python-interface/-
|
#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):
|
def jogWrite(AXIS, CMD, scale):
|
||||||
DECIMAL = [0.1,1,10,100]
|
DECIMAL = [0.1,1,10,100]
|
||||||
@ -94,7 +68,6 @@ def jogWrite(AXIS, CMD, scale):
|
|||||||
|
|
||||||
def directWrite(CMD):
|
def directWrite(CMD):
|
||||||
grbl_command = CMD
|
grbl_command = CMD
|
||||||
if freetosend == 1:
|
|
||||||
sendGRBL(grbl_command)
|
sendGRBL(grbl_command)
|
||||||
|
|
||||||
def latchWrite(CMD):
|
def latchWrite(CMD):
|
||||||
@ -108,7 +81,6 @@ def latchWrite(CMD):
|
|||||||
if CMD == 'G10':
|
if CMD == 'G10':
|
||||||
zero_all.config(bg = loaded)
|
zero_all.config(bg = loaded)
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
states[CMD] ='0'
|
states[CMD] ='0'
|
||||||
if CMD == 'M3':
|
if CMD == 'M3':
|
||||||
@ -218,7 +190,7 @@ def grblWrite():
|
|||||||
#l = line.split(";",1)
|
#l = line.split(";",1)
|
||||||
grbl_command = l
|
grbl_command = l
|
||||||
print("GCODE",grbl_command)
|
print("GCODE",grbl_command)
|
||||||
|
if freetosend == 1:
|
||||||
sendGRBL(grbl_command)
|
sendGRBL(grbl_command)
|
||||||
|
|
||||||
GCODE.close()
|
GCODE.close()
|
||||||
@ -236,14 +208,45 @@ def grblClose():
|
|||||||
|
|
||||||
def sendGRBL(grbl_command):
|
def sendGRBL(grbl_command):
|
||||||
global freetosend
|
global freetosend
|
||||||
|
freetosend = 0
|
||||||
#print(grbl_command)
|
#print(grbl_command)
|
||||||
grbl.write(str.encode(grbl_command+ '\n')) # Send g-code block to grbl
|
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
|
grbl_out = grbl.readline() # Wait for grbl response with carriage return
|
||||||
|
|
||||||
infoScreen(grbl_out)
|
infoScreen(grbl_out)
|
||||||
|
freetosend = 1
|
||||||
|
return grbl_out
|
||||||
|
|
||||||
#infoScreen("finished")
|
#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 = Tk()
|
||||||
root.title('touchCNC')
|
root.title('touchCNC')
|
||||||
@ -251,7 +254,6 @@ root.geometry('1024x600+0+0')
|
|||||||
root.resizable(False,False)#17203b
|
root.resizable(False,False)#17203b
|
||||||
root.tk_setPalette(background='#11192C', foreground='white',activeBackground='#283867', activeForeground='white' )
|
root.tk_setPalette(background='#11192C', foreground='white',activeBackground='#283867', activeForeground='white' )
|
||||||
|
|
||||||
|
|
||||||
increments = IntVar()
|
increments = IntVar()
|
||||||
movement = Frame(root, relief = 'ridge', bd = BORDER)
|
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)
|
left = Button(root, text="-X", width = buttonsize_x, height = buttonsize_y, command = lambda:jogWrite('X', '-1', increments),bd = BORDER, bg = standard)
|
||||||
|
Loading…
Reference in New Issue
Block a user