-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfil_chaud_grbl.py
83 lines (67 loc) · 2.94 KB
/
fil_chaud_grbl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import tkinter as tk
from tkinter import X, Y, BOTTOM, RIGHT, LEFT, HORIZONTAL , END , DISABLED , ttk
from tkinter import StringVar , Tk , W ,E , S , BOTH, HIDDEN, DoubleVar , Spinbox , IntVar , filedialog
from gerbil import Gerbil
import time
import re
import queue
class Grbl:
def __init__(self,nb, app, queue):
self.nb = nb
self.app = app
self.queue = queue
self.grbl = Gerbil(self.my_callback)
#Next, we tell Gerbil to use its default log handler, which, instead of printing to stdout directly, will also call above my_callback function with eventstring on_log. You could use this, for example, to output the logging strings in a GUI window:
self.grbl.setup_logging()
def connectToGrbl(self):
#We now can connect to the grbl firmware, the actual CNC machine:
self.grbl.cnect(self.app.tComPort.get() , self.app.tBaudrate.get())
#We will poll every half tsecond for the state of the CNC machine (working position, etc.):
time.sleep(1)
self.grbl.poll_start()
def disconnectToGrbl(self):
self.grbl.disconnect()
self.app.grblStatus.set("Not connected")
def resetGrbl(self):
self.grbl.abort()
def unlockGrbl(self):
self.grbl.killalarm()
def homeGrbl(self):
self.grbl.homing()
def setPosGrbl(self):
self.grbl.send_immediately("G28.1")
def goToPosGrbl(self):
self.grbl.send_immediately("G28")
def stream(self, lines):
self.grbl.stream(lines)
def my_callback(self , eventstring, *data):
args = []
for d in data:
args.append(str(d))
print("MY CALLBACK: event={} data={}".format(eventstring.ljust(30), ", ".join(args)))
# Now, do something interesting with these callbacks
if eventstring == "on_stateupdate":
#print("args=", args)
#print("status=", args[0])
self.app.grblStatus.set(args[0])
self.app.tGuillotine.updateBtnState()
mpos = args[1].replace("(" ,"").replace(")","").split(",")
self.app.grblXG.set(mpos[0])
self.app.grblYG.set(mpos[1])
self.app.grblXD.set(mpos[2])
self.app.grblYD.set(mpos[3])
self.app.grblF.set(mpos[4])
self.app.grblS.set(mpos[5])
elif eventstring == "on_msg":
self.queue.put("\n".join(args))
elif eventstring == "on_log":
if "Error" in ", ".join(args):
#print("grbl will disconnect because it get an error")
self.app.grblStatus.set("Connection lost")
self.grbl.disconnect()
self.app.tGuillotine.updateBtnState()
elif eventstring == "on_iface_error":
#print("on_iface_error")
self.queue.put("interface error\n")
self.disconnectToGrbl()
self.app.tGuillotine.updateBtnState()